【发布时间】:2017-12-12 04:53:57
【问题描述】:
我有这个 XSLT 样式表 xinclude-test.xsl:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xi="http://www.w3.org/2001/XInclude">
<xsl:output method="text"/>
<xi:include href="xinclude-test-included.xml"/>
<!-- <xsl:param name="test"> -->
<!-- aaa -->
<!-- </xsl:param> -->
<xsl:template name="main">
<xsl:value-of select="$test"/>
</xsl:template>
</xsl:stylesheet>
包含的文件xinclude-test-included.xml是
<?xml version="1.0" encoding="utf-8"?>
<xsl:param name="test" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
aaa
</xsl:param>
当我用
评估样式表时saxon -xi -xsl:xinclude-test.xsl -it:main -t
打印出来
Saxon-HE 9.8.0.1J from Saxonica
Java version 1.8.0_31
Static error at char 5 in xsl:value-of/@select on line 13 column 35 of xinclude-test.xsl:
XPST0008: Variable test has not been declared (or its declaration is not in scope)
Errors were reported during stylesheet compilation
我希望它在哪里打印“aaa”。
但是,如果我使用另一个样式表来加载第一个 XSLT:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:template name="main">
<xsl:copy-of select="document('xinclude-test.xsl')"/>
</xsl:template>
</xsl:stylesheet>
它正确地进行了 XInclude 处理。
那么我在第一个 XSLT 中做错了什么?
【问题讨论】:
-
考虑在您的 Saxon 通话中添加
-t,然后向我们展示您使用的 Saxon 版本。 -
@MartinHonnen 添加了版本信息。
-
saxonica.com/html/documentation/using-xsl/commandline 中的 Saxon 9.8 文档说“-xi:(on|off) 将 XInclude 处理应用于所有输入 XML 文档(包括模式和样式表模块以及源文档)”所以我首先建议尝试
-xi:on而不是-xi。如果这不起作用,那么我想您将不得不等待 Michael Kay 所说的。 -
我尝试了
-xi:on和-xi,结果相同。 John Bollinger 的回答让我想到 Saxon 只对正在转换的文档进行 xinclude 处理,而不是在样式表上。