On 08/08/2025 13:27, Roger L Costello costello@xxxxxxxxx wrote:
> 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?
>
Can't you just stream through, materialize each "record" and then
process each repeatedly with the identifier list?
<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:for-each select="records/record">
<xsl:variable name="record" select="copy-of(.)"/>
<xsl:for-each select="$identifiers/identifier">
<xsl:variable name="ident" select="."/>
... (use $ident to process $record)
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</results>
</xsl:source-document>
</xsl:template>
</xsl:stylesheet>
|