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

Joris Graaumans <[email protected]>
Newsgroups gmane.comp.web.query-languages
Organization Utrecht University
Message-ID <[email protected]>
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: [email protected] [mailto:[email protected]]On 
>>Behalf Of Joris Graaumans
>>Sent: Thursday, December 04, 2003 2:04 PM
>>To: [email protected]
>>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.)
>>
>>
>>    
>>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.