XSLT 3.0 部分流 (Saxon) [英] XSLT 3.0 partial streaming (Saxon)

查看:42
本文介绍了XSLT 3.0 部分流 (Saxon)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a big XML file (6 GB) with this kind of tree:

<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.我不想在 Document 中设置一次流约束.这就是我尝试使用 copy-of() 的原因.我认为,我想要做的非常接近此处描述的突发模式":http://saxonica.com/documentation/html/sourcedocs/streaming/burst-mode-streaming.html

So I used the new XSLT 3.0 streaming feature, with Saxon 9.6 EE. I don't want to have the streaming constrains once in a Document. This is why I tried to used copy-of(). I think that, what I want to do, is very close to the "burst mode" that is described here: http://saxonica.com/documentation/html/sourcedocs/streaming/burst-mode-streaming.html

这是我的 XSLT 样式表:

Here is my XSLT style sheet:

<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() 我可以直接在 for-each (xsl:value-ofa href="https://stackoverflow.com/questions/26225551/xslt-3-0-streaming-saxon/26231701">就像这个问题).(否则我有这个错误 * 至少有两个消耗操作数:{xsl:value-of} 在第 8 行,{xsl:value-of} 在第 9 行)

In a sense it works because with the copy-of() I'm able to use several xsl:value-of directly in the for-each (like in this question). (Otherwise I have this error * 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"/> 产生了这个错误:

But I still have streaming constrains because <xsl:call-template name="fnc1"/> creates this error:

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) 在文档中?

So my question is: how to do partial streaming (Documents are loaded one by one but fully) in order to be able to use call-template (and other apply-templates) in a Document?

感谢您的帮助!

推荐答案

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

I think call-template should be streamable when the context item is grounded (ie. not a streamed node), so I'll treat this as a bug. Meanwhile a workaround might be to declare fnc1 as

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

并将其称为

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

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

Alternatively, replace the template with a function and supply the context item as an explicit argument.

您可以在此处跟踪错误:

You can track the bug here:

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

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

Although we don't claim 100% conformance with the XSLT 3.0 specification yet, we'll treat any unnecessary departures in the 9.6 release as bugs unless fixing them would destabilize the product.

这篇关于XSLT 3.0 部分流 (Saxon)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆