Find all items with the specified nested child

Hey, I parsed the html doc. you need to find the whole element that has the specified child (may not be a direct descendant).

for ex:

<center> <table> ... <a /> </center> 

find all "center" tags that have a nested link thanks!

+4
source share
3 answers

Using

 //center[.//a] 

This selects all center elements in the document that has a child.

And this:

 //center[.//*/a] 

selects all center elements in the document that have a child, which is not a child of this center .

+3
source

How about the following:

 //center[element()//a] 

This means finding all the "central" elements containing any elements "a" that are descendants of "children with a direct direct element."

+1
source

You cannot use the descendant axis in a predicate?

 //center[descendant::a] 
0
source

All Articles