10.8k views
0 votes
Using the XML Document below (library with books), define the following queries in XQuery: (a) Give the titles of all Books sorted by Price. (b) How many books were written by Abiteboul? (c) Give for each author, the number of books he has written.

User Riley
by
4.7k points

1 Answer

4 votes

Answer:

Step-by-step explanation:

a)use order by clause for sorting

for $x in doc("books.xml")/bib/book order by xs:float($x/price) return $x/title (default sorted in ascending order)

or

for $x in doc("books.xml")/bib/book order by xs:float($b/price) descending return $b/title (sorted in descending order)

b)doc("books.xml")//book[author = 'Abiteboul']

c)for $x in distinct-values(doc("bib.xml")/bib/book/author)

return <res>

<name>{$x}</name>

<count>

{count (doc("bib.xml")//book[exists(indexof(author,$x))]) }

</count>

<res>

User Sili
by
5.0k points