How XPath 1.0 comparisons and negatiations work, since I always forget

Where $node-set is bound to a node-set having two or more nodes, and $string bound to a string, evaluating an expression will return a boolean true, if:

$node-set = $string
there is a node in $node-set that is equal to $string
$node-set != $string
there is a node in $node-set that is not equal to $string
not($node-set = $string)
there is not a node in $node-set that is equal to $string
not($node-set != $string)
there is not a node in $node-set that is not equal to $string

How parenthesis change expression evaluation:

descendant::*[1] or (descendant::*)[1]
Closest descendant element
descendant::*[last()] or (descendant::*)[last()]
Most distant descendant element
ancestor::*[1] or (ancestor::*)[last()]
Closest ancestor element
ancestor::*[last()] or (ancestor::*)[1]
Most distant foo ancestor element

Rewrites of some expressions I've seen in stylesheets to eliminate the last() function.

Table 1. Rewrites of reverse axis expressions with last() predicates.
(ancestor::*/@role)[last()] = 'child'ancestor::*[@role][1]/@role = 'child'
(ancestor::*/@role)[last()] = 'child' or
(ancestor::*/@role)[last()] = 'descendant'
ancestor::*[@role][1]/@role[. = 'child' or
                            . = 'descendant']