{
for $b in document("http://www.bn.com")/bib/book
where $b/publisher = "Addison-Wesley" and $b/@year > 1991
return
{ $b/title }
}
;
{
for $b in document("http://www.bn.com")/bib/book,
$t in $b/title,
$a in $b/author
return
{ $t }
{ $a }
}
;
{
for $b in document("http://www.bn.com")/bib/book
return
{ $b/title }
{
for $a in $b/author
return $a
}
}
;
{
for $a in distinct-values(document("http://www.bn.com")//author)
return
{ $a }
{
for $b in document("http://www.bn.com")/bib/book
where value-equals($b/author,$a)
return $b/title
}
}
;
{
for $b in document("www.bn.com/bib.xml")//book,
$a in document("www.amazon.com/reviews.xml")//entry
where $b/title = $a/title
return
{ $b/title }
{ $a/price/text() }
{ $b/price/text() }
}
;
{
for $b in document("www.bn.com/bib.xml")//book
where count($b/author) > 0
return
{ $b/title }
{
for $a in $b/author[position()<=2]
return $a
}
{
if (count($b/author) > 2)
then
else ()
}
}
;
{
for $b in document("www.bn.com/bib.xml")//book
where $b/publisher = "Addison-Wesley" and $b/@year > "1991"
return
{ $b/@year }
{ $b/title }
sortby (title)
}
;
for $b in document("www.bn.com/bib.xml")//book,
$e in $b/*[contains(string(.), "Suciu")]
where ends_with(name($e), "or")
return
{ $b/title }
{ $e }
;
{
for $t in document("books.xml")//chapter/title
union document("books.xml")//section/title
where contains($t/text(), "XML")
return $t
}
;
{
let $doc := document("prices.xml")
for $t in distinct-values($doc/book/title)
let $p := $doc/book[title = $t]/price
return
{
min($p)
}
}
;
{
for $b in document("www.bn.com/bib.xml")//book[author]
return
{ $b/title }
{ $b/author }
}
{
for $b in document("www.bn.com/bib.xml")//book[editor]
return
{ $b/title }
{ $b/editor/affiliation/text() }
}
;
{
for $book1 in document("www.bn.com/bib.xml")//book,
$book2 in document("www.bn.com/bib.xml")//book
let $aut1 := $book1/author sortby(last, first),
$aut2 := $book2/author sortby(last, first)
where $book1/title/text() > $book2/title/text()
and sequence-value-equal($aut1, $aut2)
return
{ $book1/title }
{ $book2/title }
}
;
{
let $b := document("book1.xml")
return
filter($b//section | $b//section/title | $b//section/title/text())
}
;
{
for $f in document("book1.xml")//figure
return
{ $f/@* }
{ $f/title }
}
;
{ count(document("book1.xml")//section) },
{ count(document("book1.xml")//figure) }
;
{
count(document("book1.xml")/book/section)
}
;
{
for $s in document("book1.xml")//section
let $f := $s/figure
return
}
;
define function section_summary(element $s) returns element
{
{ $s/@* }
{ $s/title }
{ count($s/figure) }
{
for $ss in $s/section
return section_summary($ss)
}
}
{
for $s in document("book1.xmll")//section
return section_summary($s)
}
;
for $s in document("report1.xml")//section[section.title = "Procedure"]
return ($s//incision)[2]/instrument
;
for $s in document("report1.xml")//section[section.title = "Procedure"]
return ($s//instrument)[position()<=2]
;
let $i2 := (document("report1.xml")//incision)[2]
for $a in (document("report1.xml")//action)[. follows $i2][position()<=2]
return $a//instrument
;
for $p in //procedure
where some $i in $proc//incision satisfies
empty($proc//anesthesia[. precedes $i])
return $p
;
{
let $proc := //procedure[1]
for $n in $proc//node()
where $n follows ($proc//incision)[1]
and $n precedes ($proc//incision)[2]
return $n
}
;
{
for $i in document("items.xml")//item_tuple
where $i/start_date <= date()
and $i/end_date >= date()
and contains($i/description, "Bicycle")
return
{ $i/itemno }
{ $i/description }
sortby (itemno)
}
;
{
for $i in document("items.xml")//item_tuple
let $b := document("bids.xml")//bid_tuple[itemno = $i/itemno]
where contains($i/description, "Bicycle")
return
{ $i/itemno }
{ $i/description }
{ max($b/bid) }
sortby(itemno)
}
;
{
for $u in document("users.xml")//user_tuple
for $i in document("items.xml")//item_tuple
where $u/rating > "C"
and $i/reserve_price > 1000
and $i/offered_by = $u/userid
return
{ $u/name }
{ $u/rating }
{ $i/description }
{ $i/reserve_price }
}
;
{
for $i in document("items.xml")//item_tuple
where not(some $b in document("bids.xml")//bid_tuple
satisfies $b/itemno = $i/itemno)
return
{ $i/itemno }
{ $i/description }
}
;
{
for $seller in document("users.xml")//user_tuple,
$buyer in document("users.xml")//user_tuple,
$item in document("items.xml")//item_tuple,
$highbid in document("bids.xml")//bid_tuple
where $seller/name = "Tom Jones"
and $seller/userid = $item/offered_by
and contains($item/description, "Bicycle")
and $item/itemno = $highbid/itemno
and $highbid/userid = $buyer/userid
and $highbid/bid = max(document("bids.xml")//bid_tuple
[itemno = $item/itemno]/bid)
return
{ $item/itemno }
{ $item/description }
{ $highbid/bid }
{ $buyer/name }
sortby(itemno)
}
;
{
for $seller in unordered(document("users.xml")//user_tuple),
$buyer in unordered(document("users.xml")//user_tuple),
$item in unordered(document("items.xml")//item_tuple),
$highbid in unordered(document("bids.xml")//bid_tuple)
where $seller/name = "Tom Jones"
and $seller/userid = $item/offered_by
and contains($item/description, "Bicycle")
and $item/itemno = $highbid/itemno
and $highbid/userid = $buyer/userid
and $highbid/bid = max(document("bids.xml")//bid_tuple
[itemno = $item/itemno]/bid)
return
{ $item/itemno }
{ $item/description }
{ $highbid/bid }
{ $buyer/name }
sortby (itemno)
}
;
{
for $item in document("items.xml")//item_tuple
let $b := document("bids.xml")//bid_tuple[itemno = $item/itemno]
where $item/reserve_price * 2 < max($b/bid)
return
{ $item/itemno }
{ $item/description }
{ $item/reserve_price }
{ max($b/bid) }
}
;
let $allbikes := document("items.xml")//item_tuple
[contains(description, "Bicycle")
or contains(description, "Tricycle")]
let $bikebids := document("bids.xml")//bid_tuple[itemno = $allbikes/itemno]
return
{
max($bikebids/bid)
}
;
let $item := document("items.xml")//item_tuple
[end_date >= date("1999-03-01") and end_date <= date("1999-03-31")]
return
{
count($item)
}
;
{
let $end_dates := document("items.xml")//item_tuple/end_date
for $m in distinct-values(month($end_dates))
let $item := document("items.xml")
//item_tuple[year(end_date) = 1999 and month(end_date) = $m]
return
{ $m }
{ count($item) }
sortby(month)
}
;
{
for $highbid in document("bids.xml")//bid_tuple,
$user in document("users.xml")//user_tuple
where $user/userid = $highbid/userid
and $highbid/bid = max(document("bids.xml")//bid_tuple
[itemno = $highbid/itemno]/bid)
return
{ $highbid/itemno }
{ $highbid/bid }
{ $user/name/text() }
sortby(itemno)
}
;
let $highbid := max(document("bids.xml")//bid_tuple/bid)
return
{
for $item in document("items.xml")//item_tuple,
$b in document("bids.xml")//bid_tuple[itemno = $item/itemno]
where $b/bid = $highbid
return
{ $item/itemno }
{ $item/description }
{ $highbid }
}
;
define function bid_summary ()
{
for $i in distinct-values(document("bids.xml")//itemno)
let $b := document("bids.xml")//bid_tuple[itemno = $i]
return
{ $i }
{ count($b) }
}
{
let $bid_counts := bid_summary(),
$maxbids := max($bid_counts/nbids),
$maxitemnos := $bid_counts[nbids=$max_bids]
for $item in document("items.xml")//item_tuple,
$bc in $bid_counts
where $bc/nbids = $maxbids and $item/itemno = $bc/itemno
return
{ $item/itemno }
{ $item/description }
{ $bc/nbids/text() }
}
;
{
for $uid in distinct-values(document("bids.xml")//userid),
$u in document("users.xml")//user_tuple[userid = $uid]
let $b := document("bids.xml")//bid_tuple[userid = $uid]
return
{ $u/userid }
{ $u/name }
{ count($b) }
{ avg($b/bid) }
sortby(userid)
}
;
{
for $i in distinct-values(document("bids.xml")//itemno)
let $b := document("bids.xml")//bid_tuple[itemno = $i]
where count($b) >= 3
return
{ $i }
{ avg($b/bid) }
sortby(avgbid descending)
}
;
{
for $u in document("users.xml")//user_tuple
let $b := document("bids.xml")//bid_tuple[userid = $u/userid and bid >= 100]
where count($b) > 1
return
{ $u/name/text() }
}
;
{
for $u in document("users.xml")//user_tuple
let $b := document("bids.xml")//bid_tuple[userid = $u/userid]
return
{ $u/userid }
{ $u/name }
{
if (empty($b))
then inactive
else active
}
sortby(userid)
}
;
{
for $u in document("users.xml")//user_tuple
where
every $item in document("items.xml")//item_tuple satisfies
some $b in document("bids.xml")//bid_tuple satisfies
($item/itemno = $b/itemno and $u/userid = $b/userid)
return
$u/name
}
;
{
for $u in document("users.xml")//user_tuple
return
{ $u/name }
{
for $b in distinct-values(document("bids.xml")//bid_tuple
[userid = $u/userid]/itemno),
$i in document("items.xml")//item_tuple[itemno = $b]
return
{ $i/description/text() }
sortby(.)
}
sortby(name)
}
;
{
//report//para
}
;
{
//intro/para
}
;
{
for $c in //chapter
where empty($c/intro)
return $c/section/intro/para
}
;
{
(((//chapter)[2]//section)[3]//para)[2]
}
;
{
//para[@security = "c"]
}
;
{
for $s in //section/@shorttitle
return { $s }
}
;
{
for $i in //intro/para[1]
return
{ substring(string($i), 1, 1) }
}
;
{
//section[contains(string(.//title), "is SGML")]
}
;
{
//section[contains(.//title/text(), "is SGML")]
}
;
{
for $id in document("input.xml")//xref/@xrefid
return //topic[@topicid = $id]
}
;
{
let $x := //xref[@xrefid = "top4"],
$t := //title[. precedes $x]
return $t[last()]
}
;
//news_item/title[contains(./text(), "Foobar Corporation")]
;
let $foobar_partners := //company[name = "Foobar Corporation"]//partner
for $item in //news_item
where
some $t in $item//title satisfies
(contains($t/text(), "Foobar Corporation")
and some $partner in $foobar_partners satisfies
contains($t/text(), $partner/text()))
or some $par in $item//par satisfies
(contains($par/text(), "Foobar Corporation")
and some $partner in $foobar_partners satisfies
contains($par/text(), $partner/text()))
return
{ $item/title }
{ $item/date }
;
let $foobar_partners := //company[name = "Foobar Corporation"]//partner,
$foobar_competitors := //company[name = "Foobar Corporation"]//competitor
for $item in //news_item
where some $partner in $foobar_partners satisfies
contains_in_same_sentence(string($item/content), "Foobar Corporation", $partner/text())
and not(some $competitor in $foobar_competitors satisfies
contains(string($item/content), $competitor/text()))
return
$item/title
;
for $item in //news_item,
$c in //company
let $partners := $c//partner
where contains(string($item), $c/name/text())
and some $p in $partners satisfies
contains(string($item), $p/text()) and $item/news_agent != $c/name
return
$item
;
for $item in //news_item
where contains(string($item/content), "Gorilla Corporation")
return
{ $item/title/text() }.
{ $item/date/text() }.
{ string(($item//par)[1]) }
;
let $companies := distinct-values(//company/name/text()
union //company//partner/text()
union //company//competitor/text())
for $item in //news_item,
$item_title in $item/title,
$item_para in $item//par,
$c1 in $companies,
$c2 in $companies
where $c1 != $c2
and contains_stems_in_same_sentence($item_title/text(), $c1, $c2, "acquire")
or contains_stems_in_same_sentence($item_para/text(), $c1, $c2, "acquire")
return
distinct-values($item)
;
{
for $n in distinct-values(get-namespace-uri(//*))
return
{$n}
}
;
namespace music = "http://www.example.org/music/records"
{
//music:title
}
;
namespace dt = "http://www.w3.org/2001/XMLSchema"
{
//*[@dt:*]
}
;
namespace xlink = "http://www.w3.org/1999/xlink"
{
for $hr in //@xlink:href
return { $hr }
}
;
namespace music = "http://www.example.org/music/records"
{
//music:record[music:remark/@xml:lang = "de"]
}
;
namespace ma = "http://www.example.com/AuctionWatch"
namespace anyzone = "http://www.example.com/auctioneers#anyzone"
{
//ma:Auction[@anyzone:ID]/ma:Schedule/ma:Close
}
;
namespace ma = "http://www.example.com/AuctionWatch"
{
for $a in //ma:Auction
let $seller_id := $a/ma:Trading_Partners/ma:Seller/*:ID,
$buyer_id := $a/ma:Trading_Partners/ma:High_Bidder/*:ID
where namespace_uri($seller_id) = namespace_uri($buyer_id)
return
$a/ma:AuctionHomepage
}
;
namespace ma = "http://www.example.com/AuctionWatch"
{
(for $s in //ma:Trading_Partners/ma:Seller
where $s/*:NegativeComments = 0
return $s)
union
(for $b in //ma:Trading_Partners/ma:High_Bidder
where $b/*:NegativeComments = 0
return $b)
}
;
define function one_level (element $p) returns element
{
{
for $s in document("data/parts-data.xml")//part
where $s/@partof = $p/@partid
return one_level($s)
}
}
{
for $p in document("data/parts-data.xml")//part[empty(@partof)]
return one_level($p)
}
;
{
for $m in document("census.xml")//person[name = "Martha"]
return shallow($m/@spouse->person)
}
;
define function children(element $p)
{
shallow($p/person) union shallow($p/@spouse->person/person)
}
{
for $j in document("census.xml")//person[name = "Joe"]
return children($j)
}
;
{
for $p in document("census.xml")//person,
$s in $p/@spouse->person
where $p/person/job = "Athlete" or $s/person/job = "Athlete"
return shallow($p)
}
;
{
for $p in document("census.xml")//person,
$c in $p/person
where $p/job = $c/job or $p/@spouse->person/job = $c/job
return shallow($c)
}
;
{
for $p in document("census.xml")//person,
$c in $p/person[job = $p/job]
return
}
{
for $p in document("census.xml")//person,
$c in $p/@spouse->person/person[job = $p/job]
return
}
;
{
for $b in document("census.xml")//person[name = "Bill"],
$c in $b/person | $b/@spouse->person/person,
$g in $c/person | $c/@spouse->person/person
return shallow($g)
}
;
{
for $b in document("census.xml")//person,
$c in $b/person | $b/@spouse->person/person,
$g in $c/person | $c/@spouse->person/person
return
}
;
{
for $s in document("census.xml")//person[name = "Dave"]/@spouse->person,
$sp in $s/.. | $s/../@spouse->person
return
shallow($sp)
}
;
{
for $p in document("census.xml")//person
where empty(children($p))
return shallow($p)
}
;
{
for $p in document("census.xml")//person[person]
where empty($p/@spouse->person)
return shallow($p)
}
;
define function descrip (element $e) returns element
{
let $kids := $e/* union $e/@spouse->person/*
let $mstatus := if ($e[@spouse]) then "Yes" else "No"
return
{ $e/@name/text() }
}
define function descendants (element $e)
{
if (empty($e/* union $e/@spouse->person/*))
then $e
else $e union descendants($e/* union $e/@spouse->person/*)
}
descrip(descendants(//person[name = "Joe"])) sortby(@nkids descending, .)
;
define function code(element of type ipo:Address $a) returns string
{
typeswitch ($a)
case element of type ipo:USAddress
return (treat as element of type ipo:USAddress($a))/zip/data()
case element of type ipo:UKAddress
return (treat as element of type ipo:UKAddress($a))/postcode/data()
default return "none"
}