xsl:call-template
Invokes a named template by name.
<xsl:call-template name="header"/>Unlike xsl:apply-templates, no node selection or pattern matching takes place — the named template runs in the caller’s context (same context node, same context position). Parameters declared by the called template with xsl:param are supplied via xsl:with-param children.
Attributes
| Attribute | Description |
|---|---|
name |
QName of the template to call. Required. |
Examples
Calling a template with parameters:
<xsl:template name="greet">
<xsl:param name="who" select="'World'"/>
<p>Hello <xsl:value-of select="$who"/>!</p>
</xsl:template>
<xsl:call-template name="greet">
<xsl:with-param name="who" select="'Patrick'"/>
</xsl:call-template>Recursive call (named templates are commonly used for recursion):
<xsl:template name="repeat">
<xsl:param name="text"/>
<xsl:param name="n" as="xs:integer"/>
<xsl:if test="$n > 0">
<xsl:value-of select="$text"/>
<xsl:call-template name="repeat">
<xsl:with-param name="text" select="$text"/>
<xsl:with-param name="n" select="$n - 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>