XSLTます。<xsl:とき>要素
定義と使用法
ます。<xsl:時> <:選択のxsl>要素は、関連するアクションを指定する要素がために使用されています。 ます。<xsl:時>それがtrueを返す場合、要素は、アクションの規定のその後の実装、式を評価します。
注:<のxsl:時>要素と<のxsl:選択>要素と<のxsl:それ以外の場合>複数条件テストを表現するために一緒に使用される要素。
文法
<xsl:when
test="boolean-expression">
<!-- Content: template -->
</xsl:when>
test="boolean-expression">
<!-- Content: template -->
</xsl:when>
プロパティ
属性 | 值 | 描述 |
---|---|---|
test | boolean-expression | 必需。规定要测试的布尔表达式。 |
例1
CDの価格で、次のコードは、10以上の列が色ピンク背景アーティストに追加されています。
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<xsl:choose>
<xsl:when test="price>'10'">
<td bgcolor="#ff00ff">
<xsl:value-of select="artist"/></td>
</xsl:when>
<xsl:otherwise>
<td><xsl:value-of select="artist"/></td>
</xsl:otherwise>
</xsl:choose>
</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:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<xsl:choose>
<xsl:when test="price>'10'">
<td bgcolor="#ff00ff">
<xsl:value-of select="artist"/></td>
</xsl:when>
<xsl:otherwise>
<td><xsl:value-of select="artist"/></td>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
XMLファイルを表示し 、 XSLファイルを表示し 、 結果を表示します 。
例2
の「色」と呼ばれる変数を宣言します。 その値は、現在の要素の色属性に割り当てられます。 現在の要素が何色属性を持っていない場合は、値の「色」が「グリーン」になります。
<xsl:variable name="color">
<xsl:choose>
<xsl:when test="@color">
<xsl:value-of select="@color"/>
</xsl:when>
<xsl:otherwise>green</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="@color">
<xsl:value-of select="@color"/>
</xsl:when>
<xsl:otherwise>green</xsl:otherwise>
</xsl:choose>
</xsl:variable>
完全なXSLT要素のリファレンス・マニュアル