XQuery Add

XQuery Add is used for adding elements, attributes, HTML elements and text in the results from the input documents.

Let's understand it by using an example.

XQuery Add Example

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

books.xml

snippet


Immortals of Meluha
Amish
2010
180


Harry Potter
J K. Rowling
2005
300


Let's C
Yashwant Kanetkar
2003
200

XQuery Expression

books.xqy

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

Now this XQuery expression will return the title elements in the same manner as they are described in the input document.

Output:

XQuery Add

Now you can add your own elements and attributes to the result.

Add HTML Elements and Text

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

book.xqy:

snippet



Bookstore

    { for $x in doc("books.xml")/bookstore/book order by $x/title return
  • {data($x/title)}. Category: {data($x/@category)}
  • }
XQuery Add2
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +