Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
Expression | Description |
$x + ($y * 2) | Returns the result of multiplying $y by two and adding the value of $x . |
//book | //magazine | Returns a sequence of nodes containing all of the //(book|magazine) .) |
substring-before(author, ‘ ’) | Finds the value of the first |
chapter and verse | Returns the xs:boolean value true if the context node has a child |
93.7 | Returns the decimal value 93.7 . |
sum(//product/(price * qty)) | Returns the result of multiplying the values of |
avg((//product)[position() le 5])/price) | Returns the average |
Lexical Constructs
An XPath 2.0 expression is written as a sequence of Unicode characters. Every character that's available in XML 1.0 can be used in an XPath expression, and possibly characters that are available in XML 1.1 as well, though that's been left up to the implementation to decide.
XPath itself isn't concerned with how these characters are encoded. XPath expressions will often be embedded in other languages such as XSLT, or they may be constructed as runtime character strings using a programming language such as Java or JavaScript. Any escape conventions local to the host language will be applied before the XPath parser gets to see the expression, and the syntax described in the XPath Recommendation (and in the XPath chapters of this book) is the syntax after such escapes have been expanded. For example: