xsl:for-each-group
Selects a sequence of nodes and/or atomic values and organizes them into subsets called groups.
Category: instruction
Content: (
xsl:sort*
, sequence-constructor
)
Permitted parent elements:
any XSLT element whose content model is
sequence-constructor; any literal result element
Attributes
|
|
Expression to select nodes/values. |
|
|
Groups together all items having the same value for a grouping key. The grouping key may have multiple values (a sequence of values) in which case the item is added to more than one group. |
|
|
Groups together all items having the
same value for a grouping key, provided that they are also adjacent in the input
sequence. This is useful when you need to wrap a new element around a sequence
of related elements in the source documents, for example a consecutive sequence
of |
|
|
Processes the items in the
supplied sequence in turn, starting a new group whenever one of the items
matches a specified pattern. This is useful, for example, when matching an
|
|
|
Processes the items in the
supplied sequence in turn, closing the current group whenever one of the items
matches a specified pattern. This is useful when matching a sequence of items in
which the last item in the group carries some distinguishing attribute such as
|
|
|
Can be used when grouping using either
|
|
|
The name of a collating sequence, used
when comparing grouping keys. Can be used when grouping using either
|
Notes on the Saxon implementation
Earlier drafts of XSLT 3.0 introduced new attributes bind-group
and
bind-grouping-key
; these are no longer supported since Saxon
9.6.
The composite
attribute has been implemented since Saxon 9.6.
Since 9.6, Saxon supports streamed grouping when the group-adjacent
,
group-starting-with
, or group-ending-with
attributes are used, but not with a group-by
attribute.
A working draft of XSLT 3.0 introduced 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(), but this was later dropped from the specification. This feature was implemented in Saxon 9.6, but dropped since Saxon 9.7.
Details
There are four possible ways of defining the grouping using different attributes:
group-by
, group-adjacent
,
group-starting-with
, and group-ending-with
.
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.
Examples
For examples of using the instruction, see the XSLT 2.0 specification.