Monday, September 6, 2010

simple XQuery

As we know that XQuery is a W3c standard, Saxonica is the best tool so far i explored for various requirements. But I don't know the particular reason why most of the xml developers not choosing it. If you want to derive some information from lot of xml files, better do it in easy X-query.

You can write functions like in a scripting language. The main thing is that you need to understand FLOWER expression to iterate throw a XML tree,

FLWOR means for, let, where, order by, and return

Look at this this simple example

flwor.xq













In this xquery example, we have two xml file, one is emps.xml and depts.xml, which is shown below. In emps.xml, each 'emp' element has deptno reference which is present in depts.xml, So this X-query selects all the employee from emps.xml for this the criteria is that there should be more than one employee present for a same department. Please check it with the result attached below.

depts.xml








emps.xml























result.xml











Lets see an example with functions, it is easy to write a function like we write it in XSLT function, but in XSLT function is like again a xml data , but in xquery it is like a scripting language function.

simple-xq-func.xq




















result.xml









For more information read the W3C pages for Xquery use cases page
http://www.w3.org/TR/xquery-use-cases

No comments:

Post a Comment