XQuery "Adding Elements" and "Attributes"
XML Example Document
We will continue to use the "books.xml" document in the following examples (the same XML file used in the previous section).
View the "books.xml" file in your browser.
Adding Elements and Attributes to the Result
As seen in the previous section, we can reference elements and attributes from the input file in the result:
The above XQuery expression will reference the title element and the lang attribute in the result, like this:
The above XQuery expression returns the title elements in the same way they are described in the input document.
Now we are going to add our own elements and attributes to the result!
Adding HTML Elements and Text
Now, we are going to add HTML elements to the result. We will place the result in an HTML list:
The above XQuery expression will generate the following result:
Adding Attributes to HTML Elements
Next, we are going to use the category attribute as the class attribute in the HTML list:
The above XQuery expression can generate the following result: