Removing duplicate XML node by keeping the first occurence using XSLT

SteveC

New Member
Input file:\[code\] <myroot> <nodeA id="a"> <section id="i"> <item id="0" method="a"> <!-- parent section id="i" , keep this node--> <somechild>a</somechild> </item> <item id="1" method="a"> <otherchild>a</otherchild> </item> </section> <cell id="i"> <part id="1" method="b"> <!-- parent cell id="i", keep this node--> <attr>u</attr> </part> </cell> <section id="i"> <item id="0" method="a"> <!-- parent section id="i", remove this node--> <type>blah</type> </item> <item id="3" method="a"> <other>xx</other> </item> <item id="0" method="b"> <!-- this has same id but different method, so we keep this --> <otherchild>a</otherchild> </item> </section> <cell id="i"> <part id="1" method="b"> <!-- parent cell id="i", remove this node --> <attr>y</attr> </part> </cell> </nodeA> <nodeA id="b"> <section id="i"> <item id="1" method="a"> <otherchild>a</otherchild> </item> </section> <section id="i"> <item id="0" method="a"> <type>blah</type> </item> <item id="1" method="a"> <other>xx</other> </item> </section> </nodeA> <nodeB id="a"> <cell id="i"> <part id="1" method="b"> <attr>u</attr> </part> </cell> <section id="i"> <item id="0" method="a"> <type>blah</type> </item> </section> <cell id="i"> <part id="1" method="b"> <attr>y</attr> </part> </cell> </nodeB></myroot>\[/code\]output:\[code\]<myroot> <nodeA id="a"> <section id="i"> <item id="0" method="a"> <somechild>a</somechild> </item> <item id="1" method="a"> <otherchild>a</otherchild> </item> </section> <cell id="i"> <part id="1" method="b"> <attr>u</attr> </part> </cell> <section id="i"> <item id="3" method="a"> <other>xx</other> </item> <item id="0" method="b"> <!-- this has same id but different method, so we keep this --> <otherchild>a</otherchild> </item> </section> </nodeA> <nodeA id="b"> <section id="i"> <item id="1" method="a"> <otherchild>a</otherchild> </item> </section> <section id="i"> <item id="0" method="a"> <type>blah</type> </item> </section> </nodeA> <nodeB id="a"> <cell id="i"> <part id="1" method="b"> <attr>u</attr> </part> </cell> <section id="i"> <item id="0" method="a"> <type>blah</type> </item> </section> </nodeB></myroot>\[/code\]Can anyone help me with the transformation, so that if one node occur two or more times and have the same parent id, we only keep the first occurrence and disregard the others.Also there is another element in the file namely \[code\]<nodeB></nodeB>\[/code\], \[code\]<nodeC></nodeC>\[/code\]. etc.Thanks very much.John
 
Back
Top