1

我有这个 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 中做错了什么?

4

2 回答 2

3

我相信你会得到特别是关于撒克逊人的答案或评论,但作为对你问题的更一般的答案,

那么我在第一个 XSLT 中做错了什么?

我会注意到 XSLT 2.0 不包含任何要求处理器对样式表文档执行 XInclude 处理的规定。由于规范定义了样式表文档的形式和语义,我倾向于将这种遗漏视为处理器不应对样式表文档执行 XInclude 处理的指示。函数是否document()执行 XInclude 处理也没有指定,但我不认为以同样的方式指示。

无论好坏,XSLT 都有自己的包含外部样式表片段的机制。语义与 XInclude: 有点不同,xsl:include用于xsl:import引入外部样式表模块,而不是任意 XML 片段。

于 2017-07-07T20:29:08.557 回答
1

恐怕文档与代码不匹配:Saxon 没有尝试将 -xi 选项应用于样式表文档。我们将不得不决定是否将代码或文档视为正确的。

在此处作为错误提出:https ://saxonica.plan.io/issues/3343

于 2017-07-07T22:08:01.167 回答