XQuery FLWOR + HTML
XML example document
We will continue to use this "books.xml" document in the examples below (the same file as in the previous section).
View the "books.xml" file in your browser.
Submit the result in an HTML list
Please look at the XQuery FLWOR expression below:
for $x in doc("books.xml")/bookstore/book/title
order by $x
return $x
The expression above selects all title elements under the book elements under the bookstore element and returns the title elements in alphabetical order.
Now, we want to list all the books in our bookstore using an HTML list. We add to the FLWOR expression
-
and
- tags:
-
{
- {
$x
}
for $x in doc("books.xml")/bookstore/book/title
order by $x
return
}The output of the above code:
-
Everyday Italian -
Harry Potter -
Learning XML -
XQuery Kick Start
Now we want to remove the title element and only display the data inside the title element.
- {
data(
$x
)
}
{
for $x in doc("books.xml")/bookstore/book/title
order by $x
return
}
The result will be an HTML list:
- Everyday Italian
- Harry Potter
- Learning XML
- XQuery Kick Start
- {