Oddly, positional predicates have the opposite meaning when using reverse axes such as ancestor, ancestor-or-self, preceding, or preceding-sibling. These axes, like all axes, return nodes in document order. For example, the expression:
returns the ancestors of the i element in document order, namely the catalog element, followed by the fourth product element, followed by the desc element. However, if you use a positional predicate, as in:
you might expect to get the catalog element, but you will actually get the nearest ancestor, the desc element. The expression:
will give you the catalog element.
Using Multiple Predicates
Multiple predicates can be chained together to filter items based on more than one constraint. For example:
which represents "the second product child that has a dept attribute whose value is ACC," namely the third product element. The order of the predicates is significant. If the previous example is changed to:
it means something different, namely "the second product child, if it has a dept attribute whose value is ACC." This is because the predicate changes the context, and the context node for the second predicate in this case is the second product element.