I know there are few xml/xslt merge related questions here however none seems to solve the problem I have.
What I am looking is an XSLT (as generic as possible - not tig
The following XSLT 1.0 program does what you want.
Apply it to b.xml and pass in the path to a.xml as a parameter.
Here is how it works.
B, as that contains the new nodes that you want to keep as well as the common elements between A and B.
ancestor-or-self axis.B, would have a simple path of root_node/settings/setting3/setting31/.calculatePath.nodeValueByPath is called that tries to retrieve the text value of the corresponding simple path from the other document.B. This satisfies your second bullet point.As a result, the new document matches B's structure and contains:
B that have no corresponding node in A.A when a corresponding node in B exists.Here's the XSLT: