XPath Predicate

This article provides an overview of XPath predicates.

In our XPath expressions, we've learned that a location path consists of an axis, a node test, and optionally, one or more: predicates. We've covered axes and node tests. Now let's look at predicates.

Predicate Syntax

Here's where an XPath goes within our expression (in case you've forgotten!):

Predicate Example

In the following example, we're using the XSL value-of element to select a node. The select attribute of this element specifies an XPath expression. In the expression, [@status = 'active'] is the predicate. In this case, the predicate is being used to narrow the selection down to only those records that have their status attribute set to active:

Predicate Expression Types

An XPath predicate allows you to write very specific rules about the nodes you'd like to select when constructing your expressions. There are different types of expressions that you can use in your predicates. Here are the types of expressions you can use with your predicates:

Let's have a closer look at these expression types.