xsl:call-template

Invokes a named template.

Category: instruction
Content: xsl:with-param*
Permitted parent elements: any XSLT element whose content model is sequence-constructor; any literal result element

Attributes

name

eqname

Name of the called template, must match the name defined on an xsl:template element.

Saxon availability

Available in XSLT 1.0 and later versions. Available in all Saxon editions. Available for all platforms.

Notes on the Saxon implementation

The use of extension instructions to invoke named templates (as an alternative to using xsl:call-template) is available from Saxon 13 in XSLT 4.0; it is available in Saxon 11 and 12 provided that syntax extensions are enabled.

Details

To supply parameters to the called template, one or more xsl:with-param elements may be included. The values of these parameters are available to the called template. If the xsl:with-param element specifies tunnel="yes", then the parameter is passed transparently through to templates called at any depth, but it can only be referenced by an xsl:param element that also specifies tunnel="yes". If the default value, tunnel="no" is used, then the parameter value is available only in the immediately called template, and only if the xsl:param element specifies tunnel="no" (explicitly or by defaulting the attribute).

The context of the called template (for example the current node and current node list) is the same as that for the calling template; however the variables defined in the calling template are not accessible in the called template.

In XSLT 4.0, if the name of a named template uses a namespace listed in an extension-element-prefixes attribute, then a call on the named template may be written as an extension instruction, as an alternative to using xsl:call-template.

For example, if the template is declared as:

<xsl:template name="x:indent"> <xsl:param name="spaces" as="xs:integer"/> <xsl:value-of select="'&#xa;' || string-join((1 to $spaces)!' ')"/> </xsl:template>

Then it may be invoked by writing:

<x:indent spaces="4"/>

which (assuming the presence of extension-element-prefixes="x") is equivalent to:

<xsl:call-template name="x:indent"> <xsl:with-param name="spaces" select="4"/> </xsl:call-template>

Attributes on the extension instruction are mapped to parameters declared in the named template. The rules for passing parameters are as follows:

  • If the parameter is declared with as="xs:boolean" then the attribute is interpreted as an attribute value template, accepting the values "0", "false", or "no" for false, or "1", "true", or "yes" for true.
  • If the declared type is any other atomic or union type, with no occurrence indicator, then the attribute is interpreted as an attribute value template.
  • In all other cases the value of the attribute is treated as an XPath expression, which must evaluate to a value of the required type (after any conversion, using the function conversion rules).

Note also:

  • Parameters that may be omitted (and defaulted) in an xsl:call-template instruction may similarly be omitted in the extension instruction.
  • The extension instruction must have no children other than xsl:fallback.
  • There is no way to supply tunnel parameters.

Links to W3C specifications

XSLT 3.0 Specification

XSLT 4.0 Specification

See also

xsl:apply-templates

xsl:template

xsl:with-param