FLWOR XQuery + HTML
- Προηγούμενη Σελίδα XQuery FLWOR
- Επόμενη Σελίδα Τερμίνισμοι XQuery
XML instance 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 above expression will select all title elements under the book elements under the bookstore element and return them in alphabetical order.
Now, we want to use an HTML list to list all the books in our bookstore. 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 is:
<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>
Οι αποτελέσματα θα είναι μια λίστα HTML:
<ul> <li>Everyday Italian</li> <li>Harry Potter</li> <li>Εκμάθηση XML</li> <li>Ξεκινήστε με το XQuery</li> </ul>
- Προηγούμενη Σελίδα XQuery FLWOR
- Επόμενη Σελίδα Τερμίνισμοι XQuery