SAXONICA

Saxon Documentation
Full Contents
About Saxon
Changes in this Release
Notices
Using XSLT 2.0
Using XQuery
Handling Source Documents
XML Schema Processing
XPath API for Java
Saxon on .NET
Extensibility
Saxon Extensions
Sample Saxon Applications
The Saxon SQL Extension
XSLT Elements
XPath 2.0 Expression Syntax
| Introduction
| Constants
| Variable References
| Function Calls
| Axis steps
| Parentheses and operator precedence
» | Filter expressions
| Path expressions
| Cast as, Treat as
| Set difference and intersection
| Union
| Arithmetic expressions
| Range expressions
| Comparisons
| Instance of and Castable as
| Conditional Expressions
| Quantified Expressions
| For Expressions
| Boolean expressions: AND and OR
| Sequence expressions
Function Library
Standards Conformance

# Filter expressions

The notation `E[P]` is used to select items from the sequence obtained by evaluating `E`. If the predicate `P` is numeric, the predicate selects an item if its position (counting from 1) is equal to `P`; otherwise, the effective boolean value of `P` determines whether an item is selected or not. The effective boolean value of a sequence is false if the sequence is empty, or if it contains a single item that is one of: the boolean value false, the zero-length string, or a numeric zero or NaN value. If the first item of the sequence is a node, or if the sequence is a singleton boolean, number or string other than those listed above, the effective boolean value is true. In other cases (for example, if the sequence contains two booleans or a date), evaluating the effective boolean value causes an error.

In XPath 2.0, `E` may be any sequence, it is not restricted to a node sequence. Within the predicate, the expression `.` (dot) refers to the context item, that is, the item currently being tested. The XPath 1.0 concept of context node has thus been generalized, for example `.` can refer to a string or a number.

Generally the order of items in the result preserves the order of items in `E`. As a special case, however, if `E` is a step using a reverse axis (e.g. preceding-sibling), the position of nodes for the purpose of evaluating the predicate is in reverse document order, but the result of the filter expression is in forwards document order.

Next