Incremental/streaming XSLT transformations?

偶尔善良 提交于 2020-01-02 07:11:28

问题


I'm normally using the XSLT support in the JDK (JDK 7) for XSLT transformations. Recently I've come across a rather large XML document, and applying XSLT transformations to this (even very basic ones) causes a lot of memory to be used.

I've been careful to do all my processing streaming, but it seems the XSLT engine in the JDK (which appears to be a modified Xalan) always builds up a DOM in memory first. Obviously this is not what I want.

Now I found out that the Xalan which is available separately (2.7.1 from 2007!) does have an API for doing incremental transformations. So while this does seem to work, I actually want my code to run on a stock JDK, without telling the user to fiddle with any endorsed folder.

What is the best way to do incremental XSLT transformations in Java so that my code is compatible with unmodified/stock JDK installations?

update: This recently updated question is strongly related: What is the Most Efficient Java-Based streaming XSLT Processor?


回答1:


Firstly, I would strongly recommend using the Apache versions of Xalan and Xerces rather than the versions bundled in the JDK, which are very buggy. That's particularly true for Xerces.

Secondly, if you're using Java then you really ought to be moving to XSLT 2.0, which gives you vast improvements in development productivity. In practice that means Saxon (the home edition of Saxon is free).

Incremental transformation in Xalan doesn't actually stop it building the whole source document as a tree in memory; all it does is to allow the tree to be built in parallel with the transformation process. If you want a streaming transformation, Saxon-EE is your only practical option. (Note that the saxon:stream() extension is only one small part of the streaming capabilities that Saxon offers).




回答2:


Have you tried the saxon:stream() extension in Saxon?



来源:https://stackoverflow.com/questions/10880608/incremental-streaming-xslt-transformations

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!