How to do this xml elimination based on node attribute positions using XSLT ?

phil2396

New Member
Input file:\[code\]<root> <sector> <nodeA id="a"> <section id="i"> <item1 id="1" method="create"> <somechild>a</somechild> </item1> <item1 id="1" method="delete" /> </section> </nodeA> <nodeA id="b"> <cell id="ii"> <item2 id="2" method="create"> <otherchild>a</otherchild> </item2> </cell> <cell id="ii"> <item2 id="2" method="delete" /> </cell> </nodeA> <nodeB id="i"> <cell id="ii"> <item3 id="1" method="create"> <child>b</child> </item3> </cell> <cell id="ii"> <item3 id="1" method="delete" /> <item3 id="1" method="create"> <otherchild>a</otherchild> </item3> </cell> </nodeB> </sector> </root>\[/code\]Expected Output:\[code\]<root> <sector> <nodeA id="a"> <section id="i"> </section> </nodeA> <nodeA id="b"> <cell id="ii"> </cell> <cell id="ii"> </cell> </nodeA> <nodeB id="i"> <cell id="ii"> <item3 id="1" method="create"> <!-- this is not eliminated as it violates the rule by having create followed by delete and followed by create again --> <child>b</child> </item3> </cell> <cell id="ii"> <item3 id="1" method="delete" /> <item3 id="1" method="create"> <otherchild>a</otherchild> </item3> </cell> </nodeB> </sector> </root>\[/code\]I need to eliminate node in xml using this rule:
  • one node with \[code\]method="create"\[/code\] followed with one node with \[code\]method="delete"\[/code\] will be eliminated
  • the scenario can happen in one parent or spread in two parent as long as it has the same element name and id \[code\]<cell id="ii">\[/code\]
How can I do this transformation using XSLT 1.0 or 2.0?Thank you.
 
Back
Top