xsl:stream
Used to initiate streamed processing of a source document. (In a later draft of
the XSLT 3.0 specification, the instruction is renamed xsl:source-document, which is available since
Saxon 9.7.0.8, while xsl:stream
is retained as a synonym.)
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. |
|
|
Allowed since 9.7.0.8.
Used to specifically request streamed processing. The default is
|
|
|
Defines the set of accumulators that are applicable to the document. |
|
|
|
|
|
Notes on the Saxon implementation
In the latest draft of the XSLT 3.0 specification, the xsl:stream
instruction is replaced by xsl:source-document, which is available since
Saxon 9.7.0.8. The xsl:stream
instruction is retained as a synonym.
The xsl:stream
instruction is new in XSLT 3.0, fully implemented
since 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.