<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet id="xsl" version="1.0"
		xmlns:xhtml="http://www.w3.org/1999/xhtml"
		xmlns:html="http://www.w3.org/1999/xhtml"
		xmlns:xlink="http://www.w3.org/1999/xlink"
		xmlns:svg="http://www.w3.org/2000/svg"
		xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:output method="html"/>
	
	<xsl:template match="/costs">
		<html xmlns="http://www.w3.org/1999/xhtml">
			<head>
				<title>BESM3 Summary</title>
				<style type="text/css">
					tr {
					}
					th, td {
						text-align: left;
						vertical-align: top;
						border-bottom: 1px solid black;
						padding-left: 1ex;
					}
					.name.defect:before { content: "Defect: "; }
					.defect { font-weight: bold; color: red; }
					.max { font-size: 80%; font-style: italic; }
					.modifier { font-style: italic; }
					.name { text-transform: capitalize; }
					.option { color: black; }
					.name.restriction:before { content: "Restriction: "; }
					.restriction { color: red; }
					.slot { color: green; }
					.stat { font-size: 60%; }
					.variable { color: blue; }

					ul { margin: 0; padding: 0; }
					.cost ul { list-style-type: none; }
					.detail ul { margin-left: 1em; }
				</style>
			</head>
			<body>
				<h1>BESM 3e Attribute Summary</h1>
				<dl>
					<dt class="defect">Defect</dt>
					<dd>The value of a defect is applied to the character as a whole.</dd>
					
					<dt class="restriction">Restriction [value]</dt>
					<dd>The value of a restriction is applied to the cost
						of the attribute only once, regardless of how many
						levels the attribute has.</dd>
					
					<dt class="variable">Variable [cost]</dt>
					<dd>The cost of a variable is applied to the cost of
						the attribute only once, regardless of how many
						levels the attribute has.</dd>
					
					<dt class="slot">Slot [always requires one level]</dt>
					<dd>A slot occupies one level of the attribute; in other
						words, you must have at least as many levels of the
						attribute as you have selected slots.</dd>
					
					<dt class="modifier">Modifier</dt>
					<dd>A modifier modifies the cost per level of an attribute.</dd>
				</dl>
				
				<table cellspacing="0" cellpadding="0" id="table">
				<tr>
					<th>Name <span class="stat">[stat]</span></th>
					<th>Type <span class="max">[Max Level]</span></th>
					<th>Cost per Level</th>
					<th>PMVs</th>
					<th>Detail</th>
				</tr>
				<xsl:apply-templates select="attribute[@tag='stat']">
					<xsl:sort select="@name"/>
				</xsl:apply-templates>
				<xsl:apply-templates select="attribute[@tag!='stat']">
					<xsl:sort select="@name"/>
				</xsl:apply-templates>
				<xsl:apply-templates select="restriction">
					<xsl:sort select="@name"/>
				</xsl:apply-templates>
				<xsl:apply-templates select="defect">
					<xsl:sort select="@name"/>
				</xsl:apply-templates>
				</table>
			</body>
		</html>
	</xsl:template>
	
	<xsl:template match="attribute">
		<tr>
			<td class="name">
				<xsl:value-of select="@name"/>
				<xsl:if test="@stat!=''">
					<xsl:text> </xsl:text>
					<span class="stat">[<xsl:value-of select="@stat"/>]</span>
				</xsl:if>
			</td>
			<td class="progression">
				<xsl:choose>
					<xsl:when test="@tag='slow'">
						<abbr title="1,2,4,8,16,32">slow</abbr>
					</xsl:when>
					<xsl:when test="@tag='medium'">
						<abbr title="1,3,10,30,100">medium</abbr>
					</xsl:when>
					<xsl:when test="@tag='fast'">
						<abbr title="1,10,100,1000">fast</abbr>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="@tag"/>
					</xsl:otherwise>
				</xsl:choose>
				<xsl:if test="@max!=''">
					<xsl:text> </xsl:text>
					<span class="max">[<xsl:value-of select="@max"/>]</span>
				</xsl:if>
			</td>
			<td class="cost">
				<xsl:if test="@cost!=''">
					<xsl:value-of select="@cost"/>
				</xsl:if>
				<ul>
					<xsl:apply-templates select="option|modifier"/>
				</ul>
			</td>
			<td class="pmv">
				<xsl:if test="@a!=''">A</xsl:if>
				<xsl:if test="@d!=''">D</xsl:if>
				<xsl:if test="@r!=''">R</xsl:if>
				<xsl:if test="@t!=''">T</xsl:if>
			</td>
			<td class="detail">
				<ul>
					<xsl:apply-templates select="slot"/>
					<xsl:apply-templates select="restriction"/>
					<xsl:apply-templates select="variable"/>
				</ul>
			</td>
		</tr>
	</xsl:template>
	<xsl:template match="attribute/restriction|attribute/slot|attribute/variable">
		<li class="{name()}">
			<xsl:value-of select="."/>
			<xsl:if test="@cost!=''">[<xsl:value-of select="@cost"/>]</xsl:if>
		</li>
	</xsl:template>
	<xsl:template match="attribute/option|attribute/modifier">
		<li class="{name()}">
			<xsl:value-of select="."/>: <xsl:value-of select="@cost"/>
		</li>
	</xsl:template>
	
	<xsl:template match="restriction|defect">
		<tr>
			<td>
				<xsl:attribute name="class">name <xsl:value-of select="name()"/></xsl:attribute>
				<xsl:value-of select="@name"/>
			</td>
			<td class="progression">
				<xsl:value-of select="@category"/>
				<xsl:if test="@ranks!=''">
					<xsl:text> </xsl:text>
					<span class="max">[<xsl:value-of select="@ranks"/>]</span>
				</xsl:if>
			</td>
			<td class="cost">
				<xsl:choose>
					<xsl:when test="@category='lesser'">1</xsl:when>
					<xsl:when test="@category='greater'">2</xsl:when>
					<xsl:when test="@category='serious'">3</xsl:when>
					<xsl:when test="@category='radical'">
						<xsl:value-of select="@by"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="@category"/>
					</xsl:otherwise>
				</xsl:choose>
			</td>
			<td class="pmv"></td>
			<td class="detail"></td>
		</tr>
	</xsl:template>
	
</xsl:stylesheet>
