<?xml version="1.0"?>
<xsl:stylesheet
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
	xmlns="http://www.w3.org/1999/xhtml">
	<xsl:output method="html"/>

	<xsl:template match="spells">
		<table>
			<tr>
				<th>L</th>
				<th>Spell</th>
				<th>Ref</th>
			</tr>
			<xsl:apply-templates select="book/spell">
				<xsl:sort select="@level"/>
				<xsl:sort select="name"/>
			</xsl:apply-templates>
		</table>
		Done.
	</xsl:template>

	<xsl:template match="spell">
		<tr>
			<xsl:if test="@level - 2*floor(@level div 2) = 1">
				<td>odd</td>
			</xsl:if>
			<xsl:if test="@level - 2*floor(@level div 2) = 0">
				<td>even</td>
			</xsl:if>
			<td><xsl:value-of select="preceding-sibling::*[position()=last()]/name"/></td>
			<td><xsl:value-of select="@level"/></td>
			<td><xsl:value-of select="name"/></td>
			<td><xsl:value-of select="../@acronym"/>
				<xsl:text> </xsl:text>
				<xsl:value-of select="@page"/></td>
		</tr>
	</xsl:template>

</xsl:stylesheet>
