<?xml version="1.0" encoding="UTF-8" ?>

<!--Document to try and replicate the full character sheet used. Still very
    much under development.
		Author: Gary Stewart-->
		
<xsl:stylesheet version="2.0" xml:lang="en" 
	xmlns:description="http://byakhee.sourceforge.net/xsd/description" 
	xmlns:xlink="http://www.w3.org/1999/xlink"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	xmlns="http://www.w3.org/1999/xhtml">

<xsl:output method="xml" indent="yes" />

<!--Loads a list of character sheets and processes them in some way.-->
<xsl:template name="load_list">
	<xsl:param name="list">
		<xsl:for-each select="/characters/character">
			<xsl:copy-of select="document(@href)"/>
		</xsl:for-each>
	</xsl:param>
</xsl:template>

<!--This creates a summary like character sheet as seen in the CoC main rulebook.-->
<xsl:template match="/character">
	<!--TODO: Find full name, for now just assuming name > full is there.-->
	<xsl:param name="name" select="description:name/description:full"/>
	<xsl:processing-instruction name="xml-stylesheet">href="full.css" type="text/css"</xsl:processing-instruction>
	<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
		<head>
			<title>Character Sheet for <xsl:value-of select="$name"/></title>
			<link rel="stylesheet" type="text/css" href="full.css" /> 
		</head>
		<body>
			<!--Keeping HTML seperate from the character sheet generator (same code could be used to generate a list or such-->
			<xsl:call-template name="coc-summary"/>
		</body>
	</html>
</xsl:template>

<xsl:template name="coc-summary">
	<!--TODO: Find full name, for now just assuming name > full is there, keeping this independent as well.-->
	<xsl:param name="name" select="description:name/description:full"/>
	<div class="character">
		<div class="character_description">
		<p><strong>Investigator Name: </strong><span class="character_name"><xsl:value-of select="$name"></xsl:value-of></span></p>
		<!--TODO: Process birthplace correctly.-->
		<p><strong>Birthplace: </strong> <xsl:value-of select="description:birthplace/description:location"/></p>
		<!--TODO: Language, if desired, pick highest language.-->
		<!--TODO: No lord/faction system sorted yet-->
		<!--TODO: Occupation-->
		<p><strong>Sex:</strong>  <xsl:value-of select="description:gender" /> <xsl:text> </xsl:text><strong>Age:</strong> <xsl:value-of select="character/description:age" /></p>
		</div>
		<div class="character_stats">
			<h1>Charactistics &amp; Rolls</h1>
			<ul class="attributes">
				<xsl:for-each select="attribute">
					<li><span class="name"><xsl:value-of select="@name"/></span><xsl:text> </xsl:text><span class="value"><xsl:call-template name="stat-picker"><xsl:with-param name="stat" select="."/></xsl:call-template></span></li>
				</xsl:for-each>
			</ul>
		</div>
		<div class="character_skills">
			<h1>Investigator Skills</h1>
			<xsl:if test="description:image"> 
				<div class="character_portrait"><p><img alt="{description:image/@xlink:title}" src="{description:image/@xlink:href}"/></p></div>
			</xsl:if>
			<!--Skills next, as it is a full list generate a complete list of skills.-->
			<ul class="skills">
				<xsl:for-each select="skill">
					<xsl:sort order="ascending" select="@name"/>
					<xsl:choose>
					<xsl:when test="@sub='true'">
						<li><span class="name"><xsl:value-of select="@name"/></span><!--Display default value if the character doesn't have a speciality--><xsl:text> (</xsl:text><span class="value"><xsl:call-template name="stat-picker"><xsl:with-param name="stat" select="."/></xsl:call-template></span>)
							<ul class="subskills">
							<xsl:for-each select="./skill">
							  <li><span class="name"><xsl:value-of select="@name"/></span><xsl:text> </xsl:text><span class="value"><xsl:call-template name="stat-picker"><xsl:with-param name="stat" select="."/></xsl:call-template></span></li>
							</xsl:for-each>
							</ul>
						</li>
					</xsl:when>
					<xsl:otherwise>
						<li><span class="name"><xsl:value-of select="@name"/></span><xsl:text> </xsl:text><span class="value"><xsl:call-template name="stat-picker"><xsl:with-param name="stat" select="."/></xsl:call-template></span></li>
					</xsl:otherwise>
					</xsl:choose>
				</xsl:for-each>
			</ul>
			<div class="spacer"/>
		</div>
		
	</div>
</xsl:template>

<xsl:template name="stat-picker">
	<xsl:param name="stat"/>
	<xsl:choose>
		<xsl:when test="@value"><!--value should always be displayed first by choice (though non-summaries might also represent the max values-->
			<xsl:value-of select="@value"/>
		</xsl:when>
		<xsl:when test="@calculated"><!--this has a calculated value, which should be in an XPath form, TODO: need to find a way to make this execute-->
			<xsl:variable name="calculation" select="@calculated" />
			<xsl:value-of select="@base"/><!--temp fix-->
		</xsl:when>
		<xsl:when test="@base"><!--Use the base value-->
			<xsl:value-of select="@base"/>
		</xsl:when>
		<xsl:otherwise><!--Give the unknown value (00)-->
			<xsl:text>00</xsl:text>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

</xsl:stylesheet>
