Posts

Showing posts from September, 2021

Xquery functions

Xquery functions: Functions are a set of instructions bundled together to achieve a specific outcome. Functions are a good alternative to having repeating blocks of code in a program. Values can be passed to a function using variables – we call these parameters or arguments. XQuery provides the capability to write custom functions. Listed below are the guidelines to create a custom function. We can use predefined XQuery functions in code. We can also declare custom functions as per our requirements. Method overloading can be used in Xquery. Method recursion can be used in Xquery also. Below is the syntax to create custom functions in Xquery: declare function  prefix:function_name ($ parameter as datatype ) as  returnDatatype {  ... function code here ... }; Recursive functions example: 1. declare function local:check-num($num as xs:int) {  let $result :=   if($num gt 2) then ( let $cal := ($num - 1) return local:check-num($cal)      ) else(                  if($num eq

Xquery

Image
XQuery XQuery is a functional programming query language that is used to transform or querying XML or JSON, binary. etc., data. The language is developed by the XML Query a working group of the W3C. XQuery 1.0 [2003] became a W3C Recommendation on January 23, 2007.[4] All XQuery functions and types are written in lower-case. Case-sensitive language The string value can be in single or double code. Variable name defined with $ and cannot start with number Comment (::) A Complete query always follows the FLOWR expressions, without FLOWR expressions query will never be complete. F: for – Behave like Loop as for loop in java L: let – Uses for creating a variable O: order by – sort the result    W: where – filter the nodes/result R: return – return evaluated query result   👉 for / let and return are must keywords for creating any query. Example:               let $a := "abc" return $a              or              for $each in (1 to 10) return $each   Variables: There are t