-<example-queries>
-<query>
<description>Simple fulltext query on Shakespeare plays</description>
<code>for $speech in //SPEECH[LINE &= 'love'] return $speech</code>
</query>
-<query>
<description>Fulltext query using near</description>
<code>for $speech in //SPEECH[SPEAKER &= 'witch' and near(., 'fenny snake')] return $speech</code>
</query>
-<query>
<description>Show the context of a match</description>
<code>for $speech in //SPEECH[near(LINE, 'to be or not')] let $scene := $speech/ancestor::SCENE, $act := $scene/ancestor::ACT, $play := $scene/ancestor::PLAY return <hit> <play title="{$play/TITLE}"> <act title="{$act/TITLE}"> <scene title="{$scene/TITLE}">{$speech}</scene> </act> </play> </hit></code>
</query>
-<query>
<description>Group hits by play</description>
<code>let $speech := //SPEECH[LINE &= "passion*"] let $plays := (for $s in $speech return root($s)) for $play in $plays/PLAY let $hits := $play//$speech return <play title="{$play/TITLE}" hits="{count($hits)}"> {$hits} </play></code>
</query>
-<query>
<description>Show table of contents for Macbeth</description>
<code> <toc>{ for $act in doc("/db/shakespeare/plays/macbeth.xml")/PLAY/ACT return <act> {$act/TITLE} { for $scene in $act/SCENE return <scene> {$scene/TITLE} <actors> { for $speaker in distinct-values($scene//SPEAKER) order by $speaker return <actor>{$speaker}</actor> } </actors> </scene> } </act> }</toc></code>
</query>
-<query>
<description>Find books by author</description>
<code>xquery version "1.0"; declare namespace rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"; declare namespace dc="http://purl.org/dc/elements/1.1/"; for $p in distinct-values(doc('/db/library/biblio.rdf')//dc:creator) let $books := //rdf:Description[dc:creator&=$p] return <result> <creator titles="{count($books)}">{$p}</creator> {for $b in $books return $b/dc:title} </result></code>
</query>
-<query>
<description>Find a city by name</description>
<code> (: This script accesses the mondial database, which can be found at http://dbis.informatik.uni-goettingen.de/Mondial/ :) for $city in /mondial//city[name&='tre*'] return <result> {$city} <country>{$city/ancestor::country/name}</country> <province>{$city/ancestor::province/name}</province> </result></code>
</query>
-<query>
<description>Show countries with decreasing population</description>
<code>for $c in //country[population_growth < 0] order by $c/name return <country> {$c/name, $c/population_growth} </country> </code>
</query>
-<query>
<description>Find spanish provinces and their cities</description>
<code>xquery version "1.0"; (: This script accesses the mondial database, which can be found at http://dbis.informatik.uni-goettingen.de/Mondial/ :) let $country := /mondial/country[name = 'Spain'] for $province in $country/province order by $province/name return <province> {$province/name} { for $city in $country//city[@province=$province/@id] order by $city/name return $city } </province></code>
</query>
-<query>
<description>List all organizations Germany is a member of</description>
<code> (: This script accesses the mondial database, which can be found at http://dbis.informatik.uni-goettingen.de/Mondial/ :) /mondial/id(/mondial/country[@car_code="D"]/@memberships)</code>
</query>
-<query>
<description>Countries having a common border with Austria</description>
<code>/mondial/id(/mondial/country[name = "Austria"]/border/@country)/name </code>
</query>
-<query>
<description>For each country, list 3 cities with highest population</description>
<code>(: This script accesses the mondial database, which can be found at http://dbis.informatik.uni-goettingen.de/Mondial/ :) for $country in /mondial/country let $cities := (for $city in $country//city[population] order by xs:integer($city/population[1]) descending return $city) order by $country/name return <country name="{$country/name}"> { subsequence($cities, 1, 3) } </country></code>
</query>
-<query>
<description>Show countries with highest roman catholic population</description>
<code>for $country in /mondial/country where some $r in $country/religions satisfies $r = "Roman Catholic" order by $country/religions[. = "Roman Catholic"]/@percentage cast as xs:double descending return <country name="{$country/name}"> {$country/religions} </country> </code>
</query>
-<query>
<description>Java binding (static)</description>
<code>xquery version "1.0"; declare namespace math="java:java.lang.Math"; <random>{ceiling(math:random() * 100)}</random></code>
</query>
-<query>
<description>Java binding (instance)</description>
<code>xquery version "1.0"; declare namespace rand="java:java.util.Random"; let $r := rand:new() return <random>{rand:nextInt($r, 100)}</random></code>
</query>
-<query>
<description>Request module</description>
<code>xquery version "1.0"; declare namespace request="http://exist-db.org/xquery/request"; <request> <request-uri>{request:get-uri()}</request-uri> <parameters> { for $name in request:get-parameter-names() return <parameter name="{$name}"> <value>{request:get-parameter($name, ())}</value> </parameter> } </parameters> </request></code>
</query>
-<query>
<description>Display system properties</description>
<code> <system> <version>{util:system-property("product-version")}</version> <build>{util:system-property("product-build")}</build> <jvm>{util:system-property("java.vendor"), util:system-property("java.version")}</jvm> </system></code>
</query>
</example-queries>