Is there an open source command-line tool (for Linux) to diff XML files which ignores the element order?
Example input file a.xml
:
You're requesting a sort based on the sequence of attributes in the elements being sorted. But your top-level tag
elements here have only one attribute: name
. If you want multiple tag
elements with name="BBB"
to sort differently, you need to give them distinct sort keys.
In your example, I'd try something like select="concat(name(), @name, name(*[1]), *[1]/@name)"
-- but this is a very shallow key. It uses values from the first child in the input, but the children may shift position during the process. You may be able (knowing your data better than I do) to calculate a good key for each element in a single pass, or you may just need several passes.