<?xml version="1.0" encoding="utf-8"?>
<!--
This is an XSL stylesheet, meant to be processed by an XSLT processor with a
keyboard mapping file as input, to produce an HTML file as output. -->
<!--	Steve White wrote this.  That is, © 2003 Steve White. -->
<xsl:stylesheet
	version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:xhtml="http://www.w3.org/1999/xhtml"
	xmlns="http://www.w3.org/1999/xhtml"
	exclude-result-prefixes="xhtml"
	>
<xsl:output
	method="xml" encoding="utf-8" version="1.0"
	doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
	doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
	indent="yes" 
	media-type="application/xhtml+xml"
	/>
	<!--
	omit-xml-declaration="yes"
	/>
	-->
<xsl:preserve-space elements="*" /> 

<xsl:template match="/">
	<html>
	<head>
	<title>Computer Keyboard</title>
	<meta name="author" content="Steve White" />
	<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
	<meta http-equiv="content-script-type" content="text/javascript" />
	<link rel="icon" href="bm_icon" type="image/png" />
	<link rel="stylesheet" href="../keyboard.css" type="text/css"/>
	</head>
	<body>
		<xsl:for-each select="keyboard">
			<xsl:call-template name="keyboard">
			</xsl:call-template>
		</xsl:for-each>
	<p>
		<a class="about" href="../about.html">About the keyboards</a>
	</p>  
	</body>
	</html>
</xsl:template>

<xsl:template name="spacers">
	<xsl:param name="num" select='60' />
	<xsl:choose>
		<xsl:when test='$num > 0'>
			<xsl:element name="td">
				<xsl:text>&#160;</xsl:text>
			</xsl:element>
			<xsl:call-template name="spacers">
				<xsl:with-param name="num" select='$num - 1'/>
			</xsl:call-template>
		</xsl:when>
	</xsl:choose>
</xsl:template>

<xsl:template name="keyboard">
	<xsl:variable name="textDirection">
		<xsl:choose>
			<xsl:when test='@dir'>
				<xsl:value-of select="@dir"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="ltr"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>

	<xsl:variable name="JS_warning">
		<xsl:choose>
			<xsl:when test='@JS_warning'>
				<xsl:value-of select="@JS_warning"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:text>This keyboard won’t work because your
				browser isn’t running JavaScript.</xsl:text>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>

	<xsl:variable name="inittext">
		<xsl:choose>
			<xsl:when test='inittext'>
				<xsl:value-of select="inittext"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:text>Type here. </xsl:text>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>

	<script type="text/javascript"></script>
	<noscript>
		<p class="JS_warning"><em> 
			<xsl:value-of select="$JS_warning" /> 
		</em></p>
	</noscript>

	<h1><span lang="{@language}"><xsl:value-of select="@name" /></span>
		(<xsl:value-of select="@altname" />)
	</h1>

	<form action="#" id="keyboardForm" onsubmit="return false;" >
	<table id="keyboard" class="PCKeyboard" border="1" cellpadding="0" cellspacing="2">
	<tr class="spacers"><td colspan="60">
			<!-- xsltproc incorrectly squishes this to a
			self-terminating tag if it is empty -->
	<textarea id="display" readonly="readonly"
		cols="60" rows="4" dir="{$textDirection}" lang="{@language}"
		><xsl:value-of select="$inittext" /></textarea>

	</td></tr>
	<tr class="spacers">
		<xsl:call-template name="spacers"/>
	</tr>

	<!-- cuz I don't know how to put an attribute into a with-param -->
	<xsl:variable name="tmpl" select="@language"/>

	<xsl:for-each select="row">
		<tr class="keys">
		<xsl:for-each select="key">
			<xsl:call-template name="key">
				<xsl:with-param name="language" select="$tmpl" />
			</xsl:call-template>
		</xsl:for-each>
		</tr>
	</xsl:for-each>

	</table>
	</form>
	<script type="text/javascript" src="../keyboard.js">
	</script>
</xsl:template>

<xsl:template name="key">
	<xsl:param name="language">en</xsl:param>

	<xsl:variable name="keyWidth">
		<xsl:choose>
			<xsl:when test='@width'>
				<xsl:value-of select="@width"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select='4'/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	<xsl:variable name="rowspan">
		<xsl:choose>
			<xsl:when test='@rowspan'>
				<xsl:value-of select="@rowspan"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select='1'/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	<!-- onmouseover="doHover()"
		onmousedown="doClick('{@id}')"
		onmouseup="doRelease('{@id}')" onmouseout="doRelease('{@id}')"
	-->
	<td id="Key-{@id}" colspan="{$keyWidth}" rowspan="{$rowspan}">
	<table class="key"><tr>
	<td class="label">
	<xsl:choose>
		<xsl:when test='label'>
			<xsl:value-of select="label"/>
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="@id"/>
		</xsl:otherwise>
	</xsl:choose>
	</td>
	<td lang="{$language}">
	<xsl:choose>
		<xsl:when test='uc'>
			<xsl:value-of select="uc"/>
		</xsl:when>
	</xsl:choose>
	</td></tr>
	<tr>
	<td lang="{$language}" class="alt">
	<xsl:choose>
		<xsl:when test='alt'>
			<xsl:value-of select="alt"/>
		</xsl:when>
	</xsl:choose>
	</td>
	<td lang="{$language}">
	<xsl:choose>
		<xsl:when test='lc'>
			<xsl:value-of select="lc"/>
		</xsl:when>
	</xsl:choose>
	</td></tr>
	</table>
	</td>  
</xsl:template>

<xsl:template name="uc">
</xsl:template>

</xsl:stylesheet>

