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

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

An

element will be used to process a node only if the node matches the pattern defined in the
match
attribute of the

element.

If there is more than one

element that matches a selected node, one of them is selected based on its
import precedence
and
priority
, as detailed under

on page 483.

If there is no

element that matches a selected node, a built-in template rule is used. The action of the built-in template rule depends on the kind of node, as follows:

Node Kind
Action of Built-In Template Rule
Document node
Element node
Call
apply-templates
to process each child of the selected node, using the mode specified on the call to

. This is done as if the contents of the template were

. The parameters passed in the call of

are passed transparently through the built-in template to the template rules for the child elements.
Text node
Attribute node
Copy the string value of the node to the result sequence, as a text node. This is done as if the contents of the template were
select=“string(.)”>
.
Comment node
Processing Instruction
Namespace node
No action.

For the document node and for element nodes, the built-in template rule processes the children of the selected node in document order, matching each one against the available template rules as if the template body contained an explicit

element with no
select
attribute. Unlike the situation with explicit template rules, the mode is sticky; it is carried through automatically to the template rules that are called. So if you execute
mode=“m”/>
for an element that has no matching template rule, the built-in template rule will execute
mode=“m”/>
for each of its children. This process can, of course, recurse to process the grandchildren, and so on.

In XSLT 2.0, the built-in template rules not only pass on the mode they were called with, they also pass on their parameters. This is a change from XSLT 1.0.

Parameters

If there are any

elements present as children of the

element, they define parameters that are made available to the called template rules. The same parameters are made available to each template rule that is evaluated, even though different template rules may be invoked to process different nodes in the list.

Each

element is evaluated in the same way as an

element, as described on page 500. Specifically:

  • If it has a
    select
    attribute, this is evaluated as an XPath expression.
  • If there is no
    select
    attribute and the

    element is empty, the value is a zero-length string, unless there is an
    as
    attribute, in which case it is an empty sequence.
  • Otherwise, the value of the parameter is determined by evaluating the sequence constructor contained within the

    element. If there is an
    as
    attribute, this sequence forms the value of the parameter; if not, a temporary document is constructed from this sequence, and the document node is passed as the value of the parameter. Tree-valued variables are described under

    on page 500.

If the

element has an
as
attribute, then the value of the parameter must match the type specified in this attribute, and if necessary the value is converted to this type using the standard conversion rules described on page 505. In theory it is possible for a parameter value to be converted twice, first to the type defined on the

element and then to the type defined on the corresponding

element.

It is not defined whether the parameter is evaluated once only or whether it is evaluated repeatedly, once for each node in the sequence. If the value isn't needed (for example, because the
select
expression selected no nodes or because none of the nodes matches a template that uses this parameter) then it isn't defined whether the parameter is evaluated at all. Usually this doesn't matter, because evaluating the parameter repeatedly will have exactly the same effect each time. But it's something to watch out for if the parameter is evaluated by calling an extension function that has a side effect, such as reading the next record from a database.

If the name of a child

element matches the name of an

element in the selected template rule, then the value of the

element is assigned to the relevant

variable name.

If the

element specifies
tunnel=“yes”
, then the parameter is available not only to the immediately called templates, but to templates at any depth in the call stack, provided they declare the parameter with

and a matching name. Tunnel parameters are described more fully on page 429.

If there is a child

element that does not match the name of any

element in the selected template rule, then it is ignored. This is not treated as an error.

If there is an

element in the selected template rule with no matching

element in the

element, then the parameter is given a default value: see

on page 425 for details. This is an error only if the

element specifies
required=“yes”
.

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

Other books

Horizontal Woman by Malzberg, Barry
Dead Souls by Ian Rankin
Her Master's Command by Sabrina Armstrong
The Counting-Downers by A. J. Compton
The Lovegrove Hermit by Rosemary Craddock
Gypsy Lady by Shirlee Busbee
Janaya by Shelley Munro