Re: [xsl] Using sibling value in streaming mode

Subject: Re: [xsl] Using sibling value in streaming mode
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 30 Aug 2019 22:38:17 -0000
On 30.08.2019 23:49, Martin Honnen martin.honnen@xxxxxx wrote:
On 30.08.2019 23:18, Martynas JuseviD
ius martynas@xxxxxxxxxxxxx wrote:

The value of <string key="id"> is used as <id> in <item> elements. The
problem is that <string key="id"> can occur in any position in the

I've tried using an accumulator such as

<xsl:accumulator name="map-id" initial-value="()" streamable="yes"
B B B  <xsl:accumulator-rule match="/array/map/string[@key = 'id']/text()"

and then

B B B B  <id><xsl:value-of select="accumulator-before('map-id')"/></id>
B B B B  ...

That worked partially -- only for sibling <string> elements that
followed the <string key="id">. Which is not surprising.

I've also tried accumulator-after('map-id') but got:

B B  XTSE3430: Template rule is not streamable
B B  * A call to accumulator-after() is consuming when there are no
preceding consuming instructions

Is it possible to have a streaming solution in this case?

Some buffering will be needed, converting the whole XML map structure in
an XPath 3.1 map stored in an accumulator might also work.

While storing the XML "map" in an XPath 3.1 is possible such a map
doesn't preserve the order of the "string" elements so perhaps using a
sequence of maps (or, as Saxon 9.9 EE also supports a tuple type_) is

<xsl:stylesheet xmlns:xsl="";

<xsl:output indent="yes"/>

    <xsl:mode streamable="yes" on-no-match="shallow-skip"
use-accumulators="values map-id"/>

    <xsl:accumulator name="map-id" initial-value="()" streamable="yes"
        <xsl:accumulator-rule match="array/map" select="()"/>
        <xsl:accumulator-rule match="/array/map/string[@key = 'id']/text()"

    <xsl:accumulator name="values" as="tuple(key: xs:string, val:
xs:string)*" streamable="yes" initial-value="()">
        <xsl:accumulator-rule match="array/map" select="()"/>
        <xsl:accumulator-rule match="array/map/*[@key[not(. =
            select="$value, map{ 'key' : string(../@key), 'val'
:string() }"/>

    <xsl:template match="array/map">
            <xsl:apply-templates select="accumulator-after('values')"
                <xsl:with-param name="map-id"

    <xsl:template match=".[. instance of tuple(key: xs:string, val:
xs:string)]" mode="item">
        <xsl:param name="map-id"/>


Needs to be run in Saxon EE with
for the tuple type syntax extension to be recognized and supported.

Current Thread