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