[xsl] Can a streaming loop be inside a non-streaming loop?

Subject: [xsl] Can a streaming loop be inside a non-streaming loop?
From: "Roger L Costello costello@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 8 Aug 2025 11:27:32 -0000
Hi Folks,

I have an XML document, idents.xml, that contains a list of identifiers. For
each identifier, I want to loop--in a streaming fashion--over all the records
in a huge file (records.xml). Here's what I've tried:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
    xmlns:xs="http://www.w3.org/2001/XMLSchema";
    exclude-result-prefixes="#all"
    version="3.0">

    <xsl:output method="xml" />

    <xsl:variable name="identifiers" select="doc('idents.xml')/*"/>

    <xsl:template name="main">
        <xsl:source-document href="records.xml"
                                                streamable="yes">
            <results>
                <xsl:variable name="records" select="/*"/>
                <xsl:for-each select="$identifiers/identifier">
                    <xsl:variable name="ident" select="."/>
                    <xsl:for-each select="$records/record">
                        <xsl:variable name="record" select="copy-of(.)"/>
                        ...  (use $ident to process $record)
                    </xsl:for-each>
                </xsl:for-each>
            </results>
        </xsl:source-document>
    </xsl:template>

</xsl:stylesheet>

Running the above XSLT results in the following error message:

XTSE3430  The body of the xsl:source-document instruction is not streamable
  *  Operand {records} of {let $records := ...} selects streamed nodes in a
context that
  allows arbitrary navigation

What is the correct way to do this?

/Roger

Current Thread