Task 1: Open countries.xml, compose the following XQueries: 1. Return the area of Mongolia. 2. Return the names of all cities that have the same name ...
Task 1: Open countries.xml, compose the following XQueries:
1. Return the area of Mongolia.
2. Return the names of all cities that have the same name as the country in which they are located.
3. Return the average population of Russian-speaking countries.
4. Returnthenamesofallcountrieswhereover50%ofthepopulationspeaksGerman. (Hint: Dependingonyoursolution, you may want to use ".", which refers to the "current element" within an XPath expression.)
5. Returnthenameofthecountrywiththehighestpopulation. (Hint: Youmayneedtoexplicitlycastpopulationnumbers as integers with xs:int() to get the correct answer.)
第一問:
for $x in doc("countries.xml")/countries/country where $x/@name="Mongolia" return <area>{data($x/@area)}</area>
第二問:
for $x in doc("countries.xml")/countries/country
for $y in $x/city
where $y/name= $x/@name
return $y/name
第三問:
avg(doc("countries.xml")/countries/country[language="Russian"]/@population)
第四問:
for $i in (doc("countries.xml")/countries/country/language[@percentage>50 and .="German"]/../@name) return <name>{data($i)}</name>
第五問:
for $x in doc("countries.xml")/countries/country where $x/@population = max(doc("countries.xml")/countries/country/@population) return <name>{data($x/@name)}</name>