<xsl:if>の練習2

<xsl:if>を2つ書いて、男の場合と女の場合で処理を変えた例。
【sample018.xml】
<?xml version="1.0" encoding="Shift_JIS" ?>
<?xml-stylesheet href="sample018.xsl" type="text/xsl" ?>
<社員名簿>
	<社員>
		<社員番号>001</社員番号>
		<名前>井上健語</名前>
		<年齢>38</年齢>
		<性別>男</性別>
	</社員>
	<社員>
		<社員番号>002</社員番号>
		<名前>山田太郎</名前>
		<年齢>35</年齢>
		<性別>男</性別>
	</社員>
	<社員>
		<社員番号>003</社員番号>
		<名前>中田英俊</名前>
		<年齢>28</年齢>
		<性別>男</性別>
	</社員>
	<社員>
		<社員番号>004</社員番号>
		<名前>菊池絵里子</名前>
		<年齢>25</年齢>
		<性別>女</性別>
	</社員>
	<社員>
		<社員番号>005</社員番号>
		<名前>吉田美子</名前>
		<年齢>30</年齢>
		<性別>女</性別>
	</社員>
	<社員>
		<社員番号>006</社員番号>
		<名前>三好祐介</名前>
		<年齢>25</年齢>
		<性別>男</性別>
	</社員>
</社員名簿>


【sample018.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="性別='男'">
<p>
	男性社員の
	<span style="color:blue">
		<xsl:value-of select="名前" />
	</span>
	さんを発見しました。
</p>
</xsl:if>
<xsl:if test="性別='女'">
<p>
	女性社員の
	<span style="color:red">
		<xsl:value-of select="名前" />
	</span>
	さんを発見しました。
</p>
</xsl:if>

</xsl:template>

</xsl:stylesheet>


【結果】