XSLTます。<xsl:variable>要素
定義と使用法
ます。<xsl:variable>要素は、ローカルまたはグローバル変数を宣言するために使用されます。
注:、宣言するための最上位の要素(トップレベルの要素)として、それはグローバル変数である場合。テンプレート内の変数を宣言した場合、それはローカル変数です。
注:変数の値を設定したら、この値を変更したり、変更することはできません!
ヒント:<のxsl:variable>をすることができますプロパティを選択を通じて要素やコンテンツは、変数に値を追加!
文法
<xsl:variable
name="name"
select="expression">
<!-- Content:template -->
</xsl:variable>
name="name"
select="expression">
<!-- Content:template -->
</xsl:variable>
プロパティ
属性 | 值 | 描述 |
---|---|---|
name | name | 必需。规定变量的名称。 |
select | expression | 可选。定义变量的值。 |
例1
select属性場合は、<のxsl:variable>要素は、任意のコンテンツを含めることはできません。 select属性は、テキスト文字列が含まれている場合は、引用符で囲んだ文字列を指定する必要があります。 「赤」に割り当てられ、変数「色」のための2つの例を次に示します。
<xsl:variable name="color" select="'red'" />
<xsl:variable name="color" select='"red"' />
例2
場合ます。<xsl:変数>要素は、唯一のname属性、およびなしコンテンツを含む、変数の値が空の文字列は、次のとおりです。
<xsl:variable name="j" />
例3
次の例によるます。<xsl:変数>変数 "ヘッダー"の要素の内容が割り当て:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="header">
<tr>
<th>Element</th>
<th>Description</th>
</tr>
</xsl:variable>
<xsl:template match="/">
<html>
<body>
<table>
<xsl:copy-of select="$header" />
<xsl:for-each select="reference/record">
<tr>
<xsl:if category="XML">
<td><xsl:value-of select="element"/></td>
<td><xsl:value-of select="description"/></td>
</xsl:if>
</tr>
</xsl:for-each>
</table>
<br />
<table>
<xsl:copy-of select="$header" />
<xsl:for-each select="table/record">
<tr>
<xsl:if category="XSL">
<td><xsl:value-of select="element"/></td>
<td><xsl:value-of select="description"/></td>
</xsl:if>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="header">
<tr>
<th>Element</th>
<th>Description</th>
</tr>
</xsl:variable>
<xsl:template match="/">
<html>
<body>
<table>
<xsl:copy-of select="$header" />
<xsl:for-each select="reference/record">
<tr>
<xsl:if category="XML">
<td><xsl:value-of select="element"/></td>
<td><xsl:value-of select="description"/></td>
</xsl:if>
</tr>
</xsl:for-each>
</table>
<br />
<table>
<xsl:copy-of select="$header" />
<xsl:for-each select="table/record">
<tr>
<xsl:if category="XSL">
<td><xsl:value-of select="element"/></td>
<td><xsl:value-of select="description"/></td>
</xsl:if>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
完全なXSLT要素のリファレンス・マニュアル