Project

Profile

Help

Feature #6307 ยป accumulator-trace-example.xsl

A Galtman, 2023-12-27 22:51

 
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ex="example"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
version="3.0">

<xsl:accumulator name="indent-level" as="xs:integer" initial-value="0">
<xsl:accumulator-rule match="element() | text() | comment() | processing-instruction()"
select="$value + 1"/>
<xsl:accumulator-rule match="element() | text() | comment() | processing-instruction()"
phase="end"
select="$value - 1"/>
</xsl:accumulator>
<!-- The two-value-queue accumulator, as a stepping stone toward prior-value,
stores another accumulator's last value and current value. -->
<xsl:accumulator name="two-value-queue" initial-value="()" as="map(*)?">
<xsl:accumulator-rule match="element() | text() | comment() | processing-instruction() | document-node()"
phase="start">
<xsl:map>
<xsl:map-entry key="'prior'" select="if (exists($value)) then $value('current') else ()"/>
<xsl:map-entry key="'current'" select="accumulator-before('indent-level')"/>
</xsl:map>
</xsl:accumulator-rule>
<xsl:accumulator-rule match="element() | text() | comment() | processing-instruction() | document-node()"
phase="end">
<xsl:map>
<xsl:map-entry key="'prior'" select="$value('current')"/>
<xsl:map-entry key="'current'" select="accumulator-after('indent-level')"/>
</xsl:map>
</xsl:accumulator-rule>
</xsl:accumulator>

<xsl:template name="xsl:initial-template">
<xsl:variable name="context">
<one>
<two>
<three/>
</two>
</one>
</xsl:variable>
<xsl:for-each select="$context//three">
<xsl:sequence select="accumulator-before('two-value-queue')?current" />
</xsl:for-each>
</xsl:template>

<!-- Saxon command arguments: java -cp "%SAXON_CP%" net.sf.saxon.Transform -opt:0 -T -Tlevel:high -it -xsl:... -->

<!-- Trace in Saxon 12.4 is missing all the accumulator usage information

<trace saxon-version="12.4" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="xsl:initial-template" line="35" column="45" module="accumulator-trace-example.xsl">
<xsl:variable name="context" line="36" column="34" module="accumulator-trace-example.xsl">
<trace line="37" column="12" module="accumulator-trace-example.xsl">
<LRE name="one" line="37" column="12" module="accumulator-trace-example.xsl">
<LRE name="two" line="38" column="14" module="accumulator-trace-example.xsl">
<LRE name="three" line="39" column="19" module="accumulator-trace-example.xsl">
</LRE>
</LRE>
</LRE>
</trace>
<forEach line="43" column="44" module="accumulator-trace-example.xsl">
</forEach>
</xsl:variable>
</xsl:template>
</trace>

-->
<!-- Trace in Saxon 9.9.1.8 is missing xsl:accumulator-rule and xsl:accumulator, but at least has the xsl:map and xsl:map-entry lines
<trace saxon-version="9.9.1.8" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="xsl:initial-template" line="35" column="45" module="accumulator-trace-example.xsl">
<xsl:variable name="context" line="36" column="34" module="accumulator-trace-example.xsl">
<LRE name="one" line="37" column="12" module="accumulator-trace-example.xsl">
<LRE name="two" line="38" column="14" module="accumulator-trace-example.xsl">
<LRE name="three" line="39" column="19" module="accumulator-trace-example.xsl">
</LRE>
</LRE>
</LRE>
<xsl:for-each line="43" column="44" module="accumulator-trace-example.xsl">
<source node="/one/two[1]/three[1]" line="39" file="">
<xsl:sequence line="44" column="78" module="accumulator-trace-example.xsl">
<xsl:map line="21" column="16" module="accumulator-trace-example.xsl">
<xsl:map-entry line="22" column="99" module="accumulator-trace-example.xsl">
</xsl:map-entry>
<xsl:map-entry line="23" column="85" module="accumulator-trace-example.xsl">
</xsl:map-entry>
</xsl:map>
<xsl:map line="21" column="16" module="accumulator-trace-example.xsl">
<xsl:map-entry line="22" column="99" module="accumulator-trace-example.xsl">
</xsl:map-entry>
<xsl:map-entry line="23" column="85" module="accumulator-trace-example.xsl">
</xsl:map-entry>
</xsl:map>
<xsl:map line="21" column="16" module="accumulator-trace-example.xsl">
<xsl:map-entry line="22" column="99" module="accumulator-trace-example.xsl">
</xsl:map-entry>
<xsl:map-entry line="23" column="85" module="accumulator-trace-example.xsl">
</xsl:map-entry>
</xsl:map>
<xsl:map line="21" column="16" module="accumulator-trace-example.xsl">
<xsl:map-entry line="22" column="99" module="accumulator-trace-example.xsl">
</xsl:map-entry>
<xsl:map-entry line="23" column="85" module="accumulator-trace-example.xsl">
</xsl:map-entry>
</xsl:map>
<xsl:map line="28" column="16" module="accumulator-trace-example.xsl">
<xsl:map-entry line="29" column="66" module="accumulator-trace-example.xsl">
</xsl:map-entry>
<xsl:map-entry line="30" column="84" module="accumulator-trace-example.xsl">
</xsl:map-entry>
</xsl:map>
<xsl:map line="28" column="16" module="accumulator-trace-example.xsl">
<xsl:map-entry line="29" column="66" module="accumulator-trace-example.xsl">
</xsl:map-entry>
<xsl:map-entry line="30" column="84" module="accumulator-trace-example.xsl">
</xsl:map-entry>
</xsl:map>
<xsl:map line="28" column="16" module="accumulator-trace-example.xsl">
<xsl:map-entry line="29" column="66" module="accumulator-trace-example.xsl">
</xsl:map-entry>
<xsl:map-entry line="30" column="84" module="accumulator-trace-example.xsl">
</xsl:map-entry>
</xsl:map>
<xsl:map line="28" column="16" module="accumulator-trace-example.xsl">
<xsl:map-entry line="29" column="66" module="accumulator-trace-example.xsl">
</xsl:map-entry>
<xsl:map-entry line="30" column="84" module="accumulator-trace-example.xsl">
</xsl:map-entry>
</xsl:map>
</xsl:sequence>
</source><!-/- /one/two[1]/three[1] -/->
</xsl:for-each>
</xsl:variable>
</xsl:template>
</trace>

-->
</xsl:stylesheet>
    (1-1/1)