Hi I need an efficient xpath 2.0 expressions to apply it to the following input xml <tag1> <tag2> ......... many elements here </tag2> <tag3> <tag4> a number here</tag4> ......... many elements here </tag3> <tag3> <tag4> > a number here </tag4> ......... many elements here </tag3> ..... many tag3 elements here </tag1> I need to get all the data in that xml except for the tag3 elements I need to choose just one whose <tag4> value is equal to a certain value Thanks Mahmoud
khalil_mi@hotmail.com wrote: > Hi > > I need an efficient xpath 2.0 expressions to apply it to the following > input xml > > <tag1> > <tag2> > ......... many elements here > </tag2> > <tag3> > <tag4> a number here</tag4> > ......... many elements here > </tag3> > <tag3> > <tag4> > a number here </tag4> > ......... many elements here > </tag3> > ..... many tag3 elements here > </tag1> > > I need to get all the data in that xml except for the tag3 elements I > need to choose just one whose <tag4> value is equal to a certain value > > Thanks > > Mahmoud It's not clear what do you mean. Provide desired result please. -- Oleg
On Feb 7, 12:28 pm, Oleg Tkachenko wrote: > khalil...@hotmail.com wrote: > > Hi > > > I need an efficient xpath 2.0 expressions to apply it to the following > > input xml > > > <tag1> > > <tag2> > > ......... many elements here > > </tag2> > > <tag3> > > <tag4> a number here</tag4> > > ......... many elements here > > </tag3> > > <tag3> > > <tag4> > a number here </tag4> > > ......... many elements here > > </tag3> > > ..... many tag3 elements here > > </tag1> > > > I need to get all the data in that xml except for the tag3 elements I > > need to choose just one whose <tag4> value is equal to a certain value > > > Thanks > > > Mahmoud > > It's not clear what do you mean. Provide desired result please. > > -- > Oleg- Hide quoted text - > > - Show quoted text - If the input xml is: <tag1> <tag2> ......... many elements here </tag2> <tag3> <tag4> 5</tag4> ......... many elements here </tag3> <tag3> <tag4> > 7 </tag4> ......... many elements here </tag3> ..... many tag3 elements here </tag1> And I want to choose the tage3 whose tag4 is 7 then the desired output is: <tag1> <tag2> ......... many elements here </tag2> <tag3> <tag4> > 7 </tag4> ......... many elements here </tag3> </tag1> thanks Mahmoud
khalil_mi@hotmail.com wrote: > If the input xml is: > <tag1> > <tag2> > ......... many elements here > </tag2> > <tag3> > <tag4> 5</tag4> > ......... many elements here > </tag3> > <tag3> > <tag4> > 7 </tag4> > ......... many elements here > </tag3> > > ..... many tag3 elements here > > </tag1> > > And I want to choose the tage3 whose tag4 is 7 then the desired > output is: > > <tag1> > <tag2> > ......... many elements here > </tag2> > <tag3> > <tag4> > 7 </tag4> > ......... many elements here > </tag3> > </tag1> XPath selects nodes in an existing documents, it does not change the document. Therefore if you select the root element 'tag1' in your example then it has all its children, you can't remove some of the children with XPath alone, you need XSLT for that. -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/
Martin Honnen wrote: > XPath selects nodes in an existing documents, it does not change the > document. Therefore if you select the root element 'tag1' in your > example then it has all its children, you can't remove some of the > children with XPath alone, you need XSLT for that. However if you wanted to select only certain child elements of the root element tag1 then you can do that as follows: /tag1/*[not(self::tag3[not(tag4 = '7')])] That selects all those child elements that are not 'tag3' elements not having a 'tag4' child element with contents '7'. -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/
On Feb 7, 12:52 pm, Martin Honnen wrote: > Martin Honnen wrote: > > XPath selects nodes in an existing documents, it does not change the > > document. Therefore if you select the root element 'tag1' in your > > example then it has all its children, you can't remove some of the > > children with XPath alone, you need XSLT for that. > > However if you wanted to select only certain child elements of the root > element tag1 then you can do that as follows: > /tag1/*[not(self::tag3[not(tag4 = '7')])] > That selects all those child elements that are not 'tag3' elements not > having a 'tag4' child element with contents '7'. > > -- > > Martin Honnen --- MVP XML > http://JavaScript.FAQTs.com/ That was a very helpful snippet Martin thanks for that.