[xquery-talk] query on recursive xml structure

yix yix billigo at gmail.com
Tue Aug 29 11:18:18 PDT 2006


Hi,


My input document looks like that :

<a>
    <b n="1">
        <c>pea</c>
        <d>apple</d>
        <b n="2">
            <c>kiwi</c>
            <d>banana</d>
        </b>
    </b>
    <b n="3">
        <c>kiwi</c>
        <d>banana</d>
    </b>
</a>

The structure is recursive : b can contain b.

I want to write a query to retrieve any b that contains "kiwi" and "banana",
but I want to exclude the first b (with n="1") because the keywords are not
in its own content (c+d), but in its b child's content.
The query should return b2 and b3.

This query can't go :

for $x in //b
where $x[contains(., "kiwi") and contains(., "banana")]
and not($x/c[contains(., "kiwi") and contains(., "banana")])
return     $x

because, sometimes my put could be :

<a>
    <b n="1">
        <c>pea</c>
        <d>apple</d>
        <b n="2">
            <c>kiwi</c>
            <d>banana</d>
        </b>
        <e>kiwi banana</e>
    </b>
    <b n="3">
        <c>kiwi</c>
        <d>banana</d>
    </b>
</a>

In that case, the query should return all three b.

Thanks for your help,

Billig
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://x-query.com/pipermail/talk/attachments/20060829/4061af89/attachment.htm


More information about the talk mailing list