Online XPath tester v: 0.015
What is XPath?
XPath is a querry language used for selecting nodes from XML and processing them.
It may perform operations on strings, numbers and boolean values.
XPath 2.0 introduced many new features XQuery-cośtam:
- Added support for all XML simple types
- Many new functions (trippled instruction count)
- All expressions evaluate to sequence
- Introduces conditional expressions and for-loops
XPath 3.0
- Dynamic function collapsible
- Inline functions
- Support for union types
- Introduced maps
XPath 1.0 functions
[1.0]
[1.0]
[1.0]
[1.0]
[1.0]
[1.0]
fn:last() - Returns the position of the
last node in the context list
Link do dokumentacji W3C: Node-Set-Functions
fn:position() - Returns the position of the
current context node
Link do dokumentacji W3C: Node-Set-Functions
fn:count(node-set) - Returns the number of
nodes in the node-set
Arguments and return type
Examples:
[1.0] | Type | Description |
|---|---|
| node-set | Node-set to count nodes in |
| Expression | Result |
|---|---|
| count(//b:book) | 5 |
| count(//person[@id>5]) | 17 |
Link do dokumentacji W3C: Node-Set-Functions
fn:id(object) - Returns the element
specified by it's unique id, requires DTD
Link do dokumentacji W3C: Node-Set-Functions
fn:local-name(node-set) - Returns the
local-name for the first node in the node-set
Arguments and return type
Examples:
[1.0] | Type | Description |
|---|---|
| node-set | Extract first node and return its local name |
| Expression | Result |
|---|---|
| local-name(//b:books) | b:book |
| local-name(//b:book) | b:title |
Link do dokumentacji W3C: Node-Set-Functions
fn:local-name() - Returns the local-name
for the context node
Link do dokumentacji W3C: Node-Set-Functions
fn:namespace-uri(node-set) - Returns the
namespace-uri for the first node in the node-set
Arguments and return type
Examples:
[1.0] | Type | Description |
|---|---|
| node-set | Extract first node and return the namespace URI |
| Expression | Result |
|---|---|
| namespace-uri(//b:book) | http://www.book.com |
Link do dokumentacji W3C: Node-Set-Functions
fn:namespace-uri() - Returns the
namespace-uri for the context node
Link do dokumentacji W3C: Node-Set-Functions
fn:name(node-set) - Returns the name for
the first node in the node-set
Arguments and return type
Examples:
[1.0] | Type | Description |
|---|---|
| node-set | Extract first node and return QName |
| Expression | Result |
|---|---|
| name(//b:books/*) | b:book |
| name(//b:book/*) | b:title |
Link do dokumentacji W3C: Node-Set-Functions
fn:name() - Returns the name for the
context node
Examples:
| Expression | Result |
|---|---|
| current context node | Extract first node and return QName |
Link do dokumentacji W3C: Node-Set-Functions
[1.0]
[1.0]
[1.0]
[1.0]
fn:string(object) - Returns the string
representation of the object argument
Arguments and return type
Examples:
[1.0] | Type | Description |
|---|---|
| string | The object to convert to a string |
| Expression | Result |
|---|---|
| string((1<0)) | false |
| string(.11) | 0.11 |
Link do dokumentacji W3C: String-Functions
fn:string() - Returns a string value
representation of the context node
Link do dokumentacji W3C: String-Functions
fn:concat(string, string, string*) -
Returns the concatenation of its arguments
Arguments and return type
Examples:
[1.0] | Type | Description |
|---|---|
| string | String to be merged |
| string | String to be merged |
| string* | any number of strings |
| Expression | Result |
|---|---|
| concat("aa","bb") | aabb |
| concat("aa", 123) | aa123 |
Link do dokumentacji W3C: String-Functions
fn:starts-with(string, string) - Returns
true if the first string starts with the second string
Arguments and return type
Examples:
[1.0] | Type | Description |
|---|---|
| string | String to be searched |
| string | String to be found |
| Expression | Result |
|---|---|
| starts-with("aabb", "aa") | true |
| starts-with("aabb", "cc") | false |
Link do dokumentacji W3C: String-Functions
fn:contains(string, string) - Returns true
if the first string contains the second string
Arguments and return type
Examples:
[1.0] | Type | Description |
|---|---|
| string | String to be searched |
| string | String to be found |
| Expression | Result |
|---|---|
| contains("abc", "c") | true |
| contains("abc", "1") | false |
Link do dokumentacji W3C: String-Functions
fn:substring-before(string, string) -
Returns the substring found before the first occurrence of the second argument
Arguments and return type
Examples:
[1.0] | Type | Description |
|---|---|
| string | String to be searched |
| string | String to be used to split |
| Expression | Result |
|---|---|
| substring-before("aabbcc","bb") | aa |
| substring-before("aabbcc","c") | aabb |
Link do dokumentacji W3C: String-Functions
fn:substring-after(string, string) -
Returns the substring found after the first occurrence of the second argument
Arguments and return type
Examples:
[1.0] | Type | Description |
|---|---|
| string | String to be searched |
| string | String to be used to split |
| Expression | Result |
|---|---|
| substring-after("aabbcc","bb") | cc |
| substring-after("aabbcc","a") | abbcc |
Link do dokumentacji W3C: String-Functions
fn:substring(string, number, number) -
Returns the substring starting at second argument with lenght of third argument
Arguments and return type
Examples:
[1.0] | Type | Description |
|---|---|
| string | String to be cut |
| integer | Starting position |
| integer | Length of the substring |
| Expression | Result |
|---|---|
| substring("aabbcc", 1, 2) | aa |
Link do dokumentacji W3C: String-Functions
fn:substring(string, number) - Returns the
substring of the first argument from the position specified by the second argument
Arguments and return type
Examples:
[1.0] | Type | Description |
|---|---|
| string | String to be cut |
| integer | Starting position |
| Expression | Result |
|---|---|
| substring("aabbcc", 3) | bbcc |
Link do dokumentacji W3C: String-Functions
fn:string-length(string) - Returns the
length of the string specified by the argument
Arguments and return type
Examples:
[1.0] | Type | Description |
|---|---|
| string | String of which length should be returned |
| Expression | Result |
|---|---|
| string-length("aabbcc") | 6 |
| string-length("aa bb cc") | 8 |
Link do dokumentacji W3C: String-Functions
fn:string-length() - Returns the length of
the string specified by the context node
Link do dokumentacji W3C: String-Functions
fn:normalize-space(string) - Returns a
white-space normalized string
Arguments and return type
Examples:
[1.0] | Type | Description |
|---|---|
| string | String to be normalized |
| Expression | Result |
|---|---|
| normalize-space("aa bb cc") | aa bb cc |
| normalize-space("aa bb cc") | aa bb cc |
Link do dokumentacji W3C: String-Functions
fn:normalize-space() - Returns a
white-space normalized string specified by the context-node
Link do dokumentacji W3C: String-Functions
fn:translate(string, string, string) -
Replaces characters specified by the second argument using those from the third argument
Arguments and return type
Examples:
| Type | Description |
|---|---|
| string | String to be edited |
| string | sequence of characters to be replaced |
| string | sequence of character to be used in replacement |
| Expression | Result |
|---|---|
| translate("aabbcc", "ab","xz") | xxzzcc |
| translate("Test sequence", "e","z") | Tzst szquzncz |
Link do dokumentacji W3C: String-Functions
[1.0]
fn:boolean(object) - Returns the boolean
representation of the object argument
Arguments and return type
Examples:
[1.0] | Type | Description |
|---|---|
| expression | The expression to be evaluated |
| Expression | Result |
|---|---|
| boolean(1>2) | false |
| boolean("a"="a") | true |
Link do dokumentacji W3C: Boolean-Functions
fn:not(boolean) - Returns a boolean with
the opposite value of its argument
Arguments and return type
Examples:
[1.0] | Type | Description |
|---|---|
| boolean | Boolean value to be inverted |
| Expression | Result |
|---|---|
| not("a"="a") | false |
| not(true) | false |
Link do dokumentacji W3C: Boolean-Functions
fn:true() - Returns a boolean with the
value of true
Arguments and return type
Examples:
[1.0] | Type | Description |
|---|---|
| Returns boolean value true |
| Expression | Result |
|---|---|
| true() | true |
Link do dokumentacji W3C: Boolean-Functions
fn:false() - Returns a boolean with the
value of false
Arguments and return type
Examples:
[1.0] | Type | Description |
|---|---|
| Returns boolean value false |
| Expression | Result |
|---|---|
| false() | false |
Link do dokumentacji W3C: Boolean-Functions
fn:lang(string) - Returns true if the
language of the context node is the same as the languag specified by the argument
Arguments and return type
Examples:
| Type | Description |
|---|---|
| string | Checks if the context node matches given language |
| Expression | Result |
|---|---|
| (context: ): lang('en') | true |
| (context: ): lang('en') | true |
| (context: ): lang('en') | false |
Link do dokumentacji W3C: Boolean-Functions
[1.0]
fn:number(object) - Returns the number
representation of the object argument
Arguments and return type
Examples:
[1.0] | Type | Description |
|---|---|
| object | Converts given object to a number |
| Expression | Result |
|---|---|
| number(true()) | 1 |
| number(false()) | 0 |
| number("55") | 55 |
| number(" 55 ") | 55 |
Link do dokumentacji W3C: Number-Functions
fn:number() - Returns the number
representation of the context node
Arguments and return type
Examples:
[1.0] | Type | Description |
|---|---|
| current context node | Converts current context node to a number |
| Expression | Result |
|---|---|
| number(true()) | 1 |
| number(false()) | 0 |
| number("55") | 55 |
| number(" 55 ") | 55 |
Link do dokumentacji W3C: Number-Functions
fn:sum(node-set) - Returns the sum of all
nodes in the node-set
Arguments and return type
[1.0] | Type | Description |
|---|---|
| node-set | Summs each node from the set passed through number() function |
Link do dokumentacji W3C: Number-Functions
fn:floor(number) - Returns the largest
integer value not greater than the argument
Arguments and return type
Examples:
[1.0] | Type | Description |
|---|---|
| number | Decimal number to be converted to integer |
| Expression | Result |
|---|---|
| floor(3.1) | 3 |
| floor(3.99) | 3 |
Link do dokumentacji W3C: Number-Functions
fn:ceiling(number) - Returns the smallest
integer value not less than the argument
Arguments and return type
Examples:
[1.0] | Type | Description |
|---|---|
| number | Decimal number to be converted to integer |
| Expression | Result |
|---|---|
| ceiling(3.1) | 4 |
| ceiling(3.99) | 4 |
Link do dokumentacji W3C: Number-Functions
fn:round(number) - Returns the integer
value closest to the argument
Arguments and return type
Examples:
| Type | Description |
|---|---|
| number | Decimal number to be converted to integer |
| Expression | Result |
|---|---|
| round(3.1) | 3 |
| round(3.6) | 4 |
Link do dokumentacji W3C: Number-Functions