SAXONICA

Saxon Documentation
Full Contents
About Saxon
Changes in this Release
Notices
Using XSLT 2.0
Using XQuery
Handling Source Documents
| Handling Source Documents
| Source Documents on the Command Line
| Collections
| Building a Source Document from an application
| Preloading shared reference documents
| Writing input filters
| XInclude processing
| Saxon and XML 1.1
| JAXP Source Types
| Third-party Object Models: DOM, JDOM, XOM, and DOM4J
| Choosing a Tree Model
| The PTree File Format
| Validation of Source Documents
| Whitespace Stripping in Source Documents
» | Streaming of Large Documents
| Document Projection
XML Schema Processing
XPath API for Java
Saxon on .NET
Extensibility
Saxon Extensions
Sample Saxon Applications
The Saxon SQL Extension
XSLT Elements
XPath 2.0 Expression Syntax
Function Library
Standards Conformance

# Processing the nodes returned by saxon:stream()

The nodes selected by the streamed expression may be further processed. For example:

XSLT example

    <xsl:template name="main">
      <xsl:apply-templates select="saxon:stream(doc('customers.xml')/*/customer)"
                           xmlns:saxon="http://saxon.sf.net/"/>
    </xsl:template>

    <xsl:template match="customer">
      <xsl:value-of select="code, name, location" separator="|"/>
      <xsl:text>&#xa;</xsl:text>
    </xsl:template>

XQuery example

    declare function f:customers() {
       saxon:stream(doc('customers.xml')/*/customer)
    };

    for $c in f:customers()
    return concat(string-join(($c/code, $c/name, $c/location), '|'), '&#xa;')

Conceptually, `saxon:stream()` evaluates the sequence supplied in its first argument as a sequence of nodes, and then makes copies of these nodes as described in the rules of the `xsl:copy-of` instruction. The significance of the (notional) copy operation is that the returned nodes have no ancestors or siblings; each is the root of its own tree.

The document that is processed in streaming mode must be read using the `doc()` function (or in XSLT, the `document()` function). The query or stylesheet may also process other documents (for example a document named on the command line) but this is not necessary. In XSLT it is often useful to activate the stylesheet at a named template using the `-it` option on the command line, which allows activation without a primary input document.

When streaming copy is used, the relevant calls on the `doc()` or `document()` functions are not stable: that is, there is no guarantee that if the same document is read more than once, its contents will be unchanged. This is because the whole point of the facility is to ensure that Saxon does not need to keep the content of the document in memory. This limitation explains the choice of the keyword `read-once`: the facility should not be used to process a document if it needs to be read more than once during the query or transformation.

Next