Specifying Multiple Predicates in a Single XPath Step

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - XPath Developer's Guide

Specifying Multiple Predicates in a Single XPath Step

An XPath location step will usually include only a single predicate. Under certain circumstances, however, it may be necessary to further filter the node-set returned by the first predicate, within a single XPath location step.

For example:

chapter[@author="Niikkonen, Donna"][1]

locates the first <chapter> child of the context node for which the <chapter>'s author attribute has the value "Niikkonen, Donna" (i.e., the first chapter written by Donna Niikkonen).

When using multiple predicates, you must be careful to place them in the right order. The above does not necessarily produce the same result as:

chapter[1][@author="Niikkonen, Donna"]

which always selects the first chapter, then tests whether that was or was not written by Donna Niikkonen and selects or rejects it accordingly.