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


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:

<article id="1">
   <title>The first article title</title>

<article id="2">
   <title>The second article title</title>

<article id="3">
   <title>The third article title</title>

<article id="4">
   <title>The fourth article title</title>

<article id="5">
   <title>The fifth article title</title>

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
   {$b[position() = 1]//title}
   {count($b[position() = 1]//section)}

But this (obviously) returns only one of the titles. I think I have 
found a similar problem in the W3C Use Cases (namely, Q12) but 
I would prefer not to use user defined functions.

Any help is greatly appreciated,


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.4.0 : Friday, 17 January 2020 22:43:43 UTC