Predicate filters

Location paths are quite indiscriminate. For example, the path 'book/chapter/para' selects all of the paragraphs in all of the chapters. But there is often a need to target a more selective set of elements, and possibly a single element instance.

A predicate filter is used to qualify any step in the path. The list of matches at each step is reduced by asking questions about the nodes in this list. Square brackets, '[' and ']', are used to hold the predicate:

para[....]
				

The predicate filter holds one or more test expressions. The results of the test (or tests) is a single boolean value, and the selection only succeeds when the value is true.

Position tests

The ' position()' function returns the sequential location of the element ...

Get XML Companion, The, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.