The XQuery expression above return the title elements the
exact same way as they are described in the input document.
We
now want to add our own element and attribute to the result!
Add HTML Elements and Text
Now, we want to add some HTML element to the result.
We will put the result in to an HTML list - together with some text:
<html>
<body>
<h1>Bookstore</h1>
<ul>
{
for $x in doc("booksdetail.xml")/bookstore/book
order by $x/title
return <li>{data($x/title)}. Category: {data($x/@category)}</li>
}
</ul>
</body>
</html>
The XQuery expression above will generate the following output:
Next, we want to use the category attribute as a class attribute in to the HTML list:
<html>
<body>
<h1>Bookstore</h1>
<ul>
{
for $x in doc("bookdetails.xml")/bookstore/book
order by $x/title
return <li class="{data($x/@category)}">{data($x/title)}</li>
}
</ul>
</body>
</html>
The XQuery expression above will generate the following output: