I have two files, and want to combine/overwrite whole nodes based on a particular matching value in a node tree.
file1.xml
<record>
<key>key1</key>
<nodel>
<field1>source field1</field1>
<field2>source field2</field2>
<searchkey>myname</searchkey>
</nodel>
</record>
file2.xml
<record>
<key>key2</key>
<nodel>
<field1>match field1</field1>
<field2>match field2</field2>
<searchkey>myname</searchkey>
</nodel>
</record>
Desired output:
<record>
<key>key1</key>
<nodel>
<field1>source field1</field1>
<field2>source field2</field2>
<searchkey>myname</searchkey>
</nodel>
<nodel>
<field1>match field1</field1>
<field2>match field2</field2>
<searchkey>myname</searchkey>
</nodel>
</record>
So, I want to check for a match in the searchkey, between the two files, and, if it matches, copy the whole node of the match to the output file, but keep the original key, not the match one. I will then want to delete the original nodel, though am happy to do that as a later transform.
I did ask a recent similar question for matching on the <key> nodes, but couldn’t figure out how to modify it to achieve this desired result.
Thanks.
A solution with keys:
Output:
Note: I you don’t want to preserve the original
nodel, just strip away the firstxsl:call-templateinstruction.