Project

Profile

Help

How to connect?
Download (1.22 KB) Statistics
| Branch: | Revision:

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

1
import schema namespace ipo="http://www.example.com/IPO" at "ipo.xsd";
2
import schema namespace rpt="http://www.example.com/Report" at "report.xsd";
3

    
4
let $orders := doc('ipo.xml')/schema-element(ipo:purchaseOrder)
5
                 [@orderDate ge xs:date("1999-09-01")
6
                  and @orderDate le xs:date("1999-12-31")] 
7
let $items := $orders/items/item
8
let $zips := distinct-values($orders/billTo/zip)
9
let $parts := distinct-values($items/@partNum)
10
return validate {
11
 <rpt:purchaseReport>
12
  <rpt:regions>
13
    {
14
     for $zip in $zips
15
     order by $zip
16
     return
17
      <rpt:zip code="{$zip}">
18
       {
19
        for $part in $parts
20
        let $hits := $orders[ billTo/zip = $zip and items/item/@partNum = $part]
21
        let $quantity := sum($hits//item[@partNum=$part]/quantity)
22
        (:where count($hits) > 0:)
23
        order by $part
24
        return
25
         <rpt:part number="{$part}" quantity="{$quantity}"/>
26
       }
27
      </rpt:zip>
28
    }
29
  </rpt:regions>
30
  <rpt:parts>
31
   {
32
     for $part in $parts
33
     return
34
      <rpt:part number="{$part}">
35
       {
36
         string($items[@partNum = $part]/productName)
37
       }
38
      </rpt:part>   
39
   }
40
  </rpt:parts>
41
</rpt:purchaseReport> }
42
           
(13-13/27)