XSLT 3.0流(Saxon)

ste*_*eco 6 xml xslt streaming saxon xslt-3.0

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

<Report>
   <Document>
      <documentType>E</documentType>
      <person>
         <firstname>John</firstname>
         <lastname>Smith</lastname>
      </person>
   </Document>
   <Document>
      [...]
   </Document>
   <Document>
      [...]
   </Document>
   [...]
</Report>
Run Code Online (Sandbox Code Playgroud)

如果在其上应用XSLT样式表,则会出现此错误:

线程“主”中的异常java.lang.OutOfMemoryError:Java堆空间

因此,我想尝试XSLT 3.0的新功能:使用Saxon 9.6 EE进行流传输。我不想一次在文档中使用流式传输约束。我认为我想做的非常类似于此处描述的“突发模式”:http : //saxonica.com/documentation/html/sourcedocs/streaming/burst-mode-streaming.html

这是我的Saxon命令行:

java -cp saxon9ee.jar net.sf.saxon.Transform -t -s:input.xml -xsl:stylesheet.xsl -o:output / output.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:iterate select="copy-of()/Report/Document" >
           DOC HEADER
           documentType: <xsl:value-of select="documentType"/>
           person/firstname: <xsl:value-of select="person/firstname"/>
           DOC FOOTER
           <xsl:next-iteration/>
        </xsl:iterate>
    GLOBAL FOOTER
</xsl:template>

</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)

但是我仍然有同样的内存不足错误。

谢谢您的帮助!

Mic*_*Kay 5

您的 copy-of() 正在复制上下文项,即整个文档。你要

copy-of(/Report/Document)
Run Code Online (Sandbox Code Playgroud)

它依次复制每个文档。或者我倾向于写它

/Report/Document/copy-of()
Run Code Online (Sandbox Code Playgroud)

因为我认为它使发生的事情更加清楚。

顺便说一下,这里不需要 xsl:iterate:xsl:for-each 可以很好地完成这项工作,因为对一个 Document 的处理不依赖于对任何先前文档的处理。