tags:

views:

72

answers:

2

How do I select any node a that has node b anywhere inside it?

Given the following three XML documents:

<a>
    <b></b>
</a>

or

 <a>
    <c>
     <b></b>
    </c>
</a>

or

   <a/>

I want the a element in the first two documents to be selected.

Apparently, a[//b] is not a solution.

+1  A: 

You should try:

//a[.//b]

Jeff Yates
+2  A: 
a[descendant::b]

is more accurate and efficient than

a[.//b]

which is equal to

a[self::node()/descendant-or-self::node()/child::b]
Azat Razetdinov