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

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

On entry to the function, the context item, position, and size are undefined. It is therefore an error to use the expression
.
, or any relative path expression, or the functions
position()
and
last()
. Even a path expression beginning with
/
is not allowed, because such path expressions select from the root of the tree containing the context node. This means that all information needed by the function must either be passed explicitly as a parameter or be available in a global variable. Path expressions such as
$par/a/b/c
can be used to navigate from nodes that are supplied as parameters to other nodes in the same tree.

Other values in the dynamic context, such as the current template, current mode, current group, and current grouping key, are also either undefined or empty on entry to a stylesheet function.

The result of the function is obtained by evaluating the sequence constructor. This result may be a sequence consisting of nodes (either newly constructed nodes or references to existing nodes) or atomic values or both. If there is an
as
attribute on the

element, then the result of evaluating the sequence constructor is converted, if necessary, to the specified type. Once again, the standard conversion rules defined on page 505 are used. A type error is reported if this conversion fails. If the

element has no
as
attribute, then a result of any type may be returned, and no checking or conversion takes place.

The override Attribute

The
override
attribute controls what happens if a user-written function and a vendor-supplied function have the same name.

  • override=“yes”
    means that the user-written function wins. This is the default. This value maximizes portability: the same implementation of the function will be used on all XSLT processors.
  • override=“no”
    means that the vendor-supplied function wins. This setting is useful when the stylesheet function has been written as a fallback implementation of the function, for use in environments where no vendor-supplied implementation exists. For example, at
    http://www.exslt.org/
    there is a definition of a mathematical function library, including the function
    math:sqrt()
    , which evaluates the square root of its argument. This function is likely to be available with a number of XSLT processors, but not all. By supplying an XSLT implementation of this function, and specifying
    override=“no”
    , the stylesheet author can ensure that a call to
    math:sqrt()
    will execute on any XSLT processor, and will take advantage of the vendor's native implementation when available.

Other books

Nadie es más que nadie by Miguel Ángel Revilla
Secrets & Surprises by Ann Beattie
Thin Air by George Simpson, Neal Burger
Assisted Living: A Novel by Nikanor Teratologen
The Clone Apocalypse by Kent, Steven L.
Christmas With Mr. Jeffers by Julie Kavanagh
Mob Wedding Mayhem by Ally Gray
Just Between Us by Hayley Oakes
Bloodkin by Amelia Atwater-Rhodes
Other Earths by edited by Nick Gevers, Jay Lake