XQuery HTML Format
XQuery can also be used to transform an XML document into an HTML page.
Let's take an example to see how it works:
XQuery HTML Format Example
Let's take an XML file named "books.xml", having the following code.
This example will select all the title elements under the book elements that are under the bookstore element, and return the title elements in alphabetical order.
Now, create a Java based XQuery executor program to read the books.xqy, passes it to the XQuery expression processor, and executes the expression. After that the result will be displayed.
Execute XQuery against XML
Put the above three files to a same location. We put them on desktop in a folder name XQuery4. Compile XQueryTester.java using console. You must have JDK 1.5 or later installed on your computer and classpaths are configured.
If you want to eliminate the title element and show only the data inside the title element, use the following XQuery expression: