11.6 Passing Parameters to Templates
Passing Parameters to Templates
<
with-param
name=
qname
select=
expression
>
<-- Content: -->
<
/with-param>
Parameters are passed to templates using the
xsl:with-param element. The required name
attribute specifies the name of the parameter (the variable the value
of whose binding is to be replaced). The value of the
name attribute is a QName, which is expanded as described
in [Qualified Names]. xsl:with-param is allowed
within both xsl:call-template and
xsl:apply-templates. The value of the parameter is
specified in the same way as for xsl:variable and
xsl:param. The current node and current node list used
for computing the value specified by xsl:with-param
element is the same as that used for the
xsl:apply-templates or xsl:call-template
element within which it occurs. It is not an error to pass a
parameter x to a template that does not have an
xsl:param element for x; the parameter is
simply ignored.
This example defines a named template for a
numbered-block with an argument to control the format of
the number.
<xsl:template name="numbered-block">
<xsl:param name="format">1. </xsl:param>
<fo:block>
<xsl:number format="{$format}"/>
<xsl:apply-templates/>
</fo:block>
</xsl:template>
<xsl:template match="ol//ol/li">
<xsl:call-template name="numbered-block">
<xsl:with-param name="format">a. </xsl:with-param>
</xsl:call-template>
</xsl:template>
|