Java Transformer API. Unexpected Result

Hello there,

I need to use javax.transform API for a XSLT transformation of mine. My problem is:

the result ist not (as expected) the transformed XML (i.e. the XSLT-template applied to the XML document) but the XSLT-stylesheet itself! After hours of google I've given up now :(

My code below:

[code]

Document xmlTemplate;

Document xslTemplate;

Source xmlTemplateSrc = new DOMSource(xmlTemplate);

Source xslTemplateSrc = new DOMSource(xslTemplate);

TransformerFactory factory = TransformerFactory.newInstance();

Transformer transformer = null;

Templates templates = null;

try {

templates = factory.newTemplates(xslTemplateSrc);

transformer = templates.newTransformer();

} catch (TransformerConfigurationException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

DOMResult domResult = new DOMResult();

try {

[b]transformer.transform(xmlTemplateSrc, domResult);[/b]

} catch (TransformerException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return (Document) domResult.getNode();

[/code]

What I get as Result in the DOMResult object is the XSLT-template I'm using for the transformation.

Really looking forward to some answers,

regards

christian

[1371 byte] By [bentea] at [2007-11-26 18:28:00]
# 1

I had the same problem.

I solved it by changing all my Source-implementing objects to StreamSource. Make sure you're not mixing your source object types, e.g. cretaing a SAXSource from a org.w3c.dom.Document or DOMSource. Before, I was creating a DOMSource from a sax InputSource, which I think was what was causing the problem.

Note: you do not need to use a parser on either the template (parameter to the newTransformer() function) or the source (first parameter to the transform() function) if you are using s StreamSource.

mBreada at 2007-7-9 6:02:10 > top of Java-index,BigAdmin,Troubleshoot...