﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
	version="1.0"
	xmlns:am="http://www.ani-mayhem.com/"
	xmlns:db="http://www.ani-mayhem.com/database"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns="http://www.w3.org/1999/xhtml"
	exclude-result-prefixes="am db">
	<xsl:output method="xml" indent="yes" encoding="utf-8" omit-xml-declaration="no" doctype-public="-//W3C//DTD XHTML 1.1//EN" doctype-system="http://www.w3.org/MarkUp/DTD/xhtml11.dtd"/>
	<xsl:variable name="cgi">http://www.ani-mayhem.com/cardcatalog.aspx?xmlid=</xsl:variable>
	<xsl:template match="/">
		<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
			<head>
				<title>Ani-Mayhem Online - Database</title>
				<link rel="stylesheet" href="http://www.ani-mayhem.com/ani-mayhem.css" type="text/css" />
				<link rel="stylesheet" href="http://www.ani-mayhem.com/database/database.css" type="text/css" />
				<link rel="shortcut icon" href="http://www.ani-mayhem.com/ani-mayhem.ico" type="image/x-icon" />
			</head>
			<body id="database">
				<h1>
					<a href="http://www.ani-mayhem.com/">
						<img src="http://www.ani-mayhem.com/ani-mayhem.png" alt="Ani-Mayhem Online" />
					</a>
				</h1>
				<hr />
				<h2 class="minordisaster">
					<span class="title">Database</span>
					<span class="date">December 17, 2011</span>
				</h2>
				<xsl:apply-templates/>
				<hr />
			</body>
		</html>
	</xsl:template>
	<xsl:template match="am:ani-mayhem">
		<table>
			<xsl:attribute name="summary">A complete listing of all Ani-Mayhem cards, includes Name, Type, Rarity, Series, and Set.</xsl:attribute>
			<caption class="minordisaster">Ani-Mayhem Database</caption>
			<thead>
				<tr>
					<th class="minordisaster" scope="col" id="Name">Name</th>
					<th class="minordisaster" scope="col" id="Type">Type</th>
					<th class="minordisaster" scope="col" id="Rarity">Rarity</th>
					<th class="minordisaster" scope="col" id="Series">Series</th>
					<th class="minordisaster" scope="col" id="Set">Set</th>
				</tr>
			</thead>
			<tbody>
				<xsl:apply-templates select="am:card[db:Type = 'Character']"/>
			</tbody>
			<tbody>
				<xsl:apply-templates select="am:card[db:Type = 'Enhancement']"/>
			</tbody>
			<tbody>
				<xsl:apply-templates select="am:card[db:Type = 'Equipment']"/>
			</tbody>
			<tbody>
				<xsl:apply-templates select="am:card[db:Type = 'Flash Effect']"/>
			</tbody>
			<tbody>
				<xsl:apply-templates select="am:card[db:Type = 'Global Effect']"/>
			</tbody>
			<tbody>
				<xsl:apply-templates select="am:card[db:Type = 'Haven']"/>
			</tbody>
			<tbody>
				<xsl:apply-templates select="am:card[db:Type = 'Item']"/>
			</tbody>
			<tbody>
				<xsl:apply-templates select="am:card[db:Type = 'Location']"/>
			</tbody>
			<tbody>
				<xsl:apply-templates select="am:card[db:Type = 'Major Disaster']"/>
			</tbody>
			<tbody>
				<xsl:apply-templates select="am:card[db:Type = 'Minor Disaster']"/>
			</tbody>
			<tbody>
				<xsl:apply-templates select="am:card[db:Type = 'Combat']"/>
			</tbody>
			<tbody>
				<xsl:apply-templates select="am:card[db:Type = 'Charm Combat']"/>
			</tbody>
		</table>
	</xsl:template>
	<xsl:template match="am:card">
		<tr id="{@xml:id}">
			<xsl:apply-templates/>
		</tr>
	</xsl:template>
	<xsl:template match="db:Name">
		<td>
			<a href="{$cgi}{../@xml:id}">
				<xsl:value-of select="substring(., 1, string-length() - string-length(substring-after(string(current()[contains(text(),' / ')]), substring-before(current()[contains(text(),' / ')], ' / '))))"/>
			</a>
			<xsl:if test="contains(../db:Type, 'Combat')">
				<xsl:text> / </xsl:text>
				<a href="{$cgi}{//am:card[substring-before(db:Name, ' / ') = substring-after(current(), ' / ')]/@xml:id}">
					<xsl:value-of select="substring-after(., ' / ')"/>
				</a>
			</xsl:if>
		</td>
	</xsl:template>
	<xsl:template match="db:Type | db:Rarity">
		<td class="{normalize-space(translate(., 'CDEFGHILMPRU ', 'cdefghilmpru'))}">
			<xsl:apply-templates/>
		</td>
	</xsl:template>
	<xsl:template match="db:Series">
		<td>
			<xsl:apply-templates/>
			<xsl:if test="contains(../db:Type, 'Combat')">
				<xsl:text> / </xsl:text>
				<xsl:value-of select="//am:card[substring-before(db:Name, ' / ') = substring-after(current()/../db:Name, ' / ')]/db:Series"/>
			</xsl:if>
		</td>
	</xsl:template>
	<xsl:template match="db:Set">
		<td>
			<xsl:apply-templates/>
		</td>
	</xsl:template>
</xsl:stylesheet>