Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAXP XSLT document() function problem

I am working under java application which uses XSLT transformation. I have a lot of document() calls in it, so it is possible to have java.lang.OutOfMemory exception (which I actually have), because after each call of document() function the document is cached.

At http://xml.apache.org/xalan-j/faq.html#faq-N102F9 I read that it is possible to increase heap memory size which is not the solution in my case. I also tried to use incremental transform which seems to be not supported.

So, is there any possibility to turn off document caching in jaxp while working with document() function?

like image 513
deephace Avatar asked Oct 10 '22 18:10

deephace


1 Answers

Like user1066037's answer, hopefully you can switch to Saxon. Saxon has an extension called saxon:discard-document. It's available in either the PE or EE editions or Saxon-B. Search for "Saxon-B" here: http://saxon.sourceforge.net/

From the Saxon documentation:

saxon:discard-document()

saxon:discard-document($doc as document-node()) ==> document-node()

This function removes a document from Saxon's internal document pool. The document remains in memory for the time being, but will be released from memory by the Java garbage collector when all references to nodes in the document tree have gone out of scope. This has the benefit of releasing memory, but the drawback is that if the same document is loaded again during the same transformation, it will be reparsed from the source text, and different node identifiers will be allocated. The function returns the document node that was supplied as an argument, allowing it to be used in a call such as select="saxon:discard-document(document('a.xml'))".

If you need an example of how to use saxon:discard-document, let me know and I can post one.

like image 186
Daniel Haley Avatar answered Oct 14 '22 02:10

Daniel Haley