I have a following XML
This transformation implements exactly the stated requirements. It takes special care to preserve the exact order of the elements that are not to be sorted. No other answer at present does this:
When applied on the following XML document (the same as the provided one, but with an additional
inserted between Data1
and Data2
so that we can verify the preservation of ordering of the non-sorted elements):
2222
field1
ABC
field2
1111
field1
XYZ
field2
produces the wanted, correct result -- note that the position of
is preserved:
1111
field1
XYZ
field2
2222
field1
ABC
field2