Reading source documents partially
As well as allowing a source document to be processed in a single sequential pass, the streaming facility in many cases allows the source document to be read only partially. For example, the following query will return true as soon as it finds a transaction with a negative value, and will then immediately stop processing the input file:some $t in saxon:stream(doc('big-transaction-file.xml')//transaction) satisfies number($t/@value) lt 0
This facility is particularly useful for extracting data that appears near the start of a large file. It does mean, however, that well-formedness or validity errors appearing later in the file will not necessarily be detected.
To exit early from reading a streamed document using pure XSLT 3.0 constructs, use xsl:iterate like this:<xsl:variable name="contains-debit" as="xs:boolean"> <xsl:source-document streamable="yes" href="big-transaction-file.xml"> <xsl:iterate select=".//transaction"> <xsl:on-completion select="false()"/> <xsl:if test="@value lt 0"> <xsl:break select="true()"/> </xsl:if> </xsl:iterate> </xsl:source-document> </xsl:variable>