Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
Usage
When
last()
is used within a predicate in a filter expression, the focus refers to the sequence of items being filtered. If the filter is used within a step of a path expression, then the context size is the number of nodes selected by the current step of the expression, after applying any previous filters. For example, suppose the source document is as follows:
Then:
An easy mistake is to think that
last()
returns a boolean value. You can use
last()
in a predicate to match the last node, for example
para[last()]
. This is a shorthand for the predicate
[position()=last()]
, because in a predicate, a numeric value X is equivalent to a test for the condition
position()=X
. However, this doesn't extend to other contexts, for example if you write:
if (last()) then ...
then the numeric value of the
last()
function is simply converted to a boolean as if the
boolean()
function were used. The result will always be true, because
last()
can never be zero.