xsl:for-each-group

The xsl:for-each-group element selects a sequence of nodes and/or atomic values and organizes them into subsets called groups. There are four possible ways of defining the grouping:

Saxon implements the xsl:for-each-group instruction in full. For examples of using the instruction, see the XSLT 2.0 specification.

In XSLT 3.0, the capabilities of the xsl:for-each-group instruction are extended by virtue of the fact that the pattern used in group-starting-with or group-ending-with can now match atomic values as well as nodes.

XSLT 3.0 introduces the ability to bind variables to the current group and the current grouping key as an alternative to using the functions current-group() and current-grouping-key(). The advantage of using variables is that they have static scope, so the optimizer has more chance to see what the stylesheet is doing with each group. Streamed processing is only possible if the new variables are used, as this enables the processor to determine whether or not the use of the current group is streamable.