<?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:template match="/">
		<html>
			<head>
				<title>Skillchains</title>
				<style type="text/css">
					body, table, tr, td, th { font-family: Verdana; font-size: 10pt; }
					th.shortjob { width: 2.75em; }
					table.datatable { border: none; border-collapse: collapse; }
					table.datatable tr.spacer td { padding-top: 10pt; border: none; }
					tr.sectionhead th { background-color: #EEE; font-size: 12pt; font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; }
					tr.head th { background-color: #FAFAFA; }
					table.datatable td, table.datatable th { border: solid 1px #000; }
					td.wsboth, td.wsmain, td.wsnone { text-align: center; }
					td.wsboth { background-color:#093; color:#FFF; }
					td.wsmain { background-color:#C90; color:#FFF; }
					.unbordered { border: none !important; }
					.element { font-weight: bold; }
					.fire { color: #F00; }
					.earth { color: #CC0; }
					.water { color: #00F; }
					.wind { color: #0C0; }
					.ice { color: #0BC; }
					.thunder { color: #90C; }
					.light { color: #CCC; }
					.dark { color: #000; }
				</style>
			</head>
			<body>
				<h1>Skillchains</h1>
				<xsl:apply-templates select="renkei/elements"/>
				<xsl:apply-templates select="renkei/jobs"/>
				<xsl:apply-templates select="renkei/skillchains"/>
				<xsl:apply-templates select="renkei/weapons"/>
				<h2>Skills - Elements</h2>
				<table id="skillelements" class="datatable">
					<tbody>
						<xsl:apply-templates select="renkei/weapons/weapon" mode="element"/>
						<xsl:apply-templates select="renkei/bloodpacts" mode="element"/>
						<xsl:apply-templates select="renkei/bluemagic" mode="element"/>
					</tbody>
				</table>
				<p><sup>Q</sup> - Quested, a quest must be completed to unlock this skill</p>
			</body>
		</html>
	</xsl:template>
	<xsl:template match="elements">
		<h2>Elements</h2>
		<ul>
			<xsl:apply-templates select="*"/>
		</ul>
	</xsl:template>
	<xsl:template match="element">
		<li><span style="color:{@color};">&#9679;</span> <xsl:value-of select="name[lang('en')]/text()"/></li>
	</xsl:template>
	<xsl:template match="element" mode="pip">
		<span style="color:{@color};" title="{name[lang('en')]/text()}">&#9679;</span>
	</xsl:template>
	<xsl:template match="element" mode="text">
		<span class="element {substring-after(@id, 'e.')}">
			<xsl:choose>
				<xsl:when test="@id='e.fusion'"><span class="fire">Fus</span><span class="light">ion</span></xsl:when>
				<xsl:when test="@id='e.gravitation'"><span class="earth">Gravit</span><span class="dark">ation</span></xsl:when>
				<xsl:when test="@id='e.distortion'"><span class="water">Disto</span><span class="ice">rtion</span></xsl:when>
				<xsl:when test="@id='e.fragmentation'"><span class="wind">Fragme</span><span class="thunder">ntation</span></xsl:when>
				<xsl:when test="@id='e.light.3'">~<span class="fire">Li</span><span class="light">g</span><span class="wind">h</span><span class="thunder">t</span>~</xsl:when>
				<xsl:when test="@id='e.dark.3'">~<span class="earth">D</span><span class="dark">a</span><span class="water">r</span><span class="ice">k</span>~</xsl:when>
				<xsl:otherwise><xsl:value-of select="name[lang('en')]/text()"/></xsl:otherwise>
			</xsl:choose>
		</span>
	</xsl:template>
	<xsl:template match="skillchains">
		<h2>Skillchains</h2>
		<table>
			<tbody>
				<xsl:apply-templates select="skillchain"/>
			</tbody>
		</table>
	</xsl:template>
	<xsl:template match="skillchain">
		<tr>
			<th colspan="4"><xsl:apply-templates select="burst"/><xsl:value-of select="name/text()"/></th>
		</tr>
		<xsl:apply-templates select="chain"/>
	</xsl:template>
	<xsl:template match="chain">
		<tr>
			<td>
			<xsl:if test="@prereq">
			(<xsl:value-of select="id(@prereq)/name[lang('en')]/text()"/>)
			</xsl:if>
			</td>
			<td><xsl:value-of select="id(@from)/name[lang('en')]/text()"/></td>
			<td>-&gt;</td>
			<td><xsl:value-of select="id(@to)/name[lang('en')]/text()"/></td>
		</tr>
	</xsl:template>
	<xsl:template match="burst">
		<span style="color:{id(@element)/@color};" title="{id(@element)/name[lang('en')]/text()}">&#9679;</span>
	</xsl:template>
	<xsl:template match="name">
		<xsl:value-of select="text()"/>
	</xsl:template>
	<xsl:template match="jobs">
		<h2>Jobs</h2>
		<ul>
			<xsl:apply-templates select="job"/>
		</ul>
	</xsl:template>
	<xsl:template match="job">
		<li>[<xsl:value-of select="shortname[lang('en')]/text()"/>] <xsl:value-of select="name[lang('en')]/text()"/></li>
	</xsl:template>
	<xsl:template match="weapons">
		<h2>Weapon Skills - Jobs</h2>
		<table id="wsjob" class="datatable" summary="Lists which jobs can use which weapon skills">
			<tfoot>
				<tr>
					<td colspan="2" class="unbordered"></td>
					<td class="wsboth">M/S</td>
					<td colspan="{count(/renkei/jobs/job) - 1}" class="unbordered">- Available when given job is main or support job</td>
				</tr>
				<tr class="spacer">
					
					<td colspan="{count(/renkei/jobs/job) + 2}"></td>
				</tr>
				<tr>
					<td colspan="2" class="unbordered"></td>
					<td class="wsmain">M</td>
					<td colspan="{count(/renkei/jobs/job) - 1}" class="unbordered">- Available only when given job is main job</td>
				</tr>
			</tfoot>
			<tbody>
				<xsl:apply-templates select="weapon" mode="job"/>
			</tbody>
		</table>
		<p><sup>Q</sup> - Quested, a quest must be completed to unlock this skill</p>
	</xsl:template>
	<xsl:template match="weapon" mode="job">
		<tr class="sectionhead">
			<th colspan="{count(/renkei/jobs/job) + 2}"><xsl:value-of select="name/text()"/></th>
		</tr>
		<tr class="head">
			<th>Name</th>
			<th>Level</th>
			<xsl:for-each select="/renkei/jobs/job">
				<th class="shortjob">
					<xsl:value-of select="shortname[lang('en')]/text()"/>
				</th>
			</xsl:for-each>
		</tr>
		<xsl:apply-templates select="skill" mode="job"/>
		<tr class="spacer"><td colspan="{count(/renkei/jobs/job) + 2}"></td></tr>
	</xsl:template>
	<xsl:template match="skill" mode="job">
		<xsl:variable name="skillid" select="@id"/>
		<tr>
			<th>
			<xsl:if test="@elema"><xsl:apply-templates select="id(@elema)" mode="pip"/></xsl:if>
			<xsl:if test="@elemb"><xsl:apply-templates select="id(@elemb)" mode="pip"/></xsl:if>
			<xsl:if test="@elemc"><xsl:apply-templates select="id(@elemc)" mode="pip"/></xsl:if>
			<xsl:value-of select="name[lang('en')]/text()"/></th>
			<td>
				<xsl:choose>
					<xsl:when test="@level='relic'">Relic</xsl:when>
					<xsl:otherwise><xsl:value-of select="@level"/></xsl:otherwise>
				</xsl:choose>
				<xsl:if test="@quested='yes'"><sup><abbr title="Quested">Q</abbr></sup></xsl:if>
			</td>
			<xsl:for-each select="/renkei/jobs/job">
				<xsl:variable name="jobid" select="@id"/>
				<td>
					<xsl:choose>
						<xsl:when test="count(id($skillid)/both[@job=$jobid])&gt;0"><xsl:attribute name="class">wsboth</xsl:attribute>M/S</xsl:when>
						<xsl:when test="count(id($skillid)/main[@job=$jobid])&gt;0"><xsl:attribute name="class">wsmain</xsl:attribute>M</xsl:when>
						<xsl:otherwise><xsl:attribute name="class">wsnone</xsl:attribute>-</xsl:otherwise>
					</xsl:choose>
				</td>
			</xsl:for-each>
		</tr>
	</xsl:template>
	<xsl:template match="weapon" mode="element">
		<tr class="sectionhead">
			<th colspan="5"><xsl:value-of select="name[lang('en')]/text()"/></th>
		</tr>
		<tr class="head">
			<th>Name</th>
			<th>Level</th>
			<th>A</th>
			<th>B</th>
			<th>C</th>
		</tr>
		<xsl:apply-templates select="skill" mode="element"/>
		<tr class="spacer"><td colspan="5"></td></tr>
	</xsl:template>
	<xsl:template match="skill" mode="element">
		<tr>
			<th><xsl:value-of select="name[lang('en')]/text()"/></th>
			<td>
				<xsl:choose>
					<xsl:when test="@level='relic'">Relic</xsl:when>
					<xsl:otherwise><xsl:value-of select="@level"/></xsl:otherwise>
				</xsl:choose>
				<xsl:if test="@quested='yes'"><sup><abbr title="Quested">Q</abbr></sup></xsl:if>
			</td>
			<td>
				<xsl:choose>
					<xsl:when test="@elema"><xsl:apply-templates select="id(@elema)" mode="text"/></xsl:when>
					<xsl:otherwise>-</xsl:otherwise>
				</xsl:choose>
			</td>
			<td>
				<xsl:choose>
					<xsl:when test="@elemb"><xsl:apply-templates select="id(@elemb)" mode="text"/></xsl:when>
					<xsl:otherwise>-</xsl:otherwise>
				</xsl:choose>
			</td>
			<td>
				<xsl:choose>
					<xsl:when test="@elemc"><xsl:apply-templates select="id(@elemc)" mode="text"/></xsl:when>
					<xsl:otherwise>-</xsl:otherwise>
				</xsl:choose>
			</td>
		</tr>
	</xsl:template>
	<xsl:template match="bloodpacts" mode="element">
		<tr class="sectionhead">
			<th colspan="5"><xsl:value-of select="name[lang('en')]/text()"/></th>
		</tr>
		<tr class="head">
			<th>Name</th>
			<th>Level</th>
			<th>A</th>
			<th>B</th>
			<th>C</th>
		</tr>
		<xsl:apply-templates select="avatar/bloodpact[@type='renkei']" mode="element">
			<xsl:sort data-type="number" select="@level"/>
			<xsl:sort data-type="text" select="../name[lang('en')]/text()"/>
			<xsl:sort data-type="text" select="name[lang('en')]/text()"/>
		</xsl:apply-templates>
		<tr class="spacer"><td colspan="5"></td></tr>
	</xsl:template>
	<xsl:template match="bloodpact" mode="element">
		<tr>
			<th><xsl:value-of select="../name[lang('en')]/text()"/>: <xsl:value-of select="name[lang('en')]/text()"/></th>
			<td><xsl:value-of select="@level"/></td>
			<td>
				<xsl:choose>
					<xsl:when test="@elema"><xsl:apply-templates select="id(@elema)" mode="text"/></xsl:when>
					<xsl:otherwise>-</xsl:otherwise>
				</xsl:choose>
			</td>
			<td>
				<xsl:choose>
					<xsl:when test="@elemb"><xsl:apply-templates select="id(@elemb)" mode="text"/></xsl:when>
					<xsl:otherwise>-</xsl:otherwise>
				</xsl:choose>
			</td>
			<td>
				<xsl:choose>
					<xsl:when test="@elemc"><xsl:apply-templates select="id(@elemc)" mode="text"/></xsl:when>
					<xsl:otherwise>-</xsl:otherwise>
				</xsl:choose>
			</td>
		</tr>
	</xsl:template>
	<xsl:template match="bluemagic" mode="element">
		<tr class="sectionhead">
			<th colspan="5"><xsl:value-of select="name[lang('en')]/text()"/></th>
		</tr>
		<tr class="head">
			<th>Name</th>
			<th>Level</th>
			<th>A</th>
			<th>B</th>
			<th>C</th>
		</tr>
		<xsl:apply-templates select="blue" mode="element"/>
		<tr class="spacer"><td colspan="5"></td></tr>
	</xsl:template>
	<xsl:template match="blue" mode="element">
		<tr>
			<th><xsl:value-of select="name[lang('en')]/text()"/></th>
			<td><xsl:value-of select="@level"/></td>
			<td>
				<xsl:choose>
					<xsl:when test="@elema"><xsl:apply-templates select="id(@elema)" mode="text"/></xsl:when>
					<xsl:otherwise>-</xsl:otherwise>
				</xsl:choose>
			</td>
			<td>
				<xsl:choose>
					<xsl:when test="@elemb"><xsl:apply-templates select="id(@elemb)" mode="text"/></xsl:when>
					<xsl:otherwise>-</xsl:otherwise>
				</xsl:choose>
			</td>
			<td>
				<xsl:choose>
					<xsl:when test="@elemc"><xsl:apply-templates select="id(@elemc)" mode="text"/></xsl:when>
					<xsl:otherwise>-</xsl:otherwise>
				</xsl:choose>
			</td>
		</tr>
	</xsl:template>
</xsl:stylesheet>

