W3C home > Mailing lists > Public > www-ql@w3.org > October to December 2003

Re: problem: select a list with the fewest items.

From: Joris Graaumans <joris@cs.uu.nl>
Date: Thu, 04 Dec 2003 12:46:18 +0100
Message-ID: <3FCF1E8A.7020804@cs.uu.nl>
To: Andrey Fomichev <fomichev_andrei@mail.ru>
Cc: www-ql@w3c.org

Yes, it works perfectly!

Thanks a lot,

Joris Graaumans

Andrey Fomichev wrote:

>I think the following solution should work...
>
>let $n = min(
>            for $a in doc("book.xml")//article
>            return count($a/section)
>            )
>for $b in doc("book.xml")//article
>return 
>  if (count($b/section) = $n)
>  then <result>
>          {$b/title, $n}
>       </result>
>  else ()
>
>  
>
>>-----Original Message-----
>>From: www-ql-request@w3.org [mailto:www-ql-request@w3.org]On 
>>Behalf Of Joris Graaumans
>>Sent: Thursday, December 04, 2003 2:04 PM
>>To: www-ql@w3c.org
>>Subject: problem: select a list with the fewest items.
>>
>>
>>
>>Hi,
>>
>>I have problems with expressing the following problem in XQuery. I want 
>>to make a list the title of the article that has the fewest sections of 
>>the following book.xml document:
>>
>><book>
>><article id="1">
>>   <title>The first article title</title>
>>   <section/>
>>   <section/>
>>   <section/>
>>   <section/>
>>   <section/>
>></article>
>>
>><article id="2">
>>   <title>The second article title</title>
>>   <section/>
>></article>
>>
>><article id="3">
>>   <title>The third article title</title>
>>   <section/>
>>   <section/>
>>   </article>
>>
>><article id="4">
>>   <title>The fourth article title</title>
>>   <section/>
>></article>
>>
>><article id="5">
>>   <title>The fifth article title</title>
>>    <section/>
>>   <section/>
>>   <section/>
>>   <section/>
>>   <section/>
>>  </article>
>></book>
>>
>>So, the result must be:
>>- The second article title, and:
>>- The fourth article title
>>
>>The closest I get is:
>>
>>let $b :=
>>   for $a in doc("book.xml")//article
>>   order by count($a//section)
>>   return $a
>>return
>>   <result>
>>   {$b[position() = 1]//title}
>>   {count($b[position() = 1]//section)}
>>   </result>
>>
>>But this (obviously) returns only one of the titles. I think I have 
>>found a similar problem in the W3C Use Cases (namely, 1.4.4.12 Q12) but 
>>I would prefer not to use user defined functions.
>>
>>Any help is greatly appreciated,
>>
>>Thanks,
>>
>>Joris Graaumans
>>
>>
>>(BTW: apologies for possible multiple posting on this list. I think I 
>>used a wrong alias the first time.)
>>
>>
>>    
>>
Received on Thursday, 4 December 2003 06:37:02 UTC

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