I have following xml. Note that node n1 and n3 have same children (order can be different). How can I write an XSL transformation to identify such nodes?
<Document>
<Node name="n1">
<Item value="v1">
<Item value="v2">
<Item value="v3">
</Node>
<Node name="n2">
<Item value="p1">
<Item value="p2">
<Item value="p3">
</Node>
<Node name="n3">
<Item value="v3">
<Item value="v1">
<Item value="v2">
</Node>
</Document>
Here is a complete XSLT 1.0 solution that is general enough so that it would produce correct results even when a
Nodeis allowed to have children with any name:when applied on this XML document:
the wanted, correct result is produced:
Explanation:
This is a two-pass transformation.
The result of the first pass is an XML fragment containing
Nodeelements with theirnameattribute and one newly added attribute:signature. This is the concatenation of the names and values of all children (in normal, sorted form). The result of pass1 in this concrete case is the following:In pass 2 we use the Muenchian method for grouping all
Nodeelements by theirsignatureattribute. The firstNodein every group is represented in the output with a new attributematcheswhose value is the space-delimited concatenation of thenameattributes of the remainingNodeelements in the current group.