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

problem: select a list with the fewest items.

From: Joris Graaumans <joris@cs.uu.nl>
Date: Thu, 04 Dec 2003 12:04:04 +0100
Message-ID: <3FCF14A4.40100@cs.uu.nl>
To: www-ql@w3c.org

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 05:54:47 UTC

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