Books.xml:
ABC Author Name 2020 100.00 XQuery Book Author 1 Author 2 2005 300.00 Sociology 1 Author Name 2010 250.00 Current Affairs Author Name 2004 500.00 Science Book Author 1 Author 2 Author 3 2011 150.00
Present the Result In an HTML List:
Example 1:
for $x in doc("books.xml")/bookstore/book/title order by $x return $x
Explanation:
In the above example, we are using the XQuery FLWOR expression to select all the title elements under the book elements that are under the bookstore element. Here, we are returning the title elements in alphabetical order.
Example 2:
-
{
for $x in doc("books.xml")/bookstore/book/title
order by $x
return
- {$x} }
Explanation:
In the above example, we are listing all the book-titles in the bookstore in an HTML list by adding the <ul> and <li> tags to the FLWOR expression.
Result:
ABC XQuery Book Sociology 1 Current Affairs Science Book
Example 3:
-
{
for $x in doc("books.xml")/bookstore/book/title
order by $x
return
- {data($x)} }
Explanation:
In the above example, we are eliminating the title element, to show only the data inside the title element.
Result:
- ABC
- XQuery Book
- Sociology 1
- Current Affairs
- Science Book