====== Kurs XML-a, zadanie 15. ====== Jedna uwaga: kolejności atrybutów się nie zgadzają. xquery version "1.0"; declare function local:distance($from, $to, $doc, $dist) as node() { if (exists($from[name = $to/name]) ) then else if ($dist > count($doc/country)) then else let $neighbours := ( for $code in $from/border/@country return $doc/country[@car_code = $code] ) return local:distance($from union $neighbours, $to, $doc, $dist + 1) }; let $doc := doc("mondial-europe.xml")/mondial let $top_cities := ( for $city in $doc//city let $population := avg($city/population) order by number($population) descending return $city ) let $top30_cities := subsequence($top_cities, 1, 30) return { for $country in $doc/country let $name := $country/name/text() let $population := $country/population/text() let $gdp := $country/gdp_total/text() where exists($gdp) order by number($gdp) div number($population) descending return {$name} {$gdp} {$population} } { let $sea := $doc/sea[name="Mediterranean Sea"] for $code in tokenize($sea/@country, " ") return } { for $city in $top30_cities let $country := $doc/country[province/city = $city] return {$city/name/text()} {xs:integer(avg($city/population))} {$country/name/text()} } { for $country in $doc/country let $cities := $country//city intersect $top30_cities where count($cities) gt 0 order by count($cities) descending return { for $city in $cities return {$city/name/text()} } } { for $country in $doc/country let $religion := $country/religions[@percentage>50] for $code in $country/border/@country let $other_country := $doc/country[@car_code=$code] let $other_religion := $other_country/religions[@percentage>50] where $country/name < $other_country/name and $religion ne $other_religion return } { for $group in distinct-values($doc//ethnicgroups) order by $group return { for $country in $doc/country[ethnicgroups = $group] let $percentage := $country/ethnicgroups[text() = $group]/@percentage order by number($percentage) descending return } } { let $poland := $doc/country[name = "Poland"] for $country in $doc/country let $dist := local:distance($poland, $country, $doc, 0) where $dist/@distance ne "infinity" order by number($dist/@distance) return $dist }