Quackit Logo
HTML
CSS
Scripting
Database
Hosting
Design
XML
IMCreator - Free Website Builder

XPath Predicate

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!):

Code

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":

Code

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:

  • Node Set
  • Boolean
  • Number
  • String
  • Result tree fragment

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

Enjoy this page?

  1. Link to this page (copy/paste into your own website or blog):
  2. Link to Quackit using one of these banner ads.

Thanks for supporting Quackit!