I have a set of sequential nodes that must be enclosed into a new element. Example:
cccc
aaaa<
In XSLT 1.0 the standard technique to handle this sort of thing is called Muenchian grouping, and involves the use of a key that defines how the nodes should be grouped and a trick using generate-id
to extract just the first node in each group as a proxy for the group as a whole.
This achieves the grouping you're after, but just like your non-general solution it doesn't preserve the indentation and the whitespace text nodes between the a
and b
elements, i.e. it will give you
cccc
aaaa
1111
bbbb
2222
Note that if you were able to use XSLT 2.0 then the whole thing becomes one for-each-group
: