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

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

<xsl:message>

<xsl:message 
terminate="yes | no">
・・・
</xsl:message>
xsl:messageは、XSLTプロセッサにメッセージを送信するよう指示します。 不正な入力項目などのエラー情報を通知する為に使用することができ、 terminate属性の値に「yes」を指定すると、メッセージ送信後に処理を中断します。 デフォルトの値は「no」です。
zipファイル 以下のサンプルをダウンロード(ZIP圧縮)
■ aaa.xml
<?xml version="1.0" encoding="Shift_JIS"?>
<?xml-stylesheet type="text/xsl" href="bbb.xsl"?>

<item>

<book number="b001">
<name>誰でも簡単XML</name>
<val>1800</val>
<ord>50</ord>
</book>

<book number="b004">
<name>すぐ使えるテンプレート集</name>
<val>1800</val>
<ord>30</ord>
</book>

<book number="b005">
<name>XML効率化宣言</name>
<val>2100</val>
<ord>1000</ord>
</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>
<h1>書籍発注数</h1>
 <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">
<xsl:if test="100&#60;ord">
  <xsl:message terminate="yes">
「発注数」に100より大きい数値が入力された箇所があります。100以下に入力しなおして下さい。
  </xsl:message>
</xsl:if>
 <tr>
  <td>
  <xsl:value-of select="name" />
  </td>
  <td class="aka">
  <xsl:value-of select="val" />円
  </td>
  <td>
  <xsl:apply-templates select="ord" />冊
  </td>
 </tr>
</xsl:template>

</xsl:stylesheet>
■ ccc.css
h1 {font-size:16px}
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スタイルシート内に xsl:ifと組み合わせ、xsl:messageを使用しています。 「100&#60;ord」により、ordに記述された値が100よりも大きくなると、 エラーメッセージを表示して、処理を停止します。 (「<」をそのまま記述する事はできない為「&#60;」と記述しています)
エラーが起こったその箇所で処理を停止する為、エラー以前に処理された物は表示されますが、 エラーが起こったその後は表示されません。また。xsl:messageの処理方法はプロセッサにより異なります。 下記のサンプル画像は、IEでエラーメッセージを表示させた物です。
サンプル
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>