XQuery Functions

XQuery 1.0, XPath 2.0, and XSLT 2.0 share the same functions library.

A list of different types of XQuery functions:

  • Accessor Functions
  • Error and Trace Functions
  • Numeric Functions
  • String Functions
  • AnyURI Functions
  • Boolean Functions
  • Duration/Date/Time Functions
  • QName Functions
  • Node Functions
  • Sequence Functions
  • Context Functions

Functions are specified with fn: prefix. For example: fn:string(). But fn: is the default prefix of the namespace, so you do not need to be prefix fn when function is called.

Accessor Functions

IndexNameDescription
1)fn:node-name(node)It is used to return the node-name of the argument node.
2)fn:nilled(node)It is used to return a Boolean value indicating whether the argument node is nil.
3)fn:data(item.item,...)It is used to take a sequence of items and return a sequence of atomic values.
4)fn:base-uri()
fn:base-uri(node)
It returns the value of the base-uri property of the current or specified node.
5)fn:document-uri(node)It returns the value of the document-uri property for the specified node.

Error and Trace Functions

IndexNameDescription
1)fn:error()
fn:error(error)
fn:error(error,description)
fn:error(error,description,error-object)
Example: error(fn:qname('http://example.com/test', 'err:toohigh'), 'error: price is too high')result: returns http://example.com/test#toohigh and the string "error: price is too high" to the external processing environment.
2)fn:trace(value,label)it is used to debug queries.

Numeric Values Functions

IndexNameDescription
1)fn:abs(num)It returns the absolute value of the argument.
For example: abs(3.14)
Result: 3.14
2)fn:abs(num)It returns the absolute value of the argument
For example: abs(3.14)
Result: 3.14
Example: abs(-3.14)
Result: 3.14
3)fn:ceiling(num)It returns the smallest integer that is greater than the number argument
For example: ceiling(3.14)
Result: 4
4)fn:floor(num)It returns the largest integer that is not greater than the number argument
For example: floor(3.14)
Result: 3
5)fn:round(num)It is used to round of the number argument to the nearest integer
For example: round(3.14)
Result: 3
6)fn:round-half-to-even()Example: round-half-to-even(0.5)
Result: 0
Example: round-half-to-even(1.5)
Result: 2
Example: round-half-to-even(2.5)
Result: 2

String Functions

There is a lot of string functions used in XQuery but here we are using the selected one.

A list of commonly used string manipulation functions of XQuery:

IndexNameDescription
1)string-length($string as xs:string) as xs:integer
It returns the length of the string.
2)concat($input as xs:anyatomictype?) as xs:stringIt returns the concatenated string as output.
3)string-join($sequence as xs:string*, $delimiter as xs:string) as xs:stringIt returns the combination of items in a sequence separated by a delimiter.

Boolean Value Functions

IndexNameDescription
1)fn:boolean(arg)It is used to return a Boolean value for a number, string, or node-set.
2)fn:not(arg)It specifies that the argument is first reduced to a Boolean value by applying the Boolean() function. It returns true if the Boolean value is false, and false if the Boolean value is true.
For example: not(true())
Result: false
3)fn:true()It returns the Boolean value true
Example: true()
Result: true
4)fn:false()It returns the Boolean value false
For example: false()
Result: false

Time and Date Function

There are a lot of time and date function supported in XQuery but here, we are providing the selected one.

A list of some commonly used date and time functions provided by XQuery:

IndexNameDescription
1)current-date()It is used to return the current date.
2)current-time()It is used to return the current time.
3)current-datetime()It is used to return both the current date and the current time.




Latest Courses