Quick References
      ADO
      ASP
      CSS2
      HTML
      JavaScript
      Jet SQL
      VBScript
      WML
      WMLScript
      WSH
      XHTML
      XML DOM
      XSLT

Features
      Knowledge Base
      Tutorials

Partners
     ZVON.ORG
     XML
     Planet Source Code
     VisualBuilder
     Web Design
     Your HTML Source
     XML/XSLT Forums
     ASPAlliance
     Scripts
     
     Programmers Heaven
     Tek-Tips Forums
     Developer Fusion
     Code Project


   







ELEMENT:  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.
 
We use the DevGuru Staff List XML file for our example with the following header:
<?xml-stylesheet type="text/xsl" href="xslt_example_param.xsl"?>
and we name it: xslt_example_param.xml
 
Code for xslt_example_param.xsl:
 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

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

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

</xsl:stylesheet>

 
Output:
 
Click to view output in separate window - requires Internet Explorer

 

 


Copyright 1999-2005 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information