xsl:param

<xsl:param>
<xsl:param name=”qname” >

</xsl:param>

Or:

<xsl:param name=”qname” select=”expression” />

The xsl:param element is used to declare a local or global parameter and to give that parameter a name and a default value. The default value will be used only if no other value is provided when the template is called.
The default value can be assigned by either the content of the xsl:param element or by the select attribute, but not by both. Each parameter declaration requires a separate xsl:param element.
Global parameters are declared in the top level of the style sheet (as children of the xsl:stylesheet or xsl:transform elements). Local parameters are declared by using the xsl:param element as a child of the xsl:template element.
The actual (explicit) value is set by using xsl:with-param element when the template is applied (invoked) by either the xsl:apply-template or the xsl:call-template elements.
The xsl:variable element can also be used to declare local and global variables. The only real difference between a variable and a parameter is how the value is assigned.
Like all XSLT elements, the xsl: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.
name=”qname”
The mandatory name attribute is the qname of the expression. A qname is a qualified name that is composed of an optional namespace prefix, a colon which is only present if there is a prefix, and a mandatory XML name (for example, xsl:zipcode or zipcode).
Note the following rules concerning when two different parameters can have the same name. (The same rules apply to the name attribute of the xsl:variable element.)
• A name can be repeated if one of the names is in an imported stylesheet and therefore has a lower import precedence. Under these circumstances, the higher import precedence name will always have precedence.
• Two different parameters can have the same name if they can never occur within the same scope. Therefore no ambiguity can occur (which would be an error).
• A local and global parameter can have the same name. However, when the local parameter is in scope, the global parameter cannot be accessed.
If the name attribute is assigned, a select attribute is not assigned, and there is no content, then the named parameter is set to be the empty string.
select=”expression”
The optional select attribute is an expression that defines the parameter. If the select attribute is present, then the xsl:param element cannot contain any content and is self-closing. If an expression is given, the data type must be Boolean, node-set, number or string.
If it is a (literal) string, the string must be enclosed within opening and closing quotes and in turn, that default value must be enclosed again in opening and closing quotes. For example:
<xsl:param name=”car” select=” ‘ Ford ‘ ” />
Or 
<xsl:param name=”car” select=’ ” Ford ” ‘ />
If the name attribute is assigned, a select attribute is not assigned, and there is no content, then the named parameter is set to be the empty string for the default value.
Here is the source code of xslt_call_template.xsl that uses xsl:parm element:
<xsl:stylesheet version="1.0" xmlns:xsl=

"http://www.w3.org/1999/XSL/Transform">

<xsl:template name="main" match="/">

  <html>



  <body>



  <xsl:for-each select="ebiz/employee_details">



  <xsl:sort data-type="number" order="ascending" select="age" />



    <xsl:call-template name="boo">



      <xsl:with-param name="ename" select="fname" />



      <xsl:with-param name="edob" select="age" />



    </xsl:call-template>



  </xsl:for-each>



  </body>



  </html>



</xsl:template>

<xsl:template name="data">

  <xsl:param name="ename" select="'Not Available'" />

  <xsl:param name="edob" select="'Not Available'" />

  <div>

  NAME: <xsl:value-of select="$myname" />



  <br />



  DOB: <xsl:value-of select="$mydob" />



  <hr />



  </div>



</xsl:template>



</xsl:stylesheet>
Scroll to Top