XML Data Management XPath Exercises Right or Wrong

  • Slides: 11
Download presentation
XML Data Management XPath Exercises: Right or Wrong? Werner Nutt

XML Data Management XPath Exercises: Right or Wrong? Werner Nutt

Right or Wrong? 1. How many calories are in Linguine alla Pescatora? /recipes/recipe[title/text()= "Linguine

Right or Wrong? 1. How many calories are in Linguine alla Pescatora? /recipes/recipe[title/text()= "Linguine alla Pescatora"] /nutrition/@calories … and what about style?

Right or Wrong? 4. Which recipe has the highest number of calories? //recipe[nutrition/@calories >

Right or Wrong? 4. Which recipe has the highest number of calories? //recipe[nutrition/@calories > preceding: : nutrition/@calories | nutrition/@calories > following: : nutrition/@calories] /title … and what about style?

Right or Wrong? 4. Which recipe has the highest number of calories? //recipe[not(nutrition/@calories <=

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) and not(nutrition/@calories <= ancestor: : recipe/nutrition/@calories)] … and what about style?

Right or Wrong? 6. How many compound ingredients (i. e. , ingredients with ingredients)

Right or Wrong? 6. How many compound ingredients (i. e. , ingredients with ingredients) are there in Ricotta Pie? count(/recipes/recipe[title/text() = "Ricotta Pie"] /. //ingredient[. /ingredient]) … and what about style?

Right or Wrong? 8. Which recipes have an ingredient whose preparation needs more steps

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)] … and what about style?

Right or Wrong? 8. Which recipes have an ingredient whose preparation needs more steps

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)? /recipes/recipe [. //ingredient [count(preparation/step) > count(. /ancestor: : *[name()='recipe'][1] /preparation/step)]] … and what about style?

Right or Wrong? 13. Return the ingredients of recipes other than Zuppa Inglese that

Right or Wrong? 13. Return the ingredients of recipes other than Zuppa Inglese that these recipes have in common with Zuppa Inglese. //recipe[title != "Zuppa Inglese" and. //ingredient/@name = //recipe[title="Zuppa Inglese”]//ingredient [((@name =. /preceding: : *//ingredient/@name) or (@name =. /following: : *//ingredient/@name))] ] //ingredient … and what about style?

Right or Wrong? 17. Return the names of those ingredients that are mentioned in

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)]]

Right or Wrong? 17. Return the names of those ingredients that are mentioned in

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

Right or Wrong? 17. Return the names of those ingredients that are mentioned in

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?