htmlxslt-3.0saxon-js

XSLT accumulator: How can you accumulate reference to elements


I have a number of elements I want to accumulate reference to and then at some point to present everyone one after the other. I tried the next option, but it only accumulates the value and not the element itself including all its atribiotics and text ..

The accumulator:

 <xsl:output omit-xml-declaration="no" indent="yes"/>
    <xsl:accumulator name="authorialNote_accumulator" as="xs:string*" initial-value="()">
        <xsl:accumulator-rule match="authorialNote" select="$value, @marker || ."/>
        <xsl:accumulator-rule match="eop" select="()" phase="end"/>
    </xsl:accumulator>

The template:

 <xsl:template match="eop" >
      
        <xsl:variable name="_authorialNote" select="accumulator-before('authorialNote_accumulator')"/>
                    <div class="authorial-note">
                        <xsl:for-each select="$_authorialNote">
                            <div eId="@eId">
                                <xsl:value-of select="."/>
                            </div>
                        </xsl:for-each>
                    </div>
                
    </xsl:template>

Someone has an idea how to do this


Solution

  • If you want to store an element node sequence then you need e.g.

    <xsl:accumulator name="authorialNote_accumulator" as="element()*" initial-value="()">
        <xsl:accumulator-rule match="authorialNote" select="$value, ."/>
        <xsl:accumulator-rule match="eop" select="()" phase="end"/>
    </xsl:accumulator>