fn:last() as xs:integer
Returns the context size from the dynamic context. (See Section C.2 Dynamic Context Components[XP].) If the context item is undefined, an error is raised [err:FONC0001].
fn:last()
returns the exact context position of the
last item in the current context, so it must count all the items to do
this. It is as much work as fn:count()
.
fn:last()
is therefore best used to find the last item in
a short context sequence. For example, it is useful in a path
expression predicate to find the last child node of a particular
element node in a particular document.
Using fn:last()
in a predicate expression is not an
efficient way to extract a subsequence of large item sequence. Its use
for this purpose is strongly discouraged. It is much more efficient to
use fn:tail()
or fn:subsequence()
instead.
let $x := (10, 20, 30, 40, 50) return $x[last()] => 50, which is the last item in the sequence
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.