Hi,<br><br><br>My input document looks like that :<br><br>&lt;a&gt;<br>&nbsp;&nbsp;&nbsp; &lt;b n=&quot;1&quot;&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;c&gt;pea&lt;/c&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;d&gt;apple&lt;/d&gt;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;b n=&quot;2&quot;&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;c&gt;kiwi&lt;/c&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;d&gt;banana&lt;/d&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/b&gt;<br>&nbsp;&nbsp;&nbsp; &lt;/b&gt;<br>&nbsp;&nbsp;&nbsp; &lt;b n=&quot;3&quot;&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;c&gt;kiwi&lt;/c&gt;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;d&gt;banana&lt;/d&gt;<br>&nbsp;&nbsp;&nbsp; &lt;/b&gt;<br>&lt;/a&gt;<br><br>The structure is recursive : b can contain b.<br><br>I
want to write a query to retrieve any b that contains &quot;kiwi&quot; and
&quot;banana&quot;, but I want to exclude the first b (with n=&quot;1&quot;) because the
keywords are not in its own content (c+d), but in its b child's
content.
<br>The query should return b2 and b3.<br><br>This query can't go :<br><br>for $x in //b<br>where $x[contains(., &quot;kiwi&quot;) and contains(., &quot;banana&quot;)]<br>and not($x/c[contains(., &quot;kiwi&quot;) and contains(., &quot;banana&quot;)])
<br>return &nbsp;&nbsp;&nbsp; $x<br><br>because, sometimes my put could be :<br><br>&lt;a&gt;<br>&nbsp;&nbsp;&nbsp; &lt;b n=&quot;1&quot;&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;c&gt;pea&lt;/c&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;d&gt;apple&lt;/d&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;b n=&quot;2&quot;&gt;<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;c&gt;kiwi&lt;/c&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;d&gt;banana&lt;/d&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/b&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-weight: bold;">&lt;e&gt;kiwi banana&lt;/e&gt;</span><br>&nbsp;&nbsp;&nbsp; &lt;/b&gt;<br>&nbsp;&nbsp;&nbsp; &lt;b n=&quot;3&quot;&gt;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;c&gt;kiwi&lt;/c&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;d&gt;banana&lt;/d&gt;<br>&nbsp;&nbsp;&nbsp; &lt;/b&gt;<br>&lt;/a&gt;<br><br>In that case, the query should return all three b.<br><br>Thanks for your help,<br><br>Billig