Xpath Functions
* * *
The reference manual below defines functions in XPath 2.0, XQuery 1.0, and XSLT 2.0.
* * *
## Function Reference Manual
 The default prefix for the function namespace is fn:
 The URI for the function namespace is: http://www.w3.org/2005/xpath-functions
### (#)
| Name | Description |
| --- | --- |
| fn:node-name(node) | Returns the node name of the argument node. |
| fn:nilled(node) | Returns a Boolean indicating whether the argument node is nillable. |
| fn:data(item.item,...) | Accepts a sequence of items and returns a sequence of atomic values. |
| * fn:base-uri() * fn:base-uri(node) | Returns the value of the base-uri property of the current node or the specified node. |
| fn:document-uri(node) | Returns the value of the document-uri property of the specified node. |
### (#)
| Name | Description |
| --- | --- |
| * 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. |
| fn:trace(value,label) | Used for debugging queries. |
### (#)
| Name | Description |
| --- | --- |
| fn:number(arg) | Returns the numeric value of the argument. The argument can be a Boolean, string, or node-set. Example: number('100') Result: 100 |
| fn:abs(num) | Returns the absolute value of the argument. Example: abs(3.14) Result: 3.14 Example: abs(-3.14) Result: 3.14 |
| fn:ceiling(num) | Returns the smallest integer greater than the num argument. Example: ceiling(3.14) Result: 4 |
| fn:floor(num) | Returns the largest integer not greater than the num argument. Example: floor(3.14) Result: 3 |
| fn:round(num) | Rounds the num argument to the nearest integer. Example: round(3.14) Result: 3 |
| 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 |
### (#)
| Name | Description |
| --- | --- |
| fn:string(arg) | Returns the string value of the argument. The argument can be a number, Boolean, or node-set. Example: string(314) Result: "314" |
| fn:codepoints-to-string(int,int,...) | Returns a string based on a sequence of code points. Example: codepoints-to-string(84, 104, 233, 114, 232, 115, 101) Result: 'Thérèse' |
| fn:string-to-codepoints(string) | Returns a sequence of code points based on the string. Example: string-to-codepoints("Thérèse") Result: 84, 104, 233, 114, 232, 115, 101 |
| fn:codepoint-equal(comp1,comp2) | Returns true if comp1 equals comp2 according to Unicode code point collation (http://www.w3.org/2005/02/xpath-functions/collation/codepoint), otherwise returns false. |
| * fn:compare(comp1,comp2) * fn:compare(comp1,comp2,collation) | Returns -1 if comp1 is less than comp2; returns 0 if comp1 equals comp2; returns 1 if comp1 is greater than comp2 (according to the collation used). Example: compare('ghi', 'ghi') Result: 0 |
| fn:concat(string,string,...) | Returns the concatenation of the strings. Example: concat('XPath ','is ','FUN!') Result: 'XPath is FUN!' |
| fn:string-join((string,string,...),sep) | Returns the concatenated string of the string arguments, using the sep argument as the separator. Example: string-join(('We', 'are', 'having', 'fun!'), ' ') Result: ' We are having fun! ' Example: string-join(('We', 'are', 'having', 'fun!')) Result: 'Wearehavingfun!' Example: string-join((), 'sep') Result: '' |
| * fn:substring(string,start,len) * fn:substring(string,start) | Returns the substring of the specified length starting at position start. The index of the first character is 1. If the len argument is omitted, returns the substring from position start to the end of the string. Example: substring('Beatles',1,4) Result: 'Beat' Example: substring('Beatles',2) Result: 'eatles' |
| * fn:string-length(string) * fn:string-length() | Returns the length of the specified string. If no string argument is provided, returns the length of the string value of the current node. Example: string-length('Beatles') Result: 7 |
| * fn:normalize-space(string) * fn:normalize-space() | Removes leading and trailing whitespace from the specified string and replaces all internal sequences of whitespace with a single space, then returns the result. If no string argument is provided, operates on the current node. Example: normalize-space(' The XML ') Result: 'The XML' |
| fn:normalize-unicode() | Performs Unicode normalization. |
| fn:upper-case(string) | Converts the string argument to uppercase. Example: upper-case('The XML') Result: 'THE XML' |
| fn:lower-case(string) | Converts the string argument to lowercase. Example: lower-case('The XML') Result: 'the xml' |
| fn:translate(string1,string2,string3) | Replaces characters in string1 that occur in string2 with the corresponding characters in string3. Example: translate('12:30','30','45') Result: '12:45' Example: translate('12:30','03','54') Result: '12:45' Example: translate('12:30','0123','abcd') Result: 'bc:da' |
| fn:escape-uri(stringURI,esc-res) | Example: escape-uri("http://example.com/test#car", true()) Result: "http%3A%2F%2Fexample.com%2Ftest#car" Example: escape-uri("http://example.com/test#car", false()) Result: "http://example.com/test#car" Example: escape-uri ("http://example.com/~bΓ©bΓ©", false()) Result: "http://example.com/~b%C3%A9b%C3%A9" |
| fn:contains(string1,string2) | Returns true if string1 contains string2, otherwise returns false. Example: contains('XML','XM') Result: true |
| fn:starts-with(string1,string2) | Returns true if string1 starts with string2, otherwise returns false. Example: starts-with('XML','X') Result: true |
| fn:ends-with(string1,string2) | Returns true if string1 ends with string2, otherwise returns false. Example: ends-with('XML','X') Result: false |
| fn:substring-before(string1,string2) | Returns the substring of string1 before the first occurrence of string2. Example: substring-before('12/10','/') Result: '12' |
| fn:substring-after(string1,string2) | Returns the substring of string1 after the first occurrence of string2. Example: substring-after('12/10','/') Result: '10' |
| fn:matches(string,pattern) | Returns true if the string argument matches the specified pattern, otherwise returns false. Example: matches("Merano", "ran") Result: true |
| fn:replace(string,pattern,replace) | Replaces occurrences of the specified pattern with the replace argument and returns the result. Example: replace("Bella Italia", "l", "*") Result: 'Be**a Ita*ia' Example: replace("Bella Italia", "l", "") Result: 'Bea Itaia' |
| fn:tokenize(string,pattern) | Example: tokenize("XPath is fun", "s+") Result: ("XPath", "is", "fun") |
### (#)
| Name | Description |
| --- | --- |
| fn:resolve-uri(relative,base) | |
### (#)
| Name | Description |
| --- | --- |
| fn:boolean(arg) | Returns a number
YouTip