Streaming using XSLT 3.0

Saxon-EE (as at Saxon 9.7) is very close to the draft XSLT 3.0 recommendation in terms of the streaming facilities it supports. Late changes made to the specification have generally been implemented in Saxon 9.7 maintenance releases. Specifically, Saxon 9.7.0.15 implements all the streaming features in the Candidate Recommendation of 7 February 2017, with the exception of streamable stylesheet functions. There are also some extensions.

There are two main ways to initiate a streaming transformation:

  1. Using the xsl:stream instruction, where the source document is identified within the stylesheet itself. Typically such a stylesheet will have a named template as its entry point, and will not have any principal source document supplied externally.
  2. By supplying a source document as input to a stylesheet whose initial mode is declared with streamable="yes" in an xsl:mode declaration. In this case the source document must be supplied as a StreamSource or SAXSource, and not as an in-memory tree.

The saxon:stream extension function used in previous releases is still supported for the time being. In Saxon 9.7 a call on saxon:stream is translated at compile time into a call on the XSLT 3.0 <xsl:stream> instruction. The original Saxon mechanism for streaming, namely the saxon:read-once attribute on xsl:copy-of, was dropped in Saxon 9.6.

The rules for whether a construct is streamable or not are largely the same in Saxon as in the XSLT 3.0 specification. Saxon applies these rules after doing any optimization re-writes, so some constructs end up being streamable in Saxon even though they are not guaranteed streamable in the W3C spec, because the Saxon optimizer rewrites the expression into a streamable form. An example of this effect is where variables or functions are inlined before doing the streamability analysis. In contrast, when streaming is requested, the optimizer takes care to avoid rewriting streamable constructs into a non-streamable form.

This documentation does not attempt to provide a tutorial introduction to the streaming capabilities of XSLT 3.0. The specification itself is not easy to read, especially the detailed rules on which constructs are deemed streamable. However, for the most part it is not necessary to be familiar with the detailed rules. The main things to remember are:

The XSLT 3.0 constructs most relevant to streaming are:

All these facilities are available in Saxon-EE only. Streamed templates and accumulators also require XSLT 3.0 to be enabled by setting the relevant configuration parameters or command line options.