Skip to content

xsl:accumulator-rule

Defines a rule for an xsl:accumulator.

Available in XSLT 3.0. From Saxon 9.8, available in all editions. Implemented in Saxon-PE and Saxon-EE since Saxon 9.6.

Attributes

match
pattern
Pattern defining the set of nodes to which the accumulator rule applies.
phase?
"start" | "end"
Determines whether the rule fires before or after descendants are processed, by specifying phase="start" (the default) or phase="end" respectively.
select?
expression
The expression to be evaluated by the rule may be given either by a select attribute, or by an enclosed sequence constructor.
saxon:capture?
boolean
The value "yes|true|1" on a phase="end" rule for a streaming accumulator removes the requirement for the select attribute (or sequence constructor) to be motionless. Instead the expression has access to a snapshot of the streamed node (in the sense of the fn:snapshot function). For example, writing select="($value, .)" ensures that the value of the accumulator contains a sequence of snapshot copies of all the element nodes matched by the accumulator rule. For details see saxon:capture.

Examples

For an example of the use of a capturing accumulator rule to construct the glossary of a document, see the blog article Capturing Accumulators.

Example

<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <!-- Declare accumulator for calculating minimum salary -->
  <xsl:accumulator name="min-salary" initial-value="10000000">
    <!-- Define rule for employee elements -->
    <xsl:accumulator-rule match="employee" select="if (@salary lt $value) then @salary else $value"/>
  </xsl:accumulator>

  <!-- The rest of the style -->
</xsl:stylesheet>

See also

Comments