XML technologies / XSLT / XSLT 3.0 / XSLT streaming / streamability rules

First, common terms in XSLT streaming are explained, followed by rules that must be observed to process files in streaming mode.

 

Terms

These XSLT streaming definitions come from Michael Kay, Streaming in the Saxon XSLT Processor. in: XML Prague 2014 Conference Prodeedings. February 2014. XML Prague 2014. pp. 83ff.

Sweep

sweep = scanning; describes how often the input XML document is needed to evaluate a construct.

  • motionless = motionless

    An expression is motionless when the XSLT processor need not move from its current stream position, using only the current context. An expression that does not use the input document is also motionless.

    For example, name() or attributes of the current node.

  • consuming = consuming

    Evaluation reads all content between the current element’s start and end tags.

    Examples: string(), data(), number(), xsl:value-of, xsl:copy.

  • free-ranging = context-independent

    The construct needs streamed data outside the current context. That context reaches only the current element, its attributes, and all ancestors with their attributes.

    Examples: preceding-sibling::abc, following-sibling::abc, xsl:number.

    Streaming is therefore impossible: it needs siblings, preceding or following elements outside the context.

Posture

posture = position; describes where an input element or node processed by an expression comes from.

  • grounded = grounded

    The expression returns no elements from the streamed input, only atomic values or elements from a nonstreamed document.

  • striding = striding

    The expression returns input elements, none of which contains further elements.

  • crawling = crawling

    The expression returns input elements that, unlike striding, may contain children.

  • climbing = climbing

    All ancestors and attributes are available from the current context, but afterwards the currently processed element is no longer accessible.

  • roaming = roaming

    The expression navigates to unavailable parts of the streamed document, such as siblings or preceding or following elements.

 

rules

Streamability requires that the processor reads the document once, visiting each node only once. Elements are not processed repeatedly, so stylesheets not designed for streaming usually need rewriting.

Streaming provides only the current node, ancestors and descendants, including their attributes. Siblings, preceding and following elements are unavailable. (See the unsigned XSL Transformations (XSLT) Version 3.0: 2.10 Streaming.)

Streamability rules of thumb

(See Abel Braaksma. XSLT 3.0 Streaming for the masses. in: XML Prague 2014 Conference Prodeedings. February 2014. XML Prague 2014. pp. 40–59.)

  1. Each template may contain at most one downward expression.

    For example, <xsl:apply-templates select="Ausdruck"/>, <xsl:value-of select="Ausdruck"/> etc.

    Split child processing among several templates to work around this restriction.

  2. Each construct may contain at most one downward expression.

    A construct is an instruction or expression, such as xsl:template, xsl:for-each, xsl:iterate, xsl:apply-templates, xsl:sequence etc.

  3. Use motionless expressions where possible.

    Examples:

    • name(), self::abc or @abc (attribute axis)

    • XPath functions accepting only atomic arguments (string(.))

    • XPath functions not using XML stream input (current-dateTime())

    • XPath functions using only the current node (exists(.), not(.))

    • Instructions creating new nodes (xsl:comment, xsl:element, xsl:attribute)

  4. You may move up the tree, but not back down.

    The ancestor axis stays in memory. XML hierarchy is assumed to be bounded so all required ancestor information fits there.

    Moving up loses access to the current node; otherwise all siblings would need buffering. Reading an ancestor’s attribute is an example.

    Allowed: parent::paper[parent::archive] or exists(parent::paper).

    Not allowed: parent::paper[name = 'John Doe'] (the predicate contains a downward expression), or parent::paper/string() (siblings would have to be read).

  5. burst mode.

    To partly bypass streaming restrictions, process subtrees in an additional nonstreaming mode, with unrestricted XSLT capabilities.

    This is often called burst mode or windowed streaming.

    Store the entire subtree in a variable, then process it in a separate nonstreaming mode.

    Ensure it fits in memory. Small parts often process independently, such as an address in a directory or a book in a collection.

    For burst mode examples, see burst mode.

  6. Use motionless filters.

    XPath predicates follow motionless-expression rules. Examples:

    *[self::para] or price[@currency[starts-with(.,'EUR')]].

   

back to top