Project

Profile

Help

XSLT scripts from an jar

Added by Anonymous over 19 years ago

Legacy ID: #3177118 Legacy Poster: Jan Tietjens (jantietjens)

Hi, I am using two configurations, one in which the xslt scripts are read from the file system and another where they are taken from an jar. Here is the source code for building a TransformerHandler: final String xsltDocument = (String) transformations.next(); //Templates final StreamSource xsltSource = new StreamSource(xsltDocument); xsltSource.setSystemId(xsltDocument); _logger.info("### Adding system id: " + xsltDocument + " as transformer handler."); final TransformerHandler currentTransformerHandler = _saxTransformerFactory.newTransformerHandler( xsltSource); The following exception occurs, if I run the above code with a stylesheet contained in an jar: ### Adding system id: file:[...]/build/lib/uml14.jar!/com/gentleware/poseidon/uml/model_conversion/xslt/firstRun.xsl as transformer handler. javax.xml.transform.TransformerConfigurationException: Failed to compile stylesheet. 1 error detected. at net.sf.saxon.PreparedStylesheet.prepare(PreparedStylesheet.java:124) at net.sf.saxon.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:125) at net.sf.saxon.TransformerFactoryImpl.newTransformerHandler(TransformerFactoryImpl.java:502) What am I doing wrong? Best regards, Jan Tietjens


Replies (2)

RE: XSLT scripts from an jar - Added by Anonymous over 19 years ago

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

Hard to tell without more information. The exception is just a summary, the actual errors should have been notified to the ErrorListener which by default will log them to System.err. It might be worth trying to dereference the URI yourself, to see if that changes anything or gives you more information. Use InputStream is = new URI(xsltDocument).openStream(); StreamSource xsltSource = new StreamSource(is); You say "scripts" - does that mean there is more that one stylesheet module? - if so I would think a likely candidate is that an xsl:include or xsl:import hasn't been resolved. I don't have much experience with JAR file URIs myself. I've heard a number of problem reports with them, but don't know specifically what the difficulties are. Michael Kay

RE: XSLT scripts from an jar - Added by Anonymous over 19 years ago

Legacy ID: #3177550 Legacy Poster: Jan Tietjens (jantietjens)

Thank you for your answer. The suggestion helped me to find the error. I got an FileNotFoundException and I saw that the URI which I constructed was not correct. So, everything is now working. For loading the included scrips I have written my own URIResolver which loads the scripts by the ClassLoader. Best regards, Jan Tietjens

    (1-2/2)

    Please register to reply