XQuery Functions
XQuery 1.0, XPath 2.0, and XSLT 2.0 share the same function library.
XQuery Functions
XQuery contains over 100 built-in functions. These functions can be used for string values, numeric values, date and time comparisons, node and QName operations, sequence operations, logical values, and more. You can also define your own functions in XQuery.
Built-in XQuery Functions
The URI for the XQuery function namespace:
http://www.w3.org/2005/02/xpath-functions
The default prefix for the function namespace is fn:.
You can find the complete Built-in XQuery Function Reference in our XPath tutorial.
Function Call Examples
Function calls can be used with expressions. See the examples below:
Example 1: In an Element
Example 2: In a Path Expression Predicate
Example 3: In a Let Statement
XQuery User-Defined Functions
If you cannot find the required XQuery function, you can write your own.
User-defined functions can be defined in the query or in a separate library.
Syntax
Notes on User-Defined Functions:
Use the declare function keyword
The function name must use a prefix
The data type of the parameters usually matches the data types defined in XML Schema
The function body must be enclosed in curly braces