我有一个很大的 XML 文件(6 GB),其中包含这种树:
<Report>
<Document>
<documentType>E</documentType>
<person>
<firstname>John</firstname>
<lastname>Smith</lastname>
</person>
</Document>
<Document>
[...]
</Document>
<Document>
[...]
</Document>
[...]
</Report>
如果我在其上应用 XSLT 样式表,则会出现以下错误:
线程“main”中的异常 java.lang.OutOfMemoryError:Java 堆空间
所以我想尝试新的 XSLT 3.0 功能:使用 Saxon 9.6 EE 进行流式处理。
我不想在文档中出现一次流限制。我认为,我想做的,非常接近此处描述的“突发模式”:http://saxonica.com/documentation/html/sourcedocs/streaming/burst-mode-streaming.html 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>
但我仍然有同样的内存不足错误。
感谢您的帮助!
您的 copy-of() 正在复制上下文项,即整个文档。你要
copy-of(/Report/Document)
依次复制每个文档。或者我倾向于这样写
/Report/Document/copy-of()
因为我认为这可以让人们更清楚地了解正在发生的事情。
顺便说一下,这里不需要 xsl:iterate:xsl:for-each 会很好地完成这项工作,因为一个文档的处理不依赖于任何先前文档的处理。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)