<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:template match="/">
		<html>
		<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<meta name="author" content="Gan Uesli Starling" />
		<meta name="copyright" content="2002, Gan Uesli Starling" />
		<meta name="description" content="Book collection." />
		<meta name="keywords" content="starling, vance, xml" />
		<link rel="stylesheet" type="text/css" href="../starling.css" />
		<base target="_blank" />
		</head>
		<body>
		<h1 class="center">Book Collection Index</h1>
		<xsl:apply-templates select="library/category" /> 
		</body>
		</html>
	</xsl:template>

	<xsl:template match="category">
		<br />
		<table border="2">
			<tr>
				<th colspan="6">
					<h2><xsl:apply-templates select="genre"/>: <span style="font-weight:lighter;"><xsl:apply-templates select="status"/> Copies</span></h2>
				</th>
			</tr>
			<tr>
				<th width="10%">Author</th>
				<th width="15%">Title</th>
				<th>Publisher</th>
				<th>Edition</th>
				<th>Serial</th>
				<th>Description</th>
			</tr>
			<xsl:for-each select="book">		  
				<xsl:sort select="author" data-type="text"/>
				<xsl:sort select="series" data-type="text"/>
				<xsl:sort select="title" data-type="text"/>
				<tr>
					<td style="marglin-left: 5px;"><xsl:value-of select="author"/></td>
					<td><b><xsl:value-of select="title"/></b><br /><i><xsl:value-of select="subtitle"/></i><xsl:apply-templates select="series"/><xsl:apply-templates select="illust"/><xsl:apply-templates select="isbn"/></td>
					<td><xsl:value-of select="publisher"/></td> 
					<td><xsl:value-of select="edition"/></td>
					<td align="center">
						<xsl:apply-templates select="serial"/>
					</td>
					<td><xsl:value-of select="comment"/></td>
	   			 </tr>
			</xsl:for-each>
		</table>
	</xsl:template>

	<xsl:template match="genre">
		<xsl:choose>
			<xsl:when test="text()">   <!-- test not empty -->
				<xsl:value-of select="."/>
			</xsl:when> 
			<xsl:otherwise>
				Oops, 'genre' left empty! <!-- warning signal -->
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template match="status">
		<xsl:choose>
			<xsl:when test="text()">   <!-- test not empty -->
				<xsl:value-of select="."/>
			</xsl:when> 
			<xsl:otherwise>
				Oops, 'status' left empty! <!-- warning signal -->
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template match="isbn">
		<xsl:choose>
			<xsl:when test="text()">   <!-- test not empty -->
				<xsl:value-of select="."/>
			</xsl:when> 
			<xsl:otherwise>
				&#160; <!-- nbsp char -->
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template match="subtitle">
		<xsl:choose>
			<xsl:when test="text()">   <!-- test not empty -->
				<br /><i><xsl:value-of select="."/></i>
			</xsl:when>
			<xsl:otherwise>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template match="serial">
		<xsl:choose>
			<xsl:when test="text()">   <!-- test not empty -->
				<xsl:value-of select="."/>
			</xsl:when>
			<xsl:otherwise>
				&#160; <!-- nbsp char -->
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template match="series">
		<xsl:choose>
			<xsl:when test="text()">   <!-- test not empty -->
				<br /><span style="font-size: smaller;">Series: <xsl:value-of select="."/></span>
			</xsl:when>
			<xsl:otherwise>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template match="illust">
		<xsl:choose>
			<xsl:when test="text()">   <!-- test not empty -->
				<br /><span style="font-size: smaller;">Illust: <xsl:value-of select="."/></span>
			</xsl:when>
			<xsl:otherwise>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template match="isbn">
		<xsl:choose>
			<xsl:when test="text()">   <!-- test not empty -->
				<br /><span style="font-size: smaller;"><xsl:value-of select="."/></span>
			</xsl:when>
			<xsl:otherwise>
				<span style="font-size: smaller;"><br />ISBN unknown, if any.</span>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

</xsl:stylesheet>
