gpt4 book ai didi

xml - XSLT 3.0 流式传输 (Saxon)

转载 作者:数据小太阳 更新时间:2023-10-29 01:51:35 31 4
gpt4 key购买 nike

我有一个很大的 XML 文件(6 GB),其中包含这种树:

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

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

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

所以我想尝试新的 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>

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

感谢您的帮助!

最佳答案

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

copy-of(/Report/Document)

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

/Report/Document/copy-of()

因为我认为它可以更清楚地说明正在发生的事情。

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

关于xml - XSLT 3.0 流式传输 (Saxon),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26225551/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com