# saxon:leading()

saxon:leading($input as item()*) ==> item()*

saxon:leading($input as item()*, $test as function()) ==> item()*

This function returns a sequence containing all those nodes from `$input` up to and excluding the first one (in order of the input sequence) for which $test has an effective boolean value of false. A function may be obtained in XQuery 1.1 using any of the new mechanisms for constructing functions; in other environments, it may be obtained by calling saxon:function.

The `$test` argument defaults to the function `fn:data#1`, that is, it atomizes the item.

The `$test` function is evaluated for item in $input in turn, with that item supplied as the argument to the function. The result consists of that leading sequence of items for which the effective boolean value of the function is true.

XQuery 1.1 example:

                saxon:leading(following-sibling::*, function($x){$x/self::para})

XSLT 2.0 example:

                saxon:leading(following-sibling::*, saxon:function('f:is-para', 1)

where `f:is-para` is a user-defined function that tests whether the supplied item is a `<para>` element

This will return the `<para>` elements following the current node, stopping at the first element that is not a `<para>`.

Note: this function is quite different from the EXSLT leading() function, though both fulfil a similar purpose.

Next