Assuming that I have this:
<nodes>
<node>
<number>1</number>
<name>"ABC"</name>
<comment>"blah"</comment>
</node>
<node>
<number>2</number>
<name>"DEF"</name>
<comment>"blah blah"</comment>
</node>
<node>
<number>3</number>
<name>"XYZ"</name>
<comment>"blah blah blah"</comment>
</node>
</nodes>
I would like to end up with this:
<nodes>
<node>
<number>3</number>
<name>"XYZ"</name>
<comment>"blah blah blah"</comment>
</node>
<node>
<number>2</number>
<name>"DEF"</name>
<comment>"blah blah"</comment>
</node>
<node>
<number>1</number>
<name>"ABC"</name>
<comment>"blah"</comment>
</node>
</nodes>
I. In your case the solution is as simple as this:
When this transformation is applied on the provided XML document:
the wanted, correct result is produced:
II. Reversing a node-set inplace, whose nodes all belong to the same document:
Things become much more tricky if we want to reverse the nodes of a node-set and leave all other nodes in the document “as-is”.
Let’s nave this XML document:
We want to produce from this a document where the
numelements with odd value are in the same order, but thenumelements with even value come in reverse order. The result must be:Here is the transformation that produces the wanted result: