Übung 3
1) Print all countries which are stored in the XML document
descendant::country/@name
2) How many countries can be found?
231
3) Print the names of all Chinese cities
descendant::country[./@name = "China"]/descendant-or-self::city/name/text()
4) How many people live in Bangladesh?
descendant::country[./@name = Bangladesh]/@population
5) In which countries live more than 10 million people?
descendant::country[./@population > 10000000]/@name
6) Find the first 3 French cities which are stored in the document
descendant::country[./@name = "France"]/descendant-or-self::city[position() <= 3]/name/text()
7) Print all countries in which more than 60% of the population speak German
descendant::ethnicgroups[. = "German"][./@percentage > 60]/ancestor::country/@name
8) Print the average number of inhabitants of all cities in the document
sum(descendant::city/population) div count(descendant::city)
9) Print the names of all cities that have more than 20 characters
descendant::city/name[string-length(.) > 20]
10) How many tag names in the document have less than 3 characters?
Übung 4
Exercise 2:
1)
for $j in descendant::ethnicgroups
where $j = 'Russian' and $j/parent::country/@id =
(for $i in descendant::ethnicgroups
where $i = 'Jewish'
return $i/parent::country/@id)
return $j/parent::country/@name
oder
for $y in descendant::country
let $x := $y/ethnicgroups
where $x = "Russian" and $x = "Jewish"
return $y/@name
2)
for $y in descendant::country/@name
order by $y
return $y
3)
for $y in descendant::organization
where count($y/member) > 180
return $y/@name | $y/@established
oder
for $y in descendant::organization
where count($y/member) > 180
return ($y/@name , $y/@established)
4)
<results>{
for $y in descendant::country
return <result>{$y/@name}</result>
}</results>