-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueries.xq
58 lines (58 loc) · 2.87 KB
/
queries.xq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<r> (: number of items listed on all continents :)
<l>
{
for $x in doc("auction.xml")/site/regions/*
return <count>
{count($x/item)}</count>
}
</l> (: names of items registered in Europe along with their descriptions :)
<m>
{
for $x in doc("auction.xml")/site/regions/europe//item
return <item>
<name>{$x/name/text()}</name>
<description>{$x/description}</description>
</item>
}
</m> (: names of persons and the number of items they bought :)
<n>
{
for $x in distinct-values(doc("auction.xml")/site/closed_auctions/closed_auction/buyer/@person)
return ($x, count(index-of(doc("auction.xml")/site/closed_auctions/closed_auction/buyer/@person, $x)), '
')
}
</n> (: all persons according to their interest, ie, for each interest category, display the persons :)
<p>
{
for $x in doc("auction.xml")/site/people//person
where exists($x/profile/interest/@category) = true
return <person>
<name>{$x/name/text()}</name>
<category>{$x/profile/interest}</category>
</person>
}
</p> (: Group persons by their categories of interest and output the size of each group :)
<q>
{
for $x in doc("auction.xml")/site/people/person
group by $x/profile/interest[1]/@category
where exists($x/profile/interest/@category) = true
return <person>
<count>{count($x/name)}</count>
</person>
}
</q> (: names of persons and the names of the items they bought in Europe :)
<d>
{
for $x in doc("auction.xml")/site/regions/europe/item
for $y in doc("auction.xml")/site/closed_auctions/closed_auction
for $z in doc("auction.xml")/site/people/person
where ($x/@id = $y/itemref/@item) and ($y/buyer/@person = $z/@id)
return <item>
<itemname>
{$x/name/text()}</itemname><personname>
{$z/name/text()}</personname></item>
}
</d> (: alphabetically ordered list of all items along with their location :)
<g>
{
for $x in doc("auction.xml")/site/regions//item
order by $x/name
return <item>
<name>{$x/name/text()}</name>
<location>{$x/location/text()}</location>
</item>
}
</g> (: reserve prices of those open auctions where a certain person with id person3 issued a bid before another person with id person6. Here before means "listed before in the XML document", that is, before in document order. :)
<j>
{
for $x in doc("auction.xml")/site/open_auctions/open_auction
where $x/bidder/personref/@person = 'person3'
return <reserve>
{$x/reserve/text()}</reserve>
}
</j>
</r>