Question

We are using Xalan XSLT to do XSL transform to generate HTML output i.e. XML+XSL=HTML.

Following is the code.

out=response.getOutputStream();
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer()
transformer.transform(new StreamSource(in), new StreamResult(out));

I do not want for the whole transform to finish before data is displayed on the browser. I want the StreamResult that has the HTML output to start sending data to the browser as it does perform xsl transform on individual XML nodes/XSL apply templates so that user gets the impression something is showing on the browser as it is generating because it is possible for the report XML to be big.

How do I achive that? Does Xalan XSLT support that? Does any other XSLT parser support it.

I would appreciate your advice.

Was it helpful?

Solution

The short answer is no, it's not possible to achieve this reliably with Xalan.

EDIT: However, it might be possible with extensions to Saxon - have a look at them.

As for the longer answer, the streaming capabilities of XSLT processors have seen some progress, but the results seem to be too unpredictable yet. For example, see this link: http://www.balisage.net/Proceedings/vol5/html/Kay01/BalisageVol5-Kay01.html for a discussion of an attempt to implement Streaming in Saxon.

It is assumed that the XSLT 3.0 Recommendation will embrace this question:

The primary purpose of the changes in this version of the language is to enable transformations to be performed in streaming mode, where neither the source document nor the result document is ever held in memory in its entirety.

See http://www.w3.org/TR/xslt-30/ for more information on this. This is only a working draft, though.

EDIT: For streaming with Xalan in particular, Michael Kay writes:

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. [...]

This is taken from Incremental/streaming XSLT transformations? , dating from 2012. Seems like StreamSource is not streaming, really.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top