<xsl:param>  
テンプレートで使用するパラメータの名前と値を定義します。この要素はトップレベル要素として、または <xsl:template> 要素内で使用できます。<xsl:param> をトップレベル要素として使用すると、グローバルパラメータとなり、スタイルシートのどこからでも参照できるようになります。パラメータの値を定義するには、select 属性で指定するか、または <xsl:param> 要素内で XSLT テンプレートを定義する 2 つの方法があります。
 
カテゴリ

命令

 
必須の属性
name
このパラメータの名前を定義します。

 
省略可能な属性
select
このパラメータの値を定義する XPath 式を含みます。

 
コンテンツ

select 属性を使用する場合は、<xsl:param> が空である必要があります。空にしない場合、XSLT テンプレートが含まれます。

 
指定先

<xsl:stylesheet><xsl:template><xsl:param><xsl:stylesheet> の子として指定されると、スタイルシート全体で参照可能なグローバルパラメータとなります。XSLT では、グローバルパラメータを XSLT プロセッサに渡す方法が定義されません。この処理がどのように行われるのかを確認するには、使用している XSLT プロセッサのマニュアルを参照してください。主要な XSLT プロセッサにパラメータを渡す方法の概要については、第 4 章 4.4.3 節を参照してください。

 
定義先

XSLT 11 節「変数とパラメータ」

 

複数の <xsl:param> 要素 (グローバルとローカルの両方) を定義するスタイルシートを以下に示します。ノードセットのパラメータが 1 つ含まれます。パラメータのデータタイプは XPath または XSLT のいずれかです。

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="text"/>

  <xsl:variable name="newline">
<xsl:text>
</xsl:text>
  </xsl:variable>


  <xsl:param name="favoriteNumber" select="23"/>
  <xsl:param name="favoriteColor"/>

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

  <xsl:template name="processListitems">
    <xsl:param name="items"/>
    <xsl:param name="color" select="'blue'"/>

    <xsl:for-each select="$items">
      <xsl:value-of select="position()"/>
      <xsl:text>.  </xsl:text>
      <xsl:value-of select="."/>
      <xsl:value-of select="$newline"/>
    </xsl:for-each>

    <xsl:value-of select="$newline"/>
    
    <xsl:text>Your favorite color is </xsl:text>
    <xsl:value-of select="$favoriteColor"/>
    <xsl:text>.</xsl:text>
    <xsl:value-of select="$newline"/>
    <xsl:text>The color passed to this template is </xsl:text>
    <xsl:value-of select="$color"/>
    <xsl:text>.</xsl:text>
    <xsl:value-of select="$newline"/>
  </xsl:template>

</xsl:stylesheet>

このスタイルシートを使用して次のドキュメントを変換します。

<?xml version="1.0"?>
<list>
  <title>A few of my favorite albums</title>
  <listitem>A Love Supreme</listitem>
  <listitem>Beat Crazy</listitem>
  <listitem>Here Come the Warm Jets</listitem>
  <listitem>Kind of Blue</listitem>
  <listitem>London Calling</listitem>
  <listitem>Remain in Light</listitem>
  <listitem>The Joshua Tree</listitem>
  <listitem>The Indestructible Beat of Soweto</listitem>
</list>

結果は次のとおりです。


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.

これらの結果を生成するために、値 purple を XSLT プロセッサに渡します。Xalan では、値は次のように渡されます。

java org.apache.xalan.xslt.Process -in test4.xml -xsl param.xsl 
  -param favoriteColor purple

コマンドは 1 行に入力します。グローバルパラメータの詳細、およびさまざまな XSLT プロセッサでのグローバルパラメータの設定方法については、第 4 章 4.4.3 節を参照してください。