473,395 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Use output of XSL transformation as new XSL stylesheet

Hi,

I'm trying to pre-process an XSL stylesheet with another stylesheet,
before using the result to transform an XML document. i.e.:

stylesheet(xsl) --> preprocessor(xsl) --> temp(xsl)
input(xml) --> temp(xsl) --> output(xml)

but I'm getting a NullPointerException. I'm not 100% sure exactly what
is going on here, so if someone could help I'd be grateful.

I've been working from the examples from Sun and Apache Xalan, and so
far have the following:

File input = new File("input.xml");
File stylesheet = new File("stylesheet.xsl");
File preprocessor = new File("preprocess.xsl");

SAXTransformerFactory stf =
(SAXTransformerFactory)TransformerFactory.newInsta nce();

// parse preprocessor stylesheet into templates handler
TemplatesHandler tmpltHand = stf.newTemplatesHandler();
XMLReader reader = XMLReaderFactory.createXMLReader();
reader.setContentHandler(tmpltHand);
reader.parse(new InputSource(new FileInputStream(preprocessor)));

// create transformer handler based on templates handler
Templates templates = tmpltHand.getTemplates();
TransformerHandler transHand =
stf.newTransformerHandler(templates);

// parse page stylesheet through proprocessor
reader.setContentHandler(transHand);
reader.setProperty("http://xml.org/sax/properties/lexical-handler",
transHand);

transHand.setResult(new StreamResult(System.out));
reader.parse(new InputSource(new FileInputStream(stylesheet)));

This all works fine, and displays the modified stylesheet. It's when I
try to use this stylesheet it all goes wrong. I thought I could just
redirect the output of the last stage, via a SAXResult. into a new
TemplatesContentHandler, and then use this to transform the actual
input.

replace:
transHand.setResult(new StreamResult(System.out));

with:
TemplatesHandler tmpltHand2 = stf.newTemplatesHandler();
transHand.setResult(new SAXResult(tmpltHand2));

However, when I run this I get a NullPointerException in
TransformerHandlerImpl.endDocument.

Can anybody see what is wrong here, or suggest a better way of doing
this?

Cheers,

Barney

Jan 16 '06 #1
0 1172

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bill Sneddon | last post by:
Can any one tell me how to output the following string? <%response.write "<tr><td><a href=""file://SERVER/mmlogs/TNAME" & yearmonth & """>"& "MYJUNK" & "</a><BR></td></tr>" %> ...
0
by: Dimitre Novatchev | last post by:
You seem to be unaware of the xslt processing which uses the built-in rules in the absence of templates that match some selected node. http://www.w3.org/TR/xslt#built-in-rule According to the...
3
by: Ray Tayek | last post by:
hi, trying to use an xslt to make an xslt. trying something like: <?xml version="1.0" encoding="UTF-8"?> <?xmlspysamplexml H:\java\projects\spy1\spy\inputDocumentMap.xml?> <xsl:stylesheet...
2
by: Soren Kuula | last post by:
Hi, I'm trying to teach myself a little XSL. I have made up an XML model of a consed list, like : <list> <car>a</car> <cdr> <list> <car>b</car>
4
by: Mike Conmackie | last post by:
Hi Folks, I've probably omitted something very basic but I have no idea what it might be. The results of my transformation _should_ be an xml file but all I get is the xml declaration...
1
by: KwiKiwi | last post by:
Hey, I'm doing a series of XSL Transformations from a C#.NET Console app. I've designed a .xsl file (to output to "text" not "xml") to generate a text file with entries that look like: ...
3
by: Joseph A Romeo | last post by:
I have written an XSLT transformation on an ASP.NET page. The resulting HTML is primarily a table of links. I have found that when the resulting HTML is less than or equal to 16040 bytes, the...
3
by: Fredy MuƱoz [MCP] | last post by:
Hello there! I have a couple of questions about generating HTML using an XSLT Stylesheet. I use the System.Xml and System.Xml.Xsl namespaces and a XslTransform object to make the...
18
by: Terry Holland | last post by:
I have an asp.net (1.1) application that connects to a SQL server 2000 db. I have a stored procedure in my db that out puts data in xml format. What I need to be able to do is display that xml...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.