XPATH Quick Reference#

See also http://www.zvon.org/xxl/XPathTutorial/General/examples.html

Basic syntax#

nodename Selects all child nodes of the node
/ Selects from the root node
// Selects nodes descending from the current node no matter where they are
. Selects the current node
.. Selects the parent of the current node
@ Selects attributes
* Matches any element node
@* Matches any attribute node
node() Matches any node of any kind
[ predicate ] Predicates are used to find a specific node or a node that contains a specific value.
path | path Use the | operator to match several paths

Node Set Functions#

last() Returns a number equal to the context size from the expression evaluation context.
position() Returns a number equal to the context position from the expression evaluation context.
count(node-set) Returns the number of nodes in the argument node-set.

String functions#

concat(string, string, string*)
starts-with(string, string)
contains(string, string)
substring-before(string, string)
substring-after(string, string)
substring(string, number, number?)
string-length(string?)
normalize-space(string?)
translate(string, match-char-set, replacement-char-set)

Number function#

sum(node-set)
floor(number)
ceiling(number)
round(number)

Some examples:#

/bookstore/book[1] Selects the first book element that is the child of the bookstore element
/bookstore/book[last()] Selects the last book element that is the child of the bookstore element
/bookstore/book[last()-1] Selects the last but one book element that is the child of the bookstore element
/bookstore/book[position()<3] Selects the first two book elements that are children of the bookstore element
//title[@lang] Selects all the title elements that have an attribute named lang
//title[@lang='eng'] Selects all the title elements that have an attribute named lang with a value of 'eng'
/bookstore/book[price>35.00] Selects all the book elements of the bookstore element that have a price element with a value greater than 35.00
/bookstore/book[price>35.00]/title Selects all the title elements of the book elements of the bookstore element that have a price element with a value greater than 35.00
//book/title | //book/price Selects all the title AND price elements of all book elements
//title | //price Selects all the title AND price elements in the document
/bookstore/book/title | //price Selects all the title elements of the book element of the bookstore element AND all the price elements in the document

Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-1) was last changed on 23-May-2006 22:21 by Dirk Frederickx