XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition (515 page)

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
8.79Mb size Format: txt, pdf, ePub

There are two kinds of predicate: those that depend on the node's position relative to its siblings, and those that don't. A positional predicate is one whose value is a number, or one that uses the functions
position()
or
last()
; all others are nonpositional. For example, the predicates
[1]
,
[position()!=1]
, and
[last()-1]
are all positional predicates, whereas
[@name = ’Tokyo’]
and
[*]
are nonpositional.

For a nonpositional predicate, its meaning is that the
PatternStep
matches a node only if the
effective boolean value
of the predicate is true. The concept of effective boolean value is defined in XPath, and is summarized in the entry for

on page 353 in Chapter 6. For example, the predicate
[@security = ’secret’]
is true when the node has a
security
attribute whose value is
‘secret’
, so any
PatternStep
that uses this predicate will fail if the node has no
security
attribute or if the
security
attribute has any value other than
‘secret’
.

For a positional predicate, the meaning of the predicate can be deduced from the formal rules given at the start of this chapter. However, it is easier to understand their meaning by using informal rules. A numeric predicate such as
[1]
or
[last()-1]
is equivalent to the boolean predicate
[position() = 1]
or
[position() = last()-1]
. So to evaluate a positional predicate, we need to know what
position()
and
last()
are.

Other books

Tell Me I'm Dreamin' by Eboni Snoe
Odds on Oliver by Constance C. Greene
Dust & Decay by Jonathan Maberry
My Sweet Valentine by Sanders, Jill
Wanted by Kym Brunner