Named Templates Overview for SLAX
The named template definition consists of the template keyword, the template name, a set of parameters, and a braces-delimited block of code. Parameter declarations can be inline and consist of the parameter name, and an optional equal sign (=) and value expression. You can declare additional parameters inside the block using the param statement.
You invoke named templates using the call statement, which consists of the call keyword followed by a set of parameter bindings. These bindings are a comma-separated list of parameter names, optionally followed by an equal sign (=) and a value expression. If you do not provide a value, the current value of the variable or parameter is passed. You can supply additional template parameters inside the block using the with statement.
match configuration {
var $name-servers = name-servers/name;
call temp:ting();
call temp:ting($name-servers, $size = count($name-servers));
call temp:ting() {
with $name-servers;
with $size = count($name-servers);
}
template temp:ting($name-servers, $size = 0) {
<output> "template called with size " _ $size;
}
}The XSLT equivalent is:
<xsl:template match="configuration">
<xsl:variable name="name-servers" select="name-servers/name"/>
<xsl:call-template name="temp:ting"/>
<xsl:call-template name="temp:ting">
<xsl:with-param name="name-servers" select="$name-servers"/>
<xsl:with-param name="size" select="count($name-servers)"/>
</xsl:call-template>
<xsl:call-template name="temp:ting">
<xsl:with-param name="name-servers" select="$name-servers"/>
<xsl:with-param name="size" select="count($name-servers)"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="temp:ting">
<xsl:param name="name-servers"/>
<xsl:param name="size" select="0"/>
<output>
<xsl:value-of select="concat('template called with size ', $size)"/>
</output>
</xsl:template>
Hide Navigation Pane
Show Navigation Pane
Download
SHA1