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:

Chapter

Scope

7

Notation used for describing the grammar

Overall structure of the language

Lexical rules (including comments and whitespace handling)

Literals

Variable references

Parenthesized subexpressions

Context item expression «.»

Function calls

Conditional expressions: «if»

8

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

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

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

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

Boolean operators: «and», «or»

9

Path expressions: «/», «//»

Steps and axes

Union, intersect, and except operators

10

Sequence concatenation operator: «,»

Numeric range operator: «to»

Filter expressions «a[b]»

Mapping expressions: «for»

Quantified expressions: «some» and «every»

11

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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.