module namespace xmark = "xmark-queries.xq";
declare function xmark:convert($v as xs:decimal?) as xs:decimal?
{
2.20371 * $v (: convert Dfl to Euro :)
};
declare function xmark:q01($doc as xs:string, $id as xs:string)
{
let $auction := doc($doc)
for $b in $auction/site/people/person[@id = $id]
return $b/name/text()
};
declare function xmark:q02($doc as xs:string)
{
let $auction := doc($doc)
for $b in $auction/site/open_auctions/open_auction
return { $b/bidder[1]/increase/text() }
};
declare function xmark:q03($doc as xs:string)
{
let $auction := doc($doc)
for $b in $auction/site/open_auctions/open_auction
where $b/bidder[1]/increase/text() * 2 <= $b/bidder[last()]/increase/text()
return
};
declare function xmark:q04($doc as xs:string, $person1 as xs:string, $person2 as xs:string)
{
let $auction := doc($doc)
for $b in $auction/site/open_auctions/open_auction
where some $pr1 in $b/bidder/personref[@person=$person1],
$pr2 in $b/bidder/personref[@person=$person2]
satisfies $pr1 << $pr2
return { $b/reserve/text() }
};
declare function xmark:q05($doc as xs:string, $min as xs:double) as xs:integer
{
let $auction := doc($doc)
return
count(for $i in $auction/site/closed_auctions/closed_auction
where $i/price/text() >= $min
return $i/price)
};
declare function xmark:q06($doc as xs:string) as xs:integer*
{
let $auction := doc($doc)
for $b in $auction//site/regions
return count($b//item)
};
declare function xmark:q07($doc as xs:string) as xs:integer*
{
let $auction := doc($doc)
for $p in $auction/site
return count($p//description) + count($p//annotation) + count($p//emailaddress)
};
declare function xmark:q08($doc as xs:string)
{
let $auction := doc($doc)
for $p in $auction/site/people/person
let $a := for $t in $auction/site/closed_auctions/closed_auction
where $t/buyer/@person = $p/@id
return $t
return - { count($a) }
};
declare function xmark:q09($doc as xs:string)
{
let $auction := doc($doc)
let $ca := $auction/site/closed_auctions/closed_auction
let $ei := $auction/site/regions/europe/item
for $p in $auction/site/people/person
let $a :=
for $t in $ca
where $p/@id = $t/buyer/@person
return
let $n :=
for $t2 in $ei
where $t/itemref/@item = $t2/@id
return $t2
return - {$n/name/text()}
return {$a}
};
declare function xmark:q10($doc as xs:string)
{
let $auction := doc($doc)
for $i in distinct-values($auction/site/people/person/profile/interest/@category)
let $p :=
for $t in $auction/site/people/person
where $t/profile/interest/@category = $i
return
{ $t/profile/gender/text() }
{ $t/profile/age/text() }
{ $t/profile/education/text() }
{ fn:data($t/profile/@income) }
{ $t/name/text() }
{ $t/address/street/text() }
{ $t/address/city/text() }
{ $t/address/country/text() }
{ $t/emailaddress/text() }
{ $t/homepage/text() }
{ $t/creditcard/text() }
return
{ $i }
{ $p }
};
declare function xmark:q11($doc as xs:string, $factor as xs:integer)
{
let $auction := doc($doc)
for $p in $auction/site/people/person
let $l := for $i in $auction/site/open_auctions/open_auction/initial
where $p/profile/@income > ($factor * exactly-one($i/text()))
return $i
return { count($l) }
};
declare function xmark:q12($doc as xs:string, $factor as xs:integer, $min as xs:double)
{
let $auction := doc($doc)
for $p in $auction/site/people/person
let $l := for $i in $auction/site/open_auctions/open_auction/initial
where $p/profile/@income > ($factor * exactly-one($i/text()))
return $i
where $p/profile/@income > $min
return { count($l) }
};
declare function xmark:q13($doc as xs:string)
{
let $auction := doc($doc)
for $i in $auction/site/regions/australia/item
return - { $i/description }
};
declare function xmark:q14($doc as xs:string, $kind as xs:string)
{
let $auction := doc($doc)
for $i in $auction/site//item
where contains(string(exactly-one($i/description)),$kind)
return $i/name/text()
};
declare function xmark:q15($doc as xs:string)
{
let $auction := doc($doc)
for $a in $auction/site/closed_auctions/closed_auction/annotation/description/parlist/listitem/parlist/listitem/text/emph/keyword/text()
return { $a }
};
declare function xmark:q16($doc as xs:string)
{
let $auction := doc($doc)
for $a in $auction/site/closed_auctions/closed_auction
where not(empty($a/annotation/description/parlist/listitem/parlist/listitem/text/emph/keyword/text()))
return
};
declare function xmark:q17($doc as xs:string)
{
let $auction := doc($doc)
for $p in $auction/site/people/person
where empty($p/homepage/text())
return
};
declare function xmark:q18($doc as xs:string) as xs:decimal*
{
let $auction := doc($doc)
for $i in $auction/site/open_auctions/open_auction
return xmark:convert(fn:zero-or-one($i/reserve))
};
declare function xmark:q19($doc as xs:string)
{
let $auction := doc($doc)
for $b in $auction/site/regions//item
let $k := $b/name/text()
order by zero-or-one($b/location)
return - { $b/location/text() }
};
declare function xmark:q20($doc as xs:string, $lo as xs:double, $hi as xs:double)
{
let $auction := doc($doc)
return
{ count($auction/site/people/person/profile[@income >= $hi]) }
{ count($auction/site/people/person/profile[@income < $hi and @income >= $lo]) }
{ count($auction/site/people/person/profile[@income < $lo]) }
{ count(for $p in $auction/site/people/person
where empty($p/profile/@income)
return $p) }
};