xslt - 用于在 Windows 上定位相对文件路径的 XSL 导入用法

标签 xslt

我有一个简单的 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/

相关文章:

xslt - 无法使用 XSLT/XPath 2.0 正确获取调试输出

xml - XSL - 循环中的前一个节点值

xml - 使用 XPath 选择匹配兄弟的前一个兄弟?

xslt - 创造什么?函数或模板还是?

xml - XSLT:如何选择没有子节点的所有节点

xml - 如何用xslt转换xml并在Android webview中显示

xslt - 在 XSL 中组合两个节点集

c# - 防止 XslCompiledTransform 使用自闭合标签

xml - 我可以使用 XSLT 1.0 在 XML 元素的文本内容周围添加 <p></p> 标签吗?

xslt - 如何防止 XSLT 换行?