<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html" indent="yes" encoding="UTF-8" 
  doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
  doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />

<!-- The XSL parameter that indicates the language we want. Defaults to English (en) -->  
<xsl:param name="language" select="en" />
  
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title>The Constellations</title>
</head>

<body>
<xsl:apply-templates select="constellations"/>
</body>
</html>
</xsl:template>

<xsl:template match="constellations">
<table border="1">
<caption>Names of the constellations in '<xsl:value-of select="$language" />'</caption>
<tr>
<th>Abbr</th>
<th>Latin</th>
<th>Name</th>
</tr>
<xsl:apply-templates select="const">
  <xsl:sort select="@abbr" />   <!-- sort alphabetically by abbreviation -->
</xsl:apply-templates>  
</table>
</xsl:template>

<xsl:template match="name">
</xsl:template>

<xsl:template match="genetive">
</xsl:template>

<xsl:template match="const">
<tr>
<td><xsl:value-of select="@abbr"/></td>
<td><xsl:value-of select="name"/></td>
<xsl:apply-templates />
</tr>
</xsl:template>

<xsl:template match="trans">
<td>
<xsl:choose>
<xsl:when test="$language='ja'"> 
<ruby>
  <rb><xsl:value-of select="text[@xml:lang=$language]"/></rb>
  <rt><xsl:value-of select="alternate-text[@xml:lang=$language]"/></rt>
</ruby>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="text[@xml:lang=$language]"/>
<xsl:if test="count(alternate-text[@xml:lang=$language])!=0">
(
<xsl:for-each select="alternate-text[@xml:lang=$language]">
  <xsl:value-of select="."/><xsl:if test="not(position()=last())">, </xsl:if>
</xsl:for-each>
)
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</td>
</xsl:template>


</xsl:stylesheet>

