Grouping in XSLT 1.0 is hard. XSLT 2.0 provides a new, flexible grouping instruction for grouping…
on a specific key
by transitions at the start of each group
by transitions at the end of each group
by adjacent key values
Groups can also be sorted.