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]> |
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.)