Compare and merge 2 xmls to 1 by removing common nodes and a

admin

Administrator
Staff member
I am pretty new to XSL. Let me just get to the question.
I have couple of xmls which needs to be compared first and merged depending on the data on the XML_COPY.xml file. If there are common IDs for a particular FLDR_NAME then copy the RPT node from the XML_COPY xml otherwise retain the XML_ORIG xml. If new FLDR_NAME or ID is found in XML_COPY xml then that node has to be added in the output xml file. Does that make sense!!!
XML_ORIG.xml
<FLDRS>
<FLDR>
<FLDR_NAME>ABC</FLDR_NAME>
<RPT>
<ID>D001</ID>
<NAME>A</NAME>
</RPT>
<RPT>
<ID>D002</ID>
<NAME>B</NAME>
</RPT>
</FLDR>
<FLDR>
<FLDR_NAME>DEF</FLDR_NAME>
<RPT>
<ID>D004</ID>
<NAME>D</NAME>
</RPT>
<RPT>
<ID>D005</ID>
<NAME>E</NAME>
</RPT>
</FLDR>
</FLDRS>

XML_COPY.xml
<FLDRS>
<FLDR>
<FLDR_NAME>ABC</FLDR_NAME>
<RPT>
<ID>D002</ID>
<NAME>B1</NAME>
</RPT>
<RPT>
<ID>D003</ID>
<NAME>C</NAME>
</RPT>
</FLDR>
<FLDR>
<FLDR_NAME>XYZ</FLDR_NAME>
<RPT>
<ID>D006</ID>
<NAME>X</NAME>
</RPT>
<RPT>
<ID>D007</ID>
<NAME>Y</NAME>
</RPT>
</FLDR>
</FLDRS>
Output should be...
XML_OUTPUT.xml
<FLDRS>
<FLDR>
<FLDR_NAME>ABC</FLDR_NAME>
<RPT>
<ID>D001</ID>
<NAME>A</NAME>
</RPT>
<RPT>
<ID>D002</ID>
<NAME>B1</NAME>
</RPT>
<RPT>
<ID>D003</ID>
<NAME>C</NAME>
</RPT>
</FLDR>
<FLDR>
<FLDR_NAME>DEF</FLDR_NAME>
<RPT>
<ID>D004</ID>
<NAME>D</NAME>
</RPT>
<RPT>
<ID>D005</ID>
<NAME>E</NAME>
</RPT>
</FLDR>
<FLDR>
<FLDR_NAME>XYZ</FLDR_NAME>
<RPT>
<ID>D006</ID>
<NAME>X</NAME>
</RPT>
<RPT>
<ID>D007</ID>
<NAME>Y</NAME>
</RPT>
</FLDR>
</FLDRS>

Is it possible to do this in an XSL where I can pass the path names of the xmls to be compared. Any kind of help would be deeply appreciated. I have lost considerable amount of time on this code.

Thanks.........
 
Back
Top