スタイルシート変換言語 XSLT

<xsl:if>の解説です。  スタイルシート変換言語 XSLTリファレンス 

<xsl:if>

<xsl:if
test="boolean-expression">
・・・
</xsl:if>
xsl:ifを使用すると、test属性に指定した条件が成り立つ場合にのみ、 処理を実行します。
なお、複数の分岐が必要な場合にはxsl:chooseを設定して処理を行います。
zipファイル 以下のサンプルをダウンロード(ZIP圧縮)
■ aaa.xml
<?xml version="1.0" encoding="Shift_JIS"?>
<?xml-stylesheet type="text/xsl" href="bbb.xsl"?>

<item>
<book>
<name>誰でも簡単XML</name>
<val>1800</val>
<stock>18</stock>
</book>

<book>
<name>XSLTを使いこなす</name>
<val>3200</val>
<stock>27</stock>
</book>

<book>
<name>XMLとは一体何なのか</name>
<val>1600</val>
<stock>50</stock>
</book>

<book>
<name>3日で覚えるXSLT</name>
<val>1200</val>
<stock>2</stock>
</book>

<book>
<name>楽々自動化「XML&XSLT」</name>
<val>2900</val>
<stock>10</stock>
</book>
</item>
■ bbb.xsl
<?xml version="1.0" encoding="Shift_JIS"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
<head>
<link rel="stylesheet" href="ccc.css" />
</head>
<body>
 <table cellspacing="0">
 <tr>
 <th width="180">商品名</th>
 <th>価格</th>
 <th width="180">在庫数</th>
 </tr>
  <xsl:apply-templates select="item/book" />
 </table>
</body>
</html>
</xsl:template>

<xsl:template match="book">
<tr>
<td>
<xsl:value-of select="name" />
</td>
<td class="aka">
<xsl:value-of select="val" />円
</td>
<td>
<xsl:value-of select="stock" />
<xsl:if test="stock &#60; 20"><span class="aka">(在庫数少)</span></xsl:if>
</td>
</tr>
</xsl:template>

</xsl:stylesheet>
■ ccc.css
table {width:500px}
th {background-color:#99ff66;padding:3px}
td {padding:5px;line-height:150%;border-color:#333333;
border-width:1px;border-style:solid}
.aka {color:#990000}
bbb.xslのtest属性に指定した条件式「stock &#60; 20」 は「stockの値が20未満」という意味を持ちます。なお、 「<」をそのまま記述する事はできない為「&#60;」 と記述しています。この条件が成立した要素のみ「(在庫数少)」と赤字で表示 されているのが確認できます。
サンプル
XSLT要素一覧
+ <xsl:apply-imports>
+ <xsl:apply-templates>
+ <xsl:attribute>
+ <xsl:attribute-set>
+ <xsl:call-template>
+ <xsl:comment>
+ <xsl:copy>
+ <xsl:copy-of>
+ <xsl:decimal-format>
+ <xsl:element>
+ <xsl:fallback>
+ <xsl:for-each>
+ <xsl:if>
+ <xsl:import>
+ <xsl:include>
+ <xsl:key>
+ <xsl:message>
+ <xsl:namespace-alias>
+ <xsl:number>
+ <xsl:otherwise>
+ <xsl:output>
+ <xsl:param>
+ <xsl:preserve-space>
+ <xsl:processing-instruction>
+ <xsl:sort>
+ <xsl:strip-space>
+ <xsl:stylesheet>
+ <xsl:template>
+ <xsl:text>
+ <xsl:value-of>
+ <xsl:variable>
+ <xsl:when>
+ <xsl:with-param>