<html>
<head>
<title>&lt;xsl:param&gt;</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div id="Description">
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
<tr>
<td valign="top" class="NAME">&lt;xsl:param&gt;</td>
<td valign="top" class="COMPATIBILITY">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
</tr>
<tr>
<td valign="top" colspan="2" class="description">
Defines the name and value of a parameter to be used by a template. This element can appear as a top-level element or inside the <span class="LITERAL">&lt;xsl:template&gt;</span> element. If the <span class="LITERAL">&lt;xsl:param&gt;</span> appears as a top-level element, it is a global parameter, visible to all areas of the stylesheet. The value of the parameter can be defined in one of two ways:  specified in the <span class="LITERAL">select</span> attribute, or defined in an XSLT template inside the <span class="LITERAL">&lt;xsl:param&gt;</span> element itself. </td></tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Category</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>Instruction</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Required Attributes</td>
</tr>
<tr>
<td colspan="2" class="description">
<dl>
<dt>
name
</dt>
<dd>
Defines the name of this parameter.
<P></p>
</dl>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Optional Attributes</td>
</tr>
<tr>
<td colspan="2" class="description">
<dl>
<dt>
select
</dt>
<dd>
Contains an XPath expression that defines the value of this parameter.
<P></p>
</dl>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Content</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>If the <span class="LITERAL">select</span> attribute is used, <span class="LITERAL">&lt;xsl:param&gt;</span> should be empty. Otherwise, it contains an XSLT template.</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Appears in</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>

<span class="LITERAL">&lt;xsl:stylesheet&gt;</span> and
<span class="LITERAL">&lt;xsl:template&gt;</span>. If an
<span class="LITERAL">&lt;xsl:param&gt;</span> appears as a child of
<span class="LITERAL">&lt;xsl:stylesheet&gt;</span>, then it is a global
parameter visible throughout the stylesheet. XSLT doesn't define the
way global parameters are passed to the XSLT processor, so check the
documentation for your processor to see how this is done. (See <link linkend="xslt-CHP-4-SECT-4.3">Section 4.4.3</link> in <link linkend="xslt-CHP-4">Chapter 4</link>
for an overview of how to pass parameters to the most popular XSLT
processors.)  </p>

</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Defined in</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>XSLT section 11, Variables and Parameters. </p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Example</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>Here is a stylesheet that defines several <span class="LITERAL">&lt;xsl:param&gt;</span> elements, both global and local. Notice that one of the parameters is a node-set; parameters can be of any XPath or XSLT datatype: </p>
<span class="PROGRAMLISTING"><pre>
&lt;?xml version="1.0"?&gt;
&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;

  &lt;xsl:output method="text"/&gt;

  &lt;xsl:variable name="newline"&gt;
&lt;xsl:text&gt;
&lt;/xsl:text&gt;
  &lt;/xsl:variable&gt;

<!--<?troff .Nd 10?>-->
  &lt;xsl:param name="favoriteNumber" select="23"/&gt;
  &lt;xsl:param name="favoriteColor"/&gt;

  &lt;xsl:template match="/"&gt;
    &lt;xsl:value-of select="$newline"/&gt;
    &lt;xsl:value-of select="list/title"/&gt;
    &lt;xsl:value-of select="$newline"/&gt;
    &lt;xsl:variable name="listitems" select="list/listitem"/&gt;
    &lt;xsl:call-template name="processListitems"&gt;
      &lt;xsl:with-param name="items" select="$listitems"/&gt;
      &lt;xsl:with-param name="color" select="'yellow'"/&gt;
      &lt;xsl:with-param name="number" select="$favoriteNumber"/&gt;
    &lt;/xsl:call-template&gt;
  &lt;/xsl:template&gt;

  &lt;xsl:template name="processListitems"&gt;
    &lt;xsl:param name="items"/&gt;
    &lt;xsl:param name="color" select="'blue'"/&gt;

    &lt;xsl:for-each select="$items"&gt;
      &lt;xsl:value-of select="position()"/&gt;
      &lt;xsl:text&gt;.  &lt;/xsl:text&gt;
      &lt;xsl:value-of select="."/&gt;
      &lt;xsl:value-of select="$newline"/&gt;
    &lt;/xsl:for-each&gt;

    &lt;xsl:value-of select="$newline"/&gt;
    
    &lt;xsl:text&gt;Your favorite color is &lt;/xsl:text&gt;
    &lt;xsl:value-of select="$favoriteColor"/&gt;
    &lt;xsl:text&gt;.&lt;/xsl:text&gt;
    &lt;xsl:value-of select="$newline"/&gt;
    &lt;xsl:text&gt;The color passed to this template is &lt;/xsl:text&gt;
    &lt;xsl:value-of select="$color"/&gt;
    &lt;xsl:text&gt;.&lt;/xsl:text&gt;
    &lt;xsl:value-of select="$newline"/&gt;
  &lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;</pre></span>
<p>We'll use this stylesheet to transform the following document:</p>
<span class="PROGRAMLISTING"><pre>
&lt;?xml version="1.0"?&gt;
&lt;list&gt;
  &lt;title&gt;A few of my favorite albums&lt;/title&gt;
  &lt;listitem&gt;A Love Supreme&lt;/listitem&gt;
  &lt;listitem&gt;Beat Crazy&lt;/listitem&gt;
  &lt;listitem&gt;Here Come the Warm Jets&lt;/listitem&gt;
  &lt;listitem&gt;Kind of Blue&lt;/listitem&gt;
  &lt;listitem&gt;London Calling&lt;/listitem&gt;
  &lt;listitem&gt;Remain in Light&lt;/listitem&gt;
  &lt;listitem&gt;The Joshua Tree&lt;/listitem&gt;
  &lt;listitem&gt;The Indestructible Beat of Soweto&lt;/listitem&gt;
&lt;/list&gt;</pre></span>
<p>Here are the results:</p>
<span class="PROGRAMLISTING"><pre>

A few of my favorite albums
1.  A Love Supreme
2.  Beat Crazy
3.  Here Come the Warm Jets
4.  Kind of Blue
5.  London Calling
6.  Remain in Light
7.  The Joshua Tree
8.  The Indestructible Beat of Soweto

Your favorite color is purple.
The color passed to this template is yellow.</pre></span>
<p>To generate these results, we passed the value <span class="LITERAL">purple</span> to the XSLT processor. With Xalan, the value is passed like this:</p>
<span class="PROGRAMLISTING"><pre>
java org.apache.xalan.xslt.Process -in test4.xml -xsl param.xsl 
  -param favoriteColor purple</pre></span>

<p>(The command should be entered on a single line.)  See <link linkend="xslt-CHP-4-SECT-4.3">Section 4.4.3</link> in <link linkend="xslt-CHP-4">Chapter 4</link> for a more
complete discussion of global parameters and how they can be set for
various XSLT processors. </p>

</td>
</tr>
</table>
</div>
</body>
</html>