Parameters
Parameters can be passed to either named or unnamed templates using the
<xsl:with-param>element. Inside the template, parameters must be declared and can then be referenced by prefixing their name with the dollar sign ($).The following template matches on
/, the root of the XML document. It then generates an element named<outside>, which is added to the output document, and instructs the JUNOS management process (mgd) to recursively apply templates to theconfiguration/systemsubtree. A parameter calledhostis passed to any templates that are processed.<xsl:template match="/"><outside><xsl:apply-templates select="configuration/system"><xsl:with-param name="host" select="configuration/system/host-name"/></xsl:apply-templates></outside></xsl:template>The following template matches the
<system>element, which is the top of the subtree selected in the previous example. Thehostparameter is declared with no default value. Aninsideelement is generated, which contains the value of thehostparameter.<xsl:template match="system"><xsl:param name="host"/><inside><xsl:value-of select="$host"/></inside></xsl:template>To declare a default value for a parameter, include the
selectattribute and specify the desired default. If the template is invoked without the parameter, the XPath expression is evaluated and the results are assigned to the parameter.The second template declares two parameters:
$dot, which defaults to the current node, and$changed, which defaults to thechangedattribute of the node$dot.<xsl:template name="report-changed"><xsl:param name="dot" select="."/><xsl:param name="changed" select="$dot/@changed"/><!--...--></xsl:template>The next stanza calls the
<report-changed>template and defines a source for thechangedattribute other than the default source selected in the<report-changed>template.<xsl:template match="system"><xsl:call-template name="report-changed"><xsl:with-param name="changed" select="../@changed"/></xsl:call-template></xsl:template>Likewise, the template call can include the
dotparameter and define a source other than the default current node, as shown here:<xsl:template match="system"><xsl:call-template name="report-changed"><xsl:with-param name="dot" select="../../></xsl:call-template></xsl:template>