xml data management xpath exercises: right or wrong? werner nutt
TRANSCRIPT
![Page 1: XML Data Management XPath Exercises: Right or Wrong? Werner Nutt](https://reader036.vdocuments.us/reader036/viewer/2022081811/5697bfd31a28abf838cac33c/html5/thumbnails/1.jpg)
XML Data Management
XPath Exercises: Right or Wrong?
Werner Nutt
![Page 2: XML Data Management XPath Exercises: Right or Wrong? Werner Nutt](https://reader036.vdocuments.us/reader036/viewer/2022081811/5697bfd31a28abf838cac33c/html5/thumbnails/2.jpg)
Right or Wrong?
2. Return the titles of the recipes that have
more than 500 calories.
//recipes/recipe/nutrition[@calories>500]
/../title
… and what about style?
![Page 3: XML Data Management XPath Exercises: Right or Wrong? Werner Nutt](https://reader036.vdocuments.us/reader036/viewer/2022081811/5697bfd31a28abf838cac33c/html5/thumbnails/3.jpg)
Right or Wrong?
3. Return the recipes for which at least 4 eggs are needed.
//recipe[sum(descendant::ingredient
[contains(@name,"egg")]
/@amount) >= 4]
/title
![Page 4: XML Data Management XPath Exercises: Right or Wrong? Werner Nutt](https://reader036.vdocuments.us/reader036/viewer/2022081811/5697bfd31a28abf838cac33c/html5/thumbnails/4.jpg)
Right or Wrong?
4. Which recipe has the highest number of calories?
//recipe[nutrition/@calories
> preceding::nutrition/@calories
and nutrition/@calories
> following::nutrition/@calories]
![Page 5: XML Data Management XPath Exercises: Right or Wrong? Werner Nutt](https://reader036.vdocuments.us/reader036/viewer/2022081811/5697bfd31a28abf838cac33c/html5/thumbnails/5.jpg)
Right or Wrong?
4. Which recipe has the highest number of calories?
//recipe[not(nutrition/@calories <=
preceding::recipe/nutrition/@calories)
and
not(nutrition/@calories <=
following::recipe/nutrition/@calories)]
… what exactly does this query return?
![Page 6: XML Data Management XPath Exercises: Right or Wrong? Werner Nutt](https://reader036.vdocuments.us/reader036/viewer/2022081811/5697bfd31a28abf838cac33c/html5/thumbnails/6.jpg)
Right or Wrong?
6. How many compound ingredients (i.e., ingredients with
ingredients) are there in Ricotta Pie?
count(//recipe[title="Ricotta Pie"]
/ingredient/ingredient/..)
… and what about style?
![Page 7: XML Data Management XPath Exercises: Right or Wrong? Werner Nutt](https://reader036.vdocuments.us/reader036/viewer/2022081811/5697bfd31a28abf838cac33c/html5/thumbnails/7.jpg)
Right or Wrong?
8. Which recipes have an ingredient whose preparation needs
more steps than are needed for the recipe itself (i.e., top
level steps)?
//recipe[count(ingredient/preparation/step)
>
count(preparation/step)]
![Page 8: XML Data Management XPath Exercises: Right or Wrong? Werner Nutt](https://reader036.vdocuments.us/reader036/viewer/2022081811/5697bfd31a28abf838cac33c/html5/thumbnails/8.jpg)
Right or Wrong?
10. Return the names of the ingredients of Zuppa Inglese.
//recipe[title="Zuppa Inglese"]/ingredient
![Page 9: XML Data Management XPath Exercises: Right or Wrong? Werner Nutt](https://reader036.vdocuments.us/reader036/viewer/2022081811/5697bfd31a28abf838cac33c/html5/thumbnails/9.jpg)
Right or Wrong?
12.Which recipes have an ingredient in common with
Zuppa Inglese?
//recipe[title!="Zuppa Inglese"]
[.//ingredient/@name =
//recipe[title="Zuppa Inglese"]
/ingredient/@name]
![Page 10: XML Data Management XPath Exercises: Right or Wrong? Werner Nutt](https://reader036.vdocuments.us/reader036/viewer/2022081811/5697bfd31a28abf838cac33c/html5/thumbnails/10.jpg)
Right or Wrong?
14.Return the names of all elementary ingredients that occur
in at least two recipes.
//recipe///ingredient
[count(.//ingredient) = 0
and
(@name = preceding::ingredient/@name
or
@name = following::ingredient/@name)]
/@name
![Page 11: XML Data Management XPath Exercises: Right or Wrong? Werner Nutt](https://reader036.vdocuments.us/reader036/viewer/2022081811/5697bfd31a28abf838cac33c/html5/thumbnails/11.jpg)
Right or Wrong?
14.Return the names of all elementary ingredients that occur
in at least two recipes.
//recipe[title!=preceding::title]
[ingredient/@name
=
//recipe/ingredient/@name]
/ingredient/@name
![Page 12: XML Data Management XPath Exercises: Right or Wrong? Werner Nutt](https://reader036.vdocuments.us/reader036/viewer/2022081811/5697bfd31a28abf838cac33c/html5/thumbnails/12.jpg)
Right or Wrong?
15.Return the titles of all recipes for which some form of egg
is needed (like egg whites or egg yolk).
//ingredient[@name[contains(.,'egg')]]
/ancestor::recipe/title
… and what about style?
![Page 13: XML Data Management XPath Exercises: Right or Wrong? Werner Nutt](https://reader036.vdocuments.us/reader036/viewer/2022081811/5697bfd31a28abf838cac33c/html5/thumbnails/13.jpg)
Right or Wrong?
17. Return the names of those ingredients that are mentioned in a
preparation step of their recipe.
//ingredient[//preparation/step
[contains(text(),@name)]]
![Page 14: XML Data Management XPath Exercises: Right or Wrong? Werner Nutt](https://reader036.vdocuments.us/reader036/viewer/2022081811/5697bfd31a28abf838cac33c/html5/thumbnails/14.jpg)
Right or Wrong?
17. Return the names of those ingredients that are mentioned in a
preparation step of their recipe.
//ingredient[contains(ancestor::recipe//step,
@name)]
/@name
![Page 15: XML Data Management XPath Exercises: Right or Wrong? Werner Nutt](https://reader036.vdocuments.us/reader036/viewer/2022081811/5697bfd31a28abf838cac33c/html5/thumbnails/15.jpg)
Right or Wrong?
17. Return the names of those ingredients that are mentioned in a
preparation step of their recipe.
//ingredient[contains(ancestor::recipe/preparation,
@name)]
/@name
Could we write a query that asks for an occurrence of the ingredient name
in any preparation step of the recipe?