Home >>XQuery Tutorial >XQuery Add

XQuery Add

XQuery Add

XQuery Attach is used to add elements, descriptions, HTML elements, and text to input document data.

Let's understand with an example.

XQuery Add Example

Take an XML file named books.xml, having the following data.


<book category="Mythology">  
<title lang="en">Immortals of Meluha</title>  
<book category="Children">  
<title lang="en">Max</title>  
<book category="Programming">  
<title lang="en">Let's C</title>  

XQuery Expression


for $x in doc("books.xml")/bookstore/book/title  
order by $x  
return $x 

Add HTML Elements and Text

If you want to add some HTML elements to the result, use the XQuery like this:


for $x in doc("books.xml")/bookstore/book  
order by $x/title  
return <li>{data($x/title)}. Category: {data($x/@category)}</li>