<xsl:if>の練習3

<xsl:if>で数値の大小を比較して処理を分けている。
【sample019.xml】
<?xml version="1.0" encoding="Shift_JIS" ?>
<?xml-stylesheet href="sample019.xsl" type="text/xsl" ?>
<社員名簿>
	<社員>
		<社員番号>001</社員番号>
		<名前>井上健語</名前>
		<年齢>38</年齢>
		<性別>男</性別>
	</社員>
	<社員>
		<社員番号>002</社員番号>
		<名前>山田太郎</名前>
		<年齢>35</年齢>
		<性別>男</性別>
	</社員>
	<社員>
		<社員番号>003</社員番号>
		<名前>中田英俊</名前>
		<年齢>28</年齢>
		<性別>男</性別>
	</社員>
	<社員>
		<社員番号>004</社員番号>
		<名前>菊池絵里子</名前>
		<年齢>25</年齢>
		<性別>女</性別>
	</社員>
	<社員>
		<社員番号>005</社員番号>
		<名前>吉田美子</名前>
		<年齢>30</年齢>
		<性別>女</性別>
	</社員>
	<社員>
		<社員番号>006</社員番号>
		<名前>三好祐介</名前>
		<年齢>25</年齢>
		<性別>男</性別>
	</社員>
</社員名簿>


【sample019.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><value-of>で文字列を書き出す</title>
</head>
<body>
<p><xsl:apply-templates /></p>
</body>
</html>
</xsl:template>

<xsl:template match="社員">

<xsl:if test="年齢>=30">
<p>
	<span style="color:blue"><xsl:value-of select="名前" /></span>
	さんは<xsl:value-of select="年齢" />才なので、年長組(30才以上)です。
</p>
</xsl:if>

<xsl:if test="年齢<30">
<p>
	<span style="color:red"><xsl:value-of select="名前" /></span>
	さんは<xsl:value-of select="年齢" />才なので、若年組(30才未満)です。
</p>
</xsl:if>

</xsl:template>

</xsl:stylesheet>


【結果】