By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,247 Members | 1,273 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,247 IT Pros & Developers. It's quick & easy.

Use output of XSL transformation as new XSL stylesheet

P: n/a

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.parse(new InputSource(new FileInputStream(preprocessor)));

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

// parse page stylesheet through proprocessor

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

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

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

However, when I run this I get a NullPointerException in

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



Jan 16 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.