<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet 
    version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns="http://www.w3.org/1999/xhtml">

<xsl:output method="xml" encoding="UTF-8" indent="yes" />

<!-- The XSL parameter that indicates the language we want. Defaults to English (en). -->  
<xsl:param name="language">en</xsl:param>

<!-- Another XSL parameter indicates the hemisphere. The value is either N or S,
or empty. If the value is empty, constellations in both hemispheres are included.
Defaults to empty.  -->
<xsl:param name="hemisphere" />
  
<xsl:template match="/">
<xsl:apply-templates select="constellations" />
</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" />

<!-- Suppress the "genetive" element, it is not shown in the results. -->
<xsl:template match="genetive" />

<xsl:template match="const">
<tr>
<td><xsl:value-of select="@abbr" /></td>
<td><xsl:value-of select="name" /></td>
<xsl:apply-templates select="trans" />
</tr>
</xsl:template>

<xsl:template match="trans">
<td>
<xsl:choose>
<!-- Japanese is a special case: if there is alternate text for it, use ruby markup -->
<xsl:when test="$language='ja'"> 
<ruby>
  <rb><xsl:value-of select="text[@xml:lang = $language]" /></rb>
  <rp>(</rp><rt><xsl:value-of select="alternate-text[@xml:lang = $language]" /></rt><rp>)</rp>
</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>

