<xsl:variable>で変数を使う練習1
<xsl:variable name="corp_name">ジャムハウス</xsl:variable>という記述で
変数corp_nameに「ジャムハウス」という文字列を入れている。参照するときは
変数名り前に$を付けて$corp_nameのように書く。
【sample030.xml】
<?xml version="1.0" encoding="Shift_JIS" ?>
<?xml-stylesheet href="sample030.xsl" type="text/xsl" ?>
<リスト>
<会員>
<名前>山田太郎</名前>
<年齢>58</年齢>
<役職>代表取締役</役職>
</会員>
<会員>
<名前>鈴木啓子</名前>
<年齢>48</年齢>
<役職>専務</役職>
</会員>
<会員>
<名前>井上政文</名前>
<年齢>38</年齢>
<役職>専務</役職>
</会員>
<会員>
<名前>菊池俊和</名前>
<年齢>35</年齢>
<役職>営業部長</役職>
</会員>
</リスト>
【sample030.xsl】
<?xml version="1.0" encoding="Shift_JIS" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="Shift_JIS" />
<xsl:template match="リスト">
<html>
<head>
<title></title>
</head>
<body>
<xsl:apply-templates select="会員" />
</body>
</html>
</xsl:template>
<xsl:template match="会員">
<xsl:variable name="corp_name">ジャムハウス</xsl:variable>
<p>
<xsl:value-of select="名前" />[<xsl:value-of select="$corp_name" />]
</p>
</xsl:template>
</xsl:stylesheet>
【結果】