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: <5.2.0.9.0.20030314103753.022e7a08@ncmail.datadirect-technologies.com>
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:
><db>
>   <d dno="d1">
>     <b bno="b1"/>
>     <b bno="b2"/>
>   </d>
>   <d dno="d2">
>     <b bno="b2"/>
>   </d>
></db>
>
>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)
return
     <d dno="{$d}">
       {
         for $bno in $b
         where some $a in $in//a
               satisfies (
                     exists($a//b[@bno=$bno])
                 and exists($a//d[@dno=$d]) )
         return <b bno="{$bno}"/>
       }
     </d>

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

Jonathan  
Received on Friday, 14 March 2003 11:01:09 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Saturday, 22 July 2006 00:10:18 GMT