Saxon error with XSLT import statement

南楼画角 提交于 2019-12-07 00:51:48

问题


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?


回答1:


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); 


来源:https://stackoverflow.com/questions/7236291/saxon-error-with-xslt-import-statement

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!