It's difficult to tell you why you are getting an exception when you haven't given any details of the exception. My guess (pure speculation) would be that Pt2Stylesheet.xsl contains relative URIs to other resources - perhaps includes/imports, perhaps DTD references, or perhaps a call on document() using a stylesheet-relative URI, and that this relative reference is failing to resolve. It should resolve if you set the SystemId of the StreamSource correctly, to the location of the XSLT module in the JAR file (using a jar: URL). Although such URLs are not standard URIs according to the internet RFCs (they are a JDK invention), Saxon does support them. However, given that you are avoiding hard-coding of any path to the JAR file, I'm afraid I don't know any way of discovering the URL of the stylesheet that you have loaded so that you can load other things relative to it. This would suggest that the right way to do it is using some kind of dummy URI, and resolving this yourself in a URIResolver (or EntityResolver, if it's the XML parser trying to locate the resource, rather than Saxon.) Your URIResolver would then get the resource by means of another call on getResourceAsStream().

I may be barking up the wrong tree here, if so I apologize. You haven't given me much information to work from!

Michael Kay

On 29/11/2012 19:00, Bhagat Singh wrote:

We have saxon9ee.jar evaluation version and we are planing to buy it in few weeks... but we are still in Proof of concept mode.

Working Code:

URL url = Thread.currentThread().getContextClassLoader().getResource("templates/Pt2Stylesheet.xsl");

String absoluteFilePath = url.getPath();

Source xsl = new StreamSource(absoluteFilePath );
TransformerFactory factory = TransformerFactory.newInstance();
SAXTransformerFactory saxTransFact = (SAXTransformerFactory) factory;
Transformer transformer = saxTransFact.newTransformer(xsl);

Note: Above code doesn't work when we ship code in jar file.

for that we make following changes

InputStreem xslInputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream ("templates/Pt2Stylesheet.xsl");

Source xsl = new StreamSource(xslInputStream );

Note: I Also tried to set systemId.

After making changes in the above code it stop working and throwing some exception parser exception....

Please suggest how can we overcome from this problem....



Keep yourself connected to Go Parallel: 
TUNE You got it built. Now make it sing. Tune shows you how.

saxon-help mailing list archived at