2

我有一个带有这种树的大 XML 文件(6 GB):

<Report>
   <Document>
      <documentType>E</documentType>
      <person>
         <firstname>John</firstname>
         <lastname>Smith</lastname>
      </person>
   </Document>
   <Document>
      [...]
   </Document>
   <Document>
      [...]
   </Document>
   [... there are a lot of Documents]
</Report>

所以我使用了新的 XSLT 3.0 流功能和 Saxon 9.6 EE。我不想在文档中有一次流式约束。这就是我尝试使用copy-of(). 我认为,我想要做的,非常接近这里描述的“突发模式”:http: //saxonica.com/documentation/html/sourcedocs/streaming/burst-mode-streaming.html

这是我的 XSLT 样式表:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0">
<xsl:mode streamable="yes" />

<xsl:template match="/">
    GLOBAL HEADER
        <xsl:for-each select="/Report/Document/copy-of()" >
           DOC HEADER
           documentType: <xsl:value-of select="documentType"/>
           person/firstname: <xsl:value-of select="person/firstname"/>

           <xsl:call-template name="fnc1"/>

           DOC FOOTER
        </xsl:for-each>
    GLOBAL FOOTER
</xsl:template>

<xsl:template name="fnc1">
    documentType again: <xsl:value-of select="documentType"/>
</xsl:template>

</xsl:stylesheet>

从某种意义上说,它之所以有效,是因为copy-of()我可以xsl:value-of直接在 for-each 中使用几个(就像在这个问题中一样)。(否则我有这个错误 * There are at least two consuming operands: {xsl:value-of} on line 8, and {xsl:value-of} on line 9

但我仍然有流媒体限制,因为<xsl:call-template name="fnc1"/>会产生这个错误:

Error at xsl:template on line 4 column 25 of stylesheet.xsl:
  XTSE3430: Template rule is declared streamable but it does not satisfy the streamability rules.
  * xsl:call-template is not streamable in this Saxon release
Stylesheet compilation failed: 1 error reported

所以我的问题是:如何进行部分流式传输(文档被一个一个加载但完全加载)以便能够在文档中使用call-template(和其他apply-templates)?

谢谢您的帮助!

4

1 回答 1

1

我认为当上下文项接地(即不是流式节点)时,调用模板应该是可流式的,因此我将其视为错误。同时,一种解决方法可能是将 fnc1 声明为

<xsl:template name="fnc1" mode="fnc1" match="Document"/>

并将其称为

<xsl:apply-templates select="." mode="fnc1"/>

或者,将模板替换为函数并将上下文项作为显式参数提供。

您可以在此处跟踪错误:

https://saxonica.plan.io/issues/2171

尽管我们还没有声称 100% 符合 XSLT 3.0 规范,但我们会将 9.6 版本中任何不必要的偏离视为错误,除非修复它们会破坏产品的稳定性。

于 2014-10-08T17:07:34.360 回答