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] fn:last() - Returns the position of the last node in the context list
Link do dokumentacji W3C: Node-Set-Functions
[1.0] fn:position() - Returns the position of the current context node
Link do dokumentacji W3C: Node-Set-Functions
[1.0] fn:count(node-set) - Returns the number of nodes in the node-set
Arguments and return type
Type Description
node-set Node-set to count nodes in
Examples:
Expression Result
count(//b:book) 5
count(//person[@id>5]) 17
Link do dokumentacji W3C: Node-Set-Functions
[1.0] fn:id(object) - Returns the element specified by it's unique id, requires DTD
Link do dokumentacji W3C: Node-Set-Functions
[1.0] fn:local-name(node-set) - Returns the local-name for the first node in the node-set
Arguments and return type
Type Description
node-set Extract first node and return its local name
Examples:
Expression Result
local-name(//b:books) b:book
local-name(//b:book) b:title
Link do dokumentacji W3C: Node-Set-Functions
[1.0] fn:local-name() - Returns the local-name for the context node
Link do dokumentacji W3C: Node-Set-Functions
[1.0] fn:namespace-uri(node-set) - Returns the namespace-uri for the first node in the node-set
Arguments and return type
Type Description
node-set Extract first node and return the namespace URI
Examples:
Expression Result
namespace-uri(//b:book) http://www.book.com
Link do dokumentacji W3C: Node-Set-Functions
[1.0] fn:namespace-uri() - Returns the namespace-uri for the context node
Link do dokumentacji W3C: Node-Set-Functions
[1.0] fn:name(node-set) - Returns the name for the first node in the node-set
Arguments and return type
Type Description
node-set Extract first node and return QName
Examples:
Expression Result
name(//b:books/*) b:book
name(//b:book/*) b:title
Link do dokumentacji W3C: Node-Set-Functions
[1.0] 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] fn:string(object) - Returns the string representation of the object argument
Arguments and return type
Type Description
string The object to convert to a string
Examples:
Expression Result
string((1<0)) false
string(.11) 0.11
Link do dokumentacji W3C: String-Functions
[1.0] fn:string() - Returns a string value representation of the context node
Link do dokumentacji W3C: String-Functions
[1.0] fn:concat(string, string, string*) - Returns the concatenation of its arguments
Arguments and return type
Type Description
string String to be merged
string String to be merged
string* any number of strings
Examples:
Expression Result
concat("aa","bb") aabb
concat("aa", 123) aa123
Link do dokumentacji W3C: String-Functions
[1.0] fn:starts-with(string, string) - Returns true if the first string starts with the second string
Arguments and return type
Type Description
string String to be searched
string String to be found
Examples:
Expression Result
starts-with("aabb", "aa") true
starts-with("aabb", "cc") false
Link do dokumentacji W3C: String-Functions
[1.0] fn:contains(string, string) - Returns true if the first string contains the second string
Arguments and return type
Type Description
string String to be searched
string String to be found
Examples:
Expression Result
contains("abc", "c") true
contains("abc", "1") false
Link do dokumentacji W3C: String-Functions
[1.0] fn:substring-before(string, string) - Returns the substring found before the first occurrence of the second argument
Arguments and return type
Type Description
string String to be searched
string String to be used to split
Examples:
Expression Result
substring-before("aabbcc","bb") aa
substring-before("aabbcc","c") aabb
Link do dokumentacji W3C: String-Functions
[1.0] fn:substring-after(string, string) - Returns the substring found after the first occurrence of the second argument
Arguments and return type
Type Description
string String to be searched
string String to be used to split
Examples:
Expression Result
substring-after("aabbcc","bb") cc
substring-after("aabbcc","a") abbcc
Link do dokumentacji W3C: String-Functions
[1.0] fn:substring(string, number, number) - Returns the substring starting at second argument with lenght of third argument
Arguments and return type
Type Description
string String to be cut
integer Starting position
integer Length of the substring
Examples:
Expression Result
substring("aabbcc", 1, 2) aa
Link do dokumentacji W3C: String-Functions
[1.0] fn:substring(string, number) - Returns the substring of the first argument from the position specified by the second argument
Arguments and return type
Type Description
string String to be cut
integer Starting position
Examples:
Expression Result
substring("aabbcc", 3) bbcc
Link do dokumentacji W3C: String-Functions
[1.0] fn:string-length(string) - Returns the length of the string specified by the argument
Arguments and return type
Type Description
string String of which length should be returned
Examples:
Expression Result
string-length("aabbcc") 6
string-length("aa bb cc") 8
Link do dokumentacji W3C: String-Functions
[1.0] fn:string-length() - Returns the length of the string specified by the context node
Link do dokumentacji W3C: String-Functions
[1.0] fn:normalize-space(string) - Returns a white-space normalized string
Arguments and return type
Type Description
string String to be normalized
Examples:
Expression Result
normalize-space("aa bb cc") aa bb cc
normalize-space("aa bb cc") aa bb cc
Link do dokumentacji W3C: String-Functions
[1.0] fn:normalize-space() - Returns a white-space normalized string specified by the context-node
Link do dokumentacji W3C: String-Functions
[1.0] fn:translate(string, string, string) - Replaces characters specified by the second argument using those from the third argument
Arguments and return type
Type Description
string String to be edited
string sequence of characters to be replaced
string sequence of character to be used in replacement
Examples:
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
Type Description
expression The expression to be evaluated
Examples:
Expression Result
boolean(1>2) false
boolean("a"="a") true
Link do dokumentacji W3C: Boolean-Functions
[1.0] fn:not(boolean) - Returns a boolean with the opposite value of its argument
Arguments and return type
Type Description
boolean Boolean value to be inverted
Examples:
Expression Result
not("a"="a") false
not(true) false
Link do dokumentacji W3C: Boolean-Functions
[1.0] fn:true() - Returns a boolean with the value of true
Arguments and return type
Type Description
Returns boolean value true
Examples:
Expression Result
true() true
Link do dokumentacji W3C: Boolean-Functions
[1.0] fn:false() - Returns a boolean with the value of false
Arguments and return type
Type Description
Returns boolean value false
Examples:
Expression Result
false() false
Link do dokumentacji W3C: Boolean-Functions
[1.0] 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
Type Description
string Checks if the context node matches given language
Examples:
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
Type Description
object Converts given object to a number
Examples:
Expression Result
number(true()) 1
number(false()) 0
number("55") 55
number(" 55 ") 55
Link do dokumentacji W3C: Number-Functions
[1.0] fn:number() - Returns the number representation of the context node
Arguments and return type
Type Description
current context node Converts current context node to a number
Examples:
Expression Result
number(true()) 1
number(false()) 0
number("55") 55
number(" 55 ") 55
Link do dokumentacji W3C: Number-Functions
[1.0] fn:sum(node-set) - Returns the sum of all nodes in the node-set
Arguments and return type
Type Description
node-set Summs each node from the set passed through number() function
Link do dokumentacji W3C: Number-Functions
[1.0] fn:floor(number) - Returns the largest integer value not greater than the argument
Arguments and return type
Type Description
number Decimal number to be converted to integer
Examples:
Expression Result
floor(3.1) 3
floor(3.99) 3
Link do dokumentacji W3C: Number-Functions
[1.0] fn:ceiling(number) - Returns the smallest integer value not less than the argument
Arguments and return type
Type Description
number Decimal number to be converted to integer
Examples:
Expression Result
ceiling(3.1) 4
ceiling(3.99) 4
Link do dokumentacji W3C: Number-Functions
[1.0] fn:round(number) - Returns the integer value closest to the argument
Arguments and return type
Type Description
number Decimal number to be converted to integer
Examples:
Expression Result
round(3.1) 3
round(3.6) 4
Link do dokumentacji W3C: Number-Functions