XPath1.0 is the language to access node-set in XML Document. XPath2.0 is the language to access Sequence instead.
Every value in XPath 2.0 is a sequence of items. The items may be nodes or atomic values.
xPath = Path Expression + Condition
Everything is Sequence
There is only one data type in XPath2.0 - Sequence
Sequence could be items
items could be node-set or atomic value or both
Items count from 1, actually Xpath count from 1
Operators
Xpath has its own set of operators:
Operators | Effect |
---|---|
+, -, *, div, mod, idiv | Arithmetic on numbers, dates, and durations |
=, !=, <, >, <=, >= | General comparison: compare arbitrary sequences. The result is true if any pair of items, one from each sequence, satisfies the comparison |
eq, ne, lt, gt, le, ge | Value comparison: compare single items |
is | Compare node identity: true if both operands are the same node |
<<, >> | Compare node position, based on document order |
union, intersect, except | Compare sequences of nodes, treating them as sets, returning the set union, intersection, or difference |
and, or | boolean conjunction and disjunction. Negation is achieved using the not() function. |
to | defines an integer range, for example 1 to 10 |
instance of | determines whether a value is an instance of a given type |
cast as | converts a value to a given type |
castable as | tests whether a value is convertible to a given type |
table from wiki
Path Expression
The path expression is the primary use of xpath. Path expression is usually in the format ofaxis::node-test[predicate]
Function library
XPath contains a large number of functions for working with different data types.
Purpose | Example Functions |
---|---|
General string handling | lower-case, upper-case, substring, substring-before, substring-after, translate, starts-with, ends-with, contains, string-length, concat, normalize-space, normalize-unicode |
Regular expressions | matches, replace, tokenize |
Arithmetic | count, sum, avg, min, max, round, floor, ceiling, abs |
Dates and times | adjust-dateTime-to-timezone, current-dateTime, day-from-dateTime, month-from-dateTime, days-from-duration, months-from-duration, etc. |
Properties of nodes | name, node-name, local-name, namespace-uri, base-uri, nilled |
Document handling | doc, doc-available, document-uri, collection, id, idref |
URIs | encode-for-uri, escape-html-uri, iri-to-uri, resolve-uri |
QNames | QName, namespace-uri-from-QName, prefix-from-QName, resolve-QName |
Sequences | insert-before, remove, subsequence, index-of, distinct-values, reverse, unordered, empty, exists |
Type checking | one-or-more, exactly-one, zero-or-one |
This link gives SOME info of the useful XPath expressions
http://saxon.sourceforge.net/saxon7.0/expressions.html