6

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

<Report>
   <Document>
      <documentType>E</documentType>
      <person>
         <firstname>John</firstname>
         <lastname>Smith</lastname>
      </person>
   </Document>
   <Document>
      [...]
   </Document>
   <Document>
      [...]
   </Document>
   [...]
</Report>

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

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

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

这是我的撒克逊命令行:

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>

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

谢谢您的帮助!

4

1 回答 1

6

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

copy-of(/Report/Document)

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

/Report/Document/copy-of()

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

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

于 2014-10-07T08:28:24.800 回答