Chapter 7. XPath Fundamentals

This chapter defines some fundamental features of the XPath language. The first half of the chapter describes the basic syntactic and lexical conventions of the language, and the second half describes the important notion of context: this establishes the way in which XPath expressions interact with the environment in which they are used, which for our purposes primarily means the containing XSLT stylesheet.

The complete grammar of the language is summarized in Appendix A, and for convenience I have split the constructs of the language across five chapters, as follows:




Notation used for describing the grammar

Overall structure of the language

Lexical rules (including comments and whitespace handling)


Variable references

Parenthesized subexpressions

Context item expression «.»

Function calls

Conditional expressions: «if»


Arithmetic operators: «+», «−», ...

Value comparison operators: «eq», «lt», ...

General comparison operators: «=», «<», ...

Node identity and ordering operators: «is», «<<», «>>»

Boolean operators: «and», «or»


Path expressions: «/», «//»

Steps and axes

Union, intersect, and except operators


Sequence concatenation operator: «,»

Numeric range operator: «to»

Filter expressions «a[b]»

Mapping expressions: «for»

Quantified expressions: «some» and «every»


SequenceType production

«instance of»

«castable as»

«cast as»

«treat as»

As with other programming languages, the syntax is defined in a set of production rules. Each ...

Get XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.