<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" encoding="ISO-8859-1" method="xml" version="1.0"/>
	<xsl:param name="haettava"/>
	<xsl:template match="/">
		<html>
			<head>
				<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"/>
				<title> Helian henkilöstö </title>
				<style type="text/css"> &lt;!-- h2 {text-align: center; } .harmaa
                    {background-color: silver; } --&gt; </style>
			</head>
			<body>
				<h2> Henkilöstö </h2>
				<xsl:choose>
					<!-- Jos parametri haettava ei ole tyhjä -->
					<xsl:when test="$haettava != ''">
						<xsl:choose>
							<!-- Jos on parametria haettava vastaava hetu, listataan annetulla hetulla oleva henkilö -->
							<xsl:when test="henkilosto/henkilo[hetu=$haettava]">
								<table border="1" cellpadding="5" cellspacing="0" width="90%">
									<tbody>
										<tr class="harmaa">
											<th>Nimi</th>
											<th>Email</th>
											<th>Työhuone</th>
											<th>puhelin</th>
										</tr>
										<xsl:apply-templates select="henkilosto/henkilo[hetu=$haettava]"/>
									</tbody>
								</table>
							</xsl:when>
							<xsl:otherwise>
								<p>Kyseisellä hetulla '<xsl:value-of select="$haettava"/>' ei ole henkilöä.</p>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:when>
					<!-- Jos parametri haettava on tyhjä, listataan kaikki henkilöt -->
					<xsl:otherwise>
						<table border="1" cellpadding="5" cellspacing="0" width="90%">
							<tbody>
								<tr class="harmaa">
									<th>Nimi</th>
									<th>Email</th>
									<th>Työhuone</th>
									<th>puhelin</th>
								</tr>
								<xsl:apply-templates select="henkilosto/henkilo">
									<xsl:sort select="nimi/sukunimi"/>
									<xsl:sort select="nimi/etunimi"/>
								</xsl:apply-templates>
							</tbody>
						</table>
					</xsl:otherwise>
				</xsl:choose>
			</body>
		</html>
	</xsl:template>
	<xsl:template match="henkilo">
		<tr>
			<td>
				<b>
					<xsl:value-of select="nimi/sukunimi"/> &#160;<xsl:value-of select="nimi/etunimi"/>
				</b>
			</td>
			<td>
				<xsl:value-of select="email"/>
			</td>
			<td>
				<xsl:choose>
					<xsl:when test="not (tyohuone)">&#160;</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="tyohuone"/> (<xsl:value-of select="tyohuone/@sijainti"/>)
					</xsl:otherwise>
				</xsl:choose>
			</td>
			<td>
				<xsl:apply-templates select="puhelin"/>
			</td>
		</tr>
	</xsl:template>
	<xsl:template match="puhelin">
		<xsl:value-of select="."/> (<xsl:value-of select="@type"/>)<xsl:if test="position() &lt; last()">, <br/>
		</xsl:if>
	</xsl:template>
</xsl:stylesheet>
