【问题标题】:XInclude not working with Saxon?X包括不与撒克逊人合作?
【发布时间】: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 处理,而不是在样式表上。

标签: xml xslt saxon xinclude


【解决方案1】:

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

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

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

无论好坏,XSLT 都有its own mechanism for including external stylesheet fragments。语义与 XInclude 有点不同:xsl:includexsl:import 用于引入外部样式表模块,而不是任意 XML 片段。

【讨论】:

  • 我明白了。这很有帮助。谢谢!
  • 第 3 节开头的注释不鼓励这样的解释:“样式表模块由 XDM 元素节点表示......虽然样式表模块通常以符合 XML 的文档的形式维护1.0 或 XML 1.1,本规范不强制要求这种表示形式。与源代码树一样,从文本 XML 或其他方式构造样式表模块的方式超出了本规范的范围。”
  • (和 IIRC,XInclude 用于组装样式表模块的潜在用途是该规则背后的动机之一。)
【解决方案2】:

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

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

【讨论】:

  • 在我的回答中,我认为 XSLT 2.0 建议中对 XInclude 处理的任何提及都应被视为不应在样式表文档上执行此类处理的指示。仔细观察后,我发现出现在样式表顶层的 XInclude 元素应该被认为是User-defined data elements,并且当我阅读规范时,处理器不得使用这些元素来生成与预期不同的结果树如果它们被忽略就会产生。
猜你喜欢
  • 2016-01-25
  • 2019-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-25
  • 2010-10-02
  • 1970-01-01
相关资源
最近更新 更多