How to eliminate this node in XML using XSLT based on these three rules?

hmam1

New Member
I need to eliminate xml node based on these three rules.First scenario:\[code\]<root> <sector> <nodeA id="a"> <section id="i"> <!-- this is an example where it occurs in one parent --> <item1 id="1" method="create"> <somechild>a</somechild> </item1> <item1 id="1" method="delete" /> </section> </nodeA> <nodeA id="b"> <cell id="ii"> <item1 id="2" method="create"> <somechild>a</somechild> </item1> </cell> <cell id="ii"> <item1 id="2" method="delete" /> </cell> </nodeA> </sector> </root>\[/code\]Output:\[code\]<root> <sector> <nodeA id="a"> <section id="i"> </section> </nodeA> <nodeA id="b"> <cell id="ii"> > </cell> <cell id="ii"> </cell> </nodeA> </sector> </root>\[/code\]Second scenario:\[code\]<root> <sector> <nodeA id="a"> <section id="ii"> <!-- this is an example where it occurs in different parent that has the same id --> <item1 id="0" method="delete"/> </section> <section id="ii"> <item1 id="0" method="create"> <somechild>a</somechild> </item1> </section> </nodeA> </sector> </root>\[/code\]Output:\[code\]<root> <sector> <nodeA id="a"> <section id="ii"> </section> <section id="ii"> </section> </nodeA> </sector> </root>\[/code\]Third Scenario:\[code\]<root> <sector> <nodeB id="a"> <section id="i"> <item1 id="0" method="create"> <!-- this is an example where it occurs in different parent that has the same id --> <somechild>a</somechild> </item1> <item1 id="0" method="modify"> <otherchild>a</otherchild> </item1> </section> <section id="i"> <item1 id="0" method="delete"/> </section> </nodeB> </sector> </root>\[/code\]Output:\[code\]<root> <sector> <nodeB id="a"> <section id="i"> </section> <section id="i"> </section> </nodeB> </sector> </root>\[/code\]In conclusion we need to eliminate node according to these rules:
  • one node with method create followed with one delete will be eliminated
  • one node with method delete followed with one create will be eliminated
  • one node with method create followed with one modify, followed with one delete will be eliminated
The elimination can occur inside one parent (scenario1: section id=i) or spread in different parent (scenario2 and 3) as long as it has the same id.Can anyone solve this complex transformation? It can use xslt 2.0 or 1.0. Please let me know if I need to provide more extensive example.Thank you.John
 
Back
Top