1
first
2
second
I. Here is a complete and very short XSLT 1.0 solution:
when this transformation is applied on the provided XML document:
1
first
2
second
3
first
the wanted, correct result is produced:
1
first
3
first
2
second
Do note:
The use of the Muenchian method for grouping. This is the most efficient grouping method in XSLT 1.0.
The use of AVT (Attribute Value Template) to specify a literal result element and its variable - value attribute as one whole. Using AVTs simplifies coding and yields shorter and more understandable code.
II. An even shorter XSLT 2.0 solution:
when this transformation is applied on the same XML document (above), the same correct result is again produced.
Do note:
.1. The use of the
.2. The use of the standard XSLT 2.0 functions current-group() and current-grouping-key()