xsl:source-document

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

href

{ uri }

The URI of a source document. It can be written as an attribute value template if the URI is not known statically.

streamable?

boolean

Used to request streamed processing. The value no (the default) is currently ignored.

use-accumulators?

tokens

Defines the set of accumulators that are applicable to the document.

validation?

"strict" | "lax" | "preserve" | "strip"

type?

eqname

Notes on the Saxon implementation

The xsl:source-document instruction (used with the attribute streamable="yes") replaces the xsl:stream instruction from earlier drafts of the XSLT 3.0 specification. It is available since Saxon 9.7.0.8, 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:

  1. Compute an aggregate such as a total or average (see the example below).

  2. Initiate processing of the document using template rules, by calling xsl:apply-templates using a streamable mode.

  3. 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.

  4. 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, or group-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:source-document streamable="yes" href="transactions.xml"> <out><xsl:value-of select="sum(*/transaction/value)"/></out> </xsl:source-document>

Example 2

See further examples in the W3C specification; these examples all work with Saxon 9.5 onwards.

Links to W3C specifications

XSLT 3.0 Specification

See also

xsl:apply-templates

xsl:for-each

xsl:for-each-group

xsl:iterate