XSLT 导入语句的 Saxon 错误 [英] Saxon error with XSLT import statement
问题描述
每当我有 XSLT 导入语句时,Saxon 处理器都会给我一个错误.这是错误:
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):
这是我的 XSLT 文档的样子:
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"/>
...
我的Java代码
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!
URI 解析器类永远不会被触发!它阻塞了上面的 newTransformer() 方法......我尝试了 XsltCompiler 等,同样的事情......如果我删除 import 语句,一切正常!它找不到要导入的文件,这很好,但这就是为什么我有解析器类来帮助它定位文件,但它永远不会触发解析器并且无法定位要导入的文件!
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?
推荐答案
您可能需要 为您正在加载的 XSLT 的 StreamSource
设置系统 ID.
You likely need to set the System ID for StreamSource
of the XSLT that you are loading.
当您从 StreamSource
加载时,它不知道您的 XSLT存在"在哪里,并且难以确定如何解析相对路径.
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);
这篇关于XSLT 导入语句的 Saxon 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!