W3C home > Mailing lists > Public > www-ql@w3.org > January to March 2003

Re: can I write such a XQuery?

From: Jonathan Robie <jonathan.robie@datadirect-technologies.com>
Date: Fri, 14 Mar 2003 11:00:41 -0500
Message-Id: <>
To: "Chen Yabing" <iscp0054@nus.edu.sg>, <www-ql@w3.org>

At 04:36 PM 3/14/2003 +0800, Chen Yabing wrote:

>I want to have such a result by executing an XQuery:
>   <d dno="d1">
>     <b bno="b1"/>
>     <b bno="b2"/>
>   </d>
>   <d dno="d2">
>     <b bno="b2"/>
>   </d>
>the result means that for each distinct d, we need all b with distinct bno
>that appear under their (d & b) common ancestor a.
>for example, for d1, a's ano can be "a1" & "a2", then all b with distinct
>bno under "a1" and "a2" are "b1" and "b2"
>for d2, only "b2".

If I have understood your text correctly, here is one solution:

let $b := distinct-values($in//b/@bno)
     <d dno="{$d}">
         for $bno in $b
         where some $a in $in//a
               satisfies (
                 and exists($a//d[@dno=$d]) )
         return <b bno="{$bno}"/>

I imagine more elegant solutions could be written. I haven't given this a 
lot of time.

Received on Friday, 14 March 2003 11:01:09 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 20:17:16 UTC