I need an XSL solution to replace XML nodes with new nodes.
Say I have the following existing XML structure:
XSL cannot replace anything. The best you can do is to copy the parts you want to keep, then output the parts you want to change instead of the parts you don't want to keep.
Example:
BBB
CCC
DDD
The template match @* | node() matches any attribute or any other kind of node. The trick is that template matches have priorities. You can think of the rule as being "the more specific match wins". Anything is going to be more specific than "any attribute or other node". This makes the "identity" match a very low priority.
When it is matched, it simply copies any nodes it finds inside the matched attribute or node.
Any other templates you have will have a higher priority. Whatever they match, it's the code inside the more specific template that will have effect. For example, if you simply removed everything inside of the criterion[.='AAA'] template, you'd find that you had copied your input exactly, except for the "AAA" element.