XQuery FLWOR + HTML
- Previous Page XQuery FLWOR
- Next Page XQuery Terminology
XML Sample Document
We will continue to use this "books.xml" document in the following examples (the same as the file in the previous section).
Submit the results in an HTML list
Please see the following XQuery FLWOR expression:
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 of the bookstore element and returns them in alphabetical order.
Now, we want to list all the books in our bookstore using an HTML list. We add <ul> and <li> tags to the FLWOR expression:
<ul> { for $x in doc("books.xml")/bookstore/book/title order by $x return <li>{$x}</li> } </ul>
The result of the above code:
<ul> <li><title lang="en">Everyday Italian</title></li> <li><title lang="en">Harry Potter</title></li> <li><title lang="en">Learning XML</title></li> <li><title lang="en">XQuery Kick Start</title></li> </ul>
Now we want to remove the title element and only display the data within the title element.
<ul> { for $x in doc("books.xml")/bookstore/book/title order by $x return <li>{data($x)}</li> } </ul>
The result will be an HTML list:
<ul> <li>Everyday Italian</li> <li>Harry Potter</li> <li>Learning XML</li> <li>XQuery Kick Start</li> </ul>
- Previous Page XQuery FLWOR
- Next Page XQuery Terminology