0

I am getting this exception when transforming a xml with xslt:

Caused by: java.lang.OutOfMemoryError: Java heap space
at net.sf.saxon.tree.tiny.TinyTree.condense(TinyTree.java:430)
at net.sf.saxon.tree.tiny.TinyBuilder.close(TinyBuilder.java:206)
at net.sf.saxon.event.ReceivingContentHandler.endDocument(ReceivingContentHandler.java:244)
at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:449)
at net.sf.saxon.event.Sender.send(Sender.java:177)
at net.sf.saxon.Controller.makeSourceTree(Controller.java:1910)
at net.sf.saxon.s9api.XsltTransformer.transform(XsltTransformer.java:573)
at net.sf.saxon.jaxp.TransformerImpl.transform(TransformerImpl.java:185)
at com.lomnido.service.XsltTransformService.$tt__transform(XsltTransformService.groovy:27)

I am using Saxon-HE, version 9.7.0-5

My code:

 TransformerFactory factory = TransformerFactory.newInstance();

    StreamSource xsltStream = new StreamSource(xslt)
    factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);

    Transformer transformer = factory.newTransformer(xsltStream);

    StreamSource ins = new StreamSource(input);
    File tmp = File.createTempFile("test", "xslttransform")
    StreamResult out = new StreamResult(tmp);
    transformer.transform(ins, out);

The size of the xml file is about 100MB. Is there any way how I could avoid this problem? Is there something like streaming the input file? Is there an alternative to saxon? I need xslt 2.0 for my transformations.

Best regards, Peter

1

1 Answer 1

0

Processing a 100Mb source document should be perfectly feasible without resorting to XSLT 3.0 streaming. Just make sure you have allocated enough memory to the Java VM. The source document generally takes about 5 times the raw XML size, but of course it depends on the detail. But if you run with -Xmx2g, I certainly wouldn't expect this to fail unless something unusual is going on.

Once the size reaches 500Mb you probably do want to start to think about using XSLT 3.0 streaming. But you haven't said anything about what the transformation is doing, so it could be very easy, it could be fairly difficult, or it could be impossible, depending on the actual transformation to be performed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.