xsl:stream
Used to initiate streamed processing of a source document.
Category: instruction
Content:
sequence-constructor
Permitted parent elements:
any XSLT element whose content model is sequence
constructor; any literal result element
Attributes
|
|
The URI of a source document. It can be written as an attribute value template if the URI is not known statically. |
|
|
|
|
|
Notes on the Saxon implementation
The xsl:stream
instruction is new in XSLT 3.0, fully implemented in
Saxon 9.6, and is available in Saxon-EE only (with XSLT 3.0 enabled).
Details
The body of the instruction is a sequence constructor, which is evaluated with the root node of the selected document as the context node. For streaming to work, this must be written as a streamable sequence constructor. Expressed very informally, this means it must only make downward selections in the document, and no instruction or expression may make more than one downward selection. The examples in the W3C specification illustrate some of the possibilities; these examples all work with Saxon.
Some of the things that the instruction might do are:
-
Compute an aggregate such as a total or average (see the example below).
-
Initiate processing of the document using template rules, by calling xsl:apply-templates using a streamable mode.
-
Iterate over the contents of the document using xsl:for-each or (if there is a need to "remember" information from one element to the next) using xsl:iterate.
-
Perform grouping of the document contents using xsl:for-each-group. Saxon only has limited ability to do streamed grouping, but simple cases should work. It is necessary to use one of the attributes
group-adjacent
,group-starting-with
, orgroup-ending-with
, and to use the new XSLT 3.0 binding variables for current group and current-grouping-key, rather than the XSLT 2.0 function.
For more details on streaming, see Streaming of Large Documents.
Examples
Example 1
A simple example:
<xsl:stream href="transactions.xml"> <out><xsl:value-of select="sum(*/transaction/value)"/></out> </xsl:stream>Example 2
See further examples in the W3C specification; these examples all work with Saxon 9.5 onwards.