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

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

                     group-by=“position() mod (last() idiv $cols)”>


   

   

      

   

   



See Also


on page 437


on page 455

Collations
on page 459

current-group()
function on page 739

current-grouping-key()
function on page 740

distinct-values()
function on page 749

xsl:function

The

declaration defines a stylesheet function that can be invoked using a function call from any XPath expression.

Changes in 2.0

This element is new in XSLT 2.0.

Format

  name = qname

  as? = sequence-type

  override? = “yes” | “no”>

  


Position


is a top-level declaration, which means that it always appears as a child of the

element.

Attributes

Name
Value
Meaning
name
mandatory
Lexical QName
The name of the function.
as
optional
SequenceType
The type of the value returned when this function is evaluated. A type error is reported if the result does not match this type.
override
optional
yes
or
no
Indicates whether this function overrides any vendor-supplied function of the same name.

The construct
SequenceType
is described in Chapter 11.

Content

Zero or more

elements, followed by a sequence constructor.

Effect

User-written stylesheet functions can be called from XPath expressions in the same way as system-provided functions. The function defined by this

element is added to the static context for every XPath expression in the stylesheet, which means that the function will be invoked when evaluating a function call in an XPath expression that has a matching name and number of arguments (
arity
).

When a stylesheet function is called from an XPath expression, the parameters supplied in the function call are evaluated and bound to the variables defined in the

elements, the sequence constructor contained in the

element is evaluated, and the result of this evaluation is returned as the result of the XPath function call.

The name of the function is given as a lexical QName in the
name
attribute. This name must have a namespace prefix: This is to ensure that the name does not clash with the names of functions in the standard function library. The XSLT 2.0 specification defines several namespaces (all starting with
http://www.w3.org/
) that are reserved—that is, they cannot be used for the names of user-defined functions, variables, or other stylesheet objects.

The stylesheet is allowed to contain two functions of the same name if they have different arity.

It is an error to have two functions in the stylesheet with the same name, arity, and import precedence, unless there is another with higher import precedence. When a function call in an XPath expression is evaluated, the function with highest import precedence is chosen.

The parameters to a function (which are defined using

elements as children to the

element) are mandatory parameters; it is not possible to use the
required
attribute to specify that a parameter is optional, or to specify a default value. The parameters are interpreted positionally: the first argument in the function call binds to the first

element, the second argument binds to the second

, and so on.

The values supplied as arguments to the function in the XPath function call are converted to the types defined by
as
attributes on the corresponding

elements if required, using the standard conversion rules described on page 505. If this conversion fails, a type error is reported. If an

element has no
as
attribute, then any value of any type is acceptable, and no checking or conversion takes place. This is equivalent to specifying
as=“item()*”
.

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

Other books

The Sinner by C.J. Archer
Khan Al-Khalili by Naguib Mahfouz
The Abstinence Teacher by Tom Perrotta
The Perfidious Parrot by Janwillem Van De Wetering
Capital Crimes by Jonathan Kellerman
Suite Dubai (Arriving) by Fox, Callista
Take A Chance On Me by Jennifer Dawson