Reputation: 3721
The Saxon processor gives me an error whenever I have an XSLT import statement. Here is the error:
XTSE0165: I/O error reported by XML parser processing file: shared/test.xslt (The system cannot find the path specified):
Here is how my XSLT document looks like:
<?xml version='1.0' encoding='UTF-8'?>
<xsl:stylesheet version='2.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
xmlns:fn='http://www.w3.org/2005/02/xpath-functions'
xmlns:xs='http://www.w3.org/2001/XMLSchema'
>
<xsl:import href="shared/test.xslt"/>
...
My java code
TransformerFactory transformerFactory = TransformerFactoryImpl.newInstance();
transformerFactory.setURIResolver(uriResolver); //my own custom URI resolver
Transformer transformer = transformerFactory.newTransformer(new StreamSource(xsltInputStream)); //this is where the error occurs when I debug!
The URI resolver class is never triggered! It chocks up on the newTransformer() method above.... I tried XsltCompiler, etc and same thing... If I remove the import statement, everything works!! It can't find the file to import which is fine but that's why I have the resolver class to help it locate the file but it never triggers the resolver and fails locating the file to import!
How do I resolve this?
Upvotes: 10
Views: 6864
Reputation: 66714
You likely need to set the System ID for StreamSource
of the XSLT that you are loading.
When you load from a StreamSource
, it doesn't know where your XSLT "lives" and has difficulty determining how to resolve relative paths.
StreamSource source = new StreamSource(xsltInputStream);
source.setSystemId(PATH_TO_THE_XSLT_FILE_ON_THE_FILESYSTEM_OR_URL);
Transformer transformer = transformerFactory.newTransformer(source);
Upvotes: 12