我有一个简单的 XSL 文件,如下所示:
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:import href="html/docbook.xsl"/>
</xsl:stylesheet>
我有一个 XSL 文件,它位于磁盘上的一个文件夹中(不在网络上)。它相对于我的 XSL 文件的路径(上图)是:
..\..\..\Dependencies\XSL\xsl\htmlhelp\htmlhelp.xsl
<xsl:import href="..\..\..\Dependencies\XSL\xsl\htmlhelp\htmlhelp.xsl"/>
或
<xsl:import href="../../../Dependencies/XSL/xsl/htmlhelp/htmlhelp.xsl"/>
似乎没有工作(我得到 - 找不到文件 - 来自 xslproc 工具的错误。)
在 XSL:import 中编写相对路径的正确方法是什么?
提前致谢,
保罗
最佳答案
如果您描述了如何尝试运行样式表,将会很有帮助。
Java 中包含/导入的相对路径的一个常见问题: 当您将 XSLT 作为 StreamSource 加载且未设置 SystemID 时,处理器不知道 XSLT 的“位置”并且无法解析相对路径。
http://www.onjava.com/pub/a/onjava/excerpt/java_xslt_ch5/index.html?page=5
By providing a system identifier as a parameter to the StreamSource, you are telling the XSLT processor where to look for commonFooter.xslt. Without this parameter, you may encounter an error when the processor cannot resolve this URI. The simple fix is to call the setSystemId( ) method as follows:
// construct a Source that reads from an InputStream
Source mySrc = new StreamSource(anInputStream);
// specify a system ID (a String) so the
// Source can resolve relative URLs
// that are encountered in XSLT stylesheets
mySrc.setSystemId(aSystemId);
要仔细检查的另一件事是您的相对路径确实正确。在命令提示符中浏览到 XSLT 所在的位置,然后 cd 到该相对路径以查看它是否找到该文件。
关于xslt - 用于在 Windows 上定位相对文件路径的 XSL 导入用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1449449/