XSLT 3.0 流(撒克逊) [英] XSLT 3.0 streaming (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>
[...]
</Report>
如果我在其上应用 XSLT 样式表,则会出现此错误:
If I apply an XSLT style sheet on it, I have this error:
线程main"中的异常 java.lang.OutOfMemoryError: Java heap space
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
所以我想尝试新的 XSLT 3.0 特性:流媒体,使用 Saxon 9.6 EE.我不想在 Document 中设置一次流约束.我认为,我想要做的非常接近此处描述的突发模式":http://saxonica.com/documentation/html/sourcedocs/streaming/burst-mode-streaming.html
So I wanted to try the new XSLT 3.0 feature: streaming, with Saxon 9.6 EE. I don't want to have the streaming constrains once in a Document. 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
这是我的 Saxon 命令行:
Here is my Saxon command line:
java -cp saxon9ee.jar net.sf.saxon.Transform -t -s:input.xml -xsl:stylesheet.xsl -o:output/output.html
java -cp saxon9ee.jar net.sf.saxon.Transform -t -s:input.xml -xsl:stylesheet.xsl -o:output/output.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: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>
但我仍然有同样的内存不足错误.
But I still have the same out of memory error.
感谢您的帮助!
推荐答案
您的 copy-of() 正在复制上下文项,即整个文档.你想要
Your copy-of() is copying the context item, which is the entire document. You want
copy-of(/Report/Document)
依次复制每个文档.或者我倾向于写它
which copies each Document in turn. Or I tend to write it
/Report/Document/copy-of()
因为我认为它可以更清楚地说明正在发生的事情.
because I think it makes it clearer what is going on.
顺便说一下,这里不需要 xsl:iterate:xsl:for-each 可以很好地完成这项工作,因为对一个 Document 的处理不依赖于对任何先前文档的处理.
Incidentally you don't need xsl:iterate here: xsl:for-each will do the job perfectly well, because processing of one Document doesn't depend on the processing of any previous documents.
这篇关于XSLT 3.0 流(撒克逊)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!