XSLT » Elements » xsl:with-param




The xsl:with-param element is used to set the explicit value of a named parameter when using the xsl:apply-templates and the xsl:call-template elements.

The concept is that the xsl:param element is used to declare a local or global parameter by assigning a name and a default value. The xsl:with-param element is used to set the actual (explicit) value which will be used in place of the default value. The name cited by the xsl:with-param element must match a name in an xsl:param element. If there is no such match, the xsl:with-param element is simply ignored, but it is not treated as an error.

Like all XSLT elements, the xsl:with-param element must be closed (well-formed). If the select attribute is present, then this element is self-closing. If the select attribute is not present, then this element is not self-closing and the separate closing element is mandatory.



<xsl:template name="hoo" match="/">
  <xsl:for-each select="devguru_staff/programmer">
    <xsl:call-template name="boo">
      <xsl:with-paramname="myname" select="name" />
      <xsl:with-paramname="mydob" select="dob" />

<xsl:template name="boo">
  <xsl:param name="myname" select="'NotAvailable'" />
  <xsl:param name="mydob" select="'Not Available'"/>
  NAME: <xsl:value-of select="$myname" />
  <br />
  DOB: <xsl:value-of select="$mydob" />
  <hr />

NAME: Bugs Bunny
DOB: 03/21/1970
NAME: Daisy Duck
DOB: 08/09/1949
NAME: Minnie Mouse
DOB: 04/13/1977
NAME: Pluto
DOB: 07/04/1979
NAME: Porky Pig
DOB: 11/30/1956
NAME: Road Runner
DOB: 01/19/1953

This is the code for xslt_example_withparam.xsl.

We use the DevGuru Staff List XML file for our example with the following header:
<?xml-stylesheet type="text/xsl" href="xslt_example_withparam.xsl"?>

Language(s): XSLT

See Also: