Skip to content

Commit

Permalink
Revised to take account of comments
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelhkay committed Sep 27, 2023
1 parent eb4fab1 commit 6df49c1
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions specifications/xslt-40/src/xslt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26479,19 +26479,23 @@ the same group, and the-->

<p>This means that an accumulator that needs access to the typed value or string value of an element
can get this directly with a rule that matches the element, avoiding the need
to write rules that match the element's text node children.
to write rules that match the elements text node children.
</p>

<p>For example, to capture a copy of the most recent <code>h2</code> element in a document,
the following accumulator might be declared:</p>

<eg><![CDATA[<xsl:accumulator name="most-recent-h2" streamable="yes">
<xsl:accumulator-rule match="h2" capture="yes" select="."/>
<xsl:accumulator-rule match="h2" phase="end" capture="yes" select="."/>
</xsl:accumulator>]]></eg>

<p>and subsequent processing wishing to copy the most recent <code>h2</code> element into the result
tree can simply use <code>&lt;xsl:copy-of select="accumulator-before('most-recent-h2')"/></code>.</p>

<p>Without the <code>capture="yes"</code> attribute, this accumulator would be rejected
as non-streamable, because the <code>select</code> expression on the accumulator rule
is consuming.</p>

</note>

<example id="use-accumulator-to-create-glossary">
Expand All @@ -26510,10 +26514,21 @@ the same group, and the-->
capture="yes"
select="map:put($value, @term, .)"/>
</xsl:accumulator>]]></eg>
<p>At the end of processing, the map containing all the terms and their definitions (including
the internal markup) is available as the value
of <code>accumulator-before('glossary-terms')</code>, and this can be sorted and rendered in the usual way.</p>

<p>Suppose that the input XML document contains an element <code>&lt;glossary/></code> marking
the point where the glossary is to be inserted. The glossary can then be generated
using a template rule such as:</p>
<eg><![CDATA[<xsl:template match="glossary">
<h2>Glossary</h2>
<dl>
<xsl:for-each select="map:pairs(accumulator-before('glossary-terms'))">
<xsl:sort select="?key"/>
<dt>{?key}</dt>
<dd><xsl:apply-templates select="?value"/></dd>
</xsl:for-each>
</dl>
</xsl:template>]]></eg>


</example>


Expand Down Expand Up @@ -26561,7 +26576,10 @@ the same group, and the-->
the <termref def="dt-expression">expression</termref> in the <code>select</code> attribute or the contained
<termref def="dt-sequence-constructor"/>, with respect to the declared type of the accumulator,
is <termref def="dt-grounded"/> and <termref def="dt-motionless"/>.</p></item>
<item><p>The rule has <code>capture="yes"</code>.</p></item>
<item><p>The rule has <code>capture="yes"</code> and the <termref def="dt-sweep"/> of
the <termref def="dt-expression">expression</termref> in the <code>select</code> attribute or the contained
<termref def="dt-sequence-constructor"/>
is <termref def="dt-consuming"/> or <termref def="dt-motionless"/>.</p></item>
</olist>
</item>

Expand Down

0 comments on commit 6df49c1

Please sign in to comment.