I need to transform following repeating pattern
<root>
<bar>bar 1</bar>
<baz>baz 1</baz>
<qux>qux 1</qux>
<bar>bar 2</bar>
<baz>baz 2</baz>
<qux>qux 2</qux>
</root>
Into this;
<root>
<foo>
<bar>bar 1</bar>
<baz>baz 1</baz>
<qux>qux 1</qux>
</foo>
<foo>
<bar>bar 2</bar>
<baz>baz 2</baz>
<qux>qux 2</qux>
</foo>
</root>
But don't want to use loop solutions.
This transformation:
when applied on the provided XML document:
produces the wanted, correct result:
Do note:
The transformation doesn't need to know and hardcode any element name -- it just uses the fact that the sequence of elements names is repeating.
The use of keys to find all members of a group.
The use of modes to process the same nodes in more than one way.
Many, many solutions. This one use fine grained traversal:
Output:
Other solution: push style with key.