I have two xml files, which need to be merged into one xml. Here is the example:
orginal.xml file :
<employees>
<employee id="1">
<name> Name1 </name>
<email> email1 <email>
</employee>
<employee id="2">
<name> Name2 </name>
<email> email2 <email>
</employee>
</employees>
update.xml file:
<employees>
<employee id="2">
<name> Name2 </name>
<email> email_New <email>
</employee>
<employee id="3">
<name> Name3 </name>
<email> email3 <email>
</employee>
</employees>
they should be merged to a xml file like this:
<employees>
<employee id="1">
<name> Name1 </name>
<email> email1 <email>
</employee>
<employee id="2">
<name> Name2 </name>
<email> email_New <email>
</employee>
<employee id="3">
<name> Name3 </name>
<email> email3 <email>
</employee>
</employees>
Actually, I'd like to use the update.xml to update the orginal.xml :
new employee in update.xml should be added to original.xml
modified employee information in update.xml should overwrite the corresponding employee node.
I know a little of XSLT, but my knowledge is not enough to figure out the right XSLT for the merge.
Please give this a try:
When run with your first XML as the input and with the update.xml present in the same folder, this produces:
fileName
andupdates
are declared as parameters, so if the updates are in a file named something other than "update.xml" or you want to pass the update XML in directly, you can do that without making any modifications to the XSLT.