Project

Profile

Help

How to connect?
Download (858 Bytes) Statistics
| Branch: | Revision:

he / src / use-cases / r / q12.xq @ a31dd97a

1
declare namespace my="my.uri";
2

    
3
declare function my:bid_summary()
4
  as element()*
5
{
6
    for $i in distinct-values(doc("bids.xml")//itemno)
7
    let $b := doc("bids.xml")//bid_tuple[itemno = $i]
8
    return
9
        <bid_count>
10
            <itemno>{ $i }</itemno>
11
            <nbids>{ count($b) }</nbids>
12
        </bid_count>
13
};
14

    
15
<result>
16
 {
17
    let $bid_counts := my:bid_summary(),
18
        $maxbids := max(for $z in $bid_counts/nbids return number($z)),
19
        $maxitemnos := $bid_counts[nbids = $maxbids]
20
    for $item in doc("items.xml")//item_tuple,
21
        $bc in $bid_counts
22
    where $bc/nbids =  $maxbids and $item/itemno = $bc/itemno
23
    return
24
        <popular_item>
25
            { $item/itemno }
26
            { $item/description }
27
            <bid_count>{ $bc/nbids/text() }</bid_count>
28
        </popular_item>
29
 }
30
</result>
(11-11/42)