XML technologies / XSLT / Introduction to XSLT 2.0 / XSLT and XPath – round three / Variables and parameters / Tunneling through default rules
(Excerpt from “XSLT 2.0 & XPath 2.0” by Frank Bongers, chapter 3.)
With named templates, tunneling variables is straightforward because the stylesheet author fully controls which template is called, when, from where and with which parameters. This is less predictable with xsl:apply-templates and parameters passed at the same time. This calling method adapts flexibly to the source document’s structure. A call with parameters may therefore fail to reach a template rule capable of accepting them.
Chapter one already mentioned the XSLT processor and its implemented default rules for different node types. For elements and the document node, the default rule is:
<xsl:template match="*|/">
<xsl:apply-templates/>
</xsl:template>
No parameter passing is shown, but this is not an actual template rule. Default rules’ parameter behavior deserves attention: XSLT 1.0 and 2.0 differ here.
In XSLT 1.0, default rules do not forward parameter values.
A parameter passed to a default rule is discarded, even if that rule is only an intermediate step toward the template expecting the parameter.
In XSLT 2.0, parameters tunnel through default rules.
A welcome, intuitive improvement in XSLT 2.0 is automatic parameter forwarding by the default template. Parameters supplied to it reappear at its output alongside the sequence it constructs, becoming available to the template rules now called. If another default rule is activated, the process repeats.
To avoid misunderstanding, no tunnel attribute is required on the passed parameter. All parameters tunnel through default rules independently of this attribute.
Copyright © Galileo Press, Bonn 2008
You may print the online version for your private use.
Otherwise, this chapter from “XSLT 2.0 & XPath 2.0 ― Das umfassende Handbuch” is subject to the same conditions as the bound edition. The work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
Galileo Press, Rheinwerkallee 4, 53227 Bonn