Project

Profile

Help

Difference between Java API and command line

Added by Anonymous about 15 years ago

Legacy ID: #6450653 Legacy Poster: John Eric Hamacher (midvale)

We currently run Saxon from the command line but we are moving towards building a custom application which uses the APIs: System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl"); TransformerFactory tfactory = TransformerFactory.newInstance(); Transformer transformer = tfactory.newTransformer(new DOMSource(xslt)); transformer.transform(new DOMSource(xml),new StreamResult(fo)); 09/02/17 11:48:48 Caused by: javax.xml.transform.TransformerConfigurationException: Failed to compile stylesheet. 1 error detected. 09/02/17 11:48:48 at net.sf.saxon.PreparedStylesheet.prepare(PreparedStylesheet.java:176) 09/02/17 11:48:48 at net.sf.saxon.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:139) 09/02/17 11:48:48 at net.sf.saxon.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:91) 09/02/17 11:48:48 at com.gallup.fogen.FOGenerator.transform(FOGenerator.java:24) 09/02/17 11:48:48 at com.gallup.fogen.FogenController.handleXML(FogenController.java:40) With the command line a certain XSLT document runs cleanly. However, in the code above we get this exception. I am suspecting that if I could turn off validation of the XSLT, this might go away. How can I turn off validation? Thanks Eric


Replies (1)

RE: Difference between Java API and command line - Added by Anonymous about 15 years ago

Legacy ID: #6451776 Legacy Poster: Michael Kay (mhkay)

The compiler has reported an error message, which will have been written to the standard error output; you haven't shown me the standard error output, so I don't know what the error is. Often if you are compiling stylesheets from your application code, it's a good idea to set your own error listener so you can control where the compile-time error messages are written. If this is a working stylesheet then I think there's a good chance that the error is caused by not setting a system ID on the Source object used to supply the stylesheet. This will cause relative URIs in xsl:include and xsl:import to fail to resolve. Using a DOMSource for the stylesheet is unusual, and not something I would do without good reason, but that's not the cause of the failure. You should also setSystemId() on the DOMSource used for the source document. Again, don't use a DOMSource without good reason - the DOM is much less efficient than Saxon's native tree model (sometimes by a factor of ten).

    (1-1/1)

    Please register to reply