<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  
  <xsl:output 
    method="html" 
    indent="yes" 
    doctype-public="-//W3C//DTD HTML 4.01//EN" 
    doctype-system="http://www.w3.org/TR/html4/strict.dtd"
    encoding="ISO-8859-1" />

  <xsl:param name="filename"/>

  <!-- Copy all nodes that don't match anything simply into the
  resulting .html -->
  <xsl:template match=" a | abbr | acronym | address | applet | area | b | base | basefont | 
    bdo | big | blockquote  | body | br | button | caption | cite | code | col | 
    colgroup | dd | del | dfn | dir | div | dl | dt | em | fieldset     | font | form | 
    frame | frameset | h1 | h2 | h3 | h4 | h5 | h6 | head | hr | html | i | iframe | img | 
    input | ins | isindex    | kbd | label | legend | li | link | map |  meta | 
    noframes | noscript | object | ol | optgroup | option | p     | param | pre | q | s | 
    samp | script | select | small | span | strike | strong | style | sub | sup | table | 
    tbody | td | textarea | tfoot | th | thead | title | tr | tt | u | ul | var">

    <xsl:copy>
      <xsl:copy-of select="@*"/>
      <xsl:apply-templates/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="text()">
    <xsl:value-of select="." />
  </xsl:template>

  <!-- Error out on all unknown tags -->
  <xsl:template match="*">
    <xsl:message terminate="yes">
      <xsl:text>Found unknown tag: </xsl:text>
      <xsl:text>"</xsl:text><xsl:value-of select="name()"/><xsl:text>"</xsl:text>
      <xsl:value-of select="." />
    </xsl:message>
  </xsl:template>

  <xsl:template match="dlink">
    <a href="{@href}"><xsl:value-of select="substring-after(@href,'http://savannah.nongnu.org/download/robovasion/dist/')"/></a>
  </xsl:template> 

  <xsl:template match="dlink-full">
    <a href="{@href}"><xsl:value-of select="@href"/></a>
  </xsl:template> 

  <xsl:template match="page">
    <html>
      <head>
        <title>Aleona's Tales - <xsl:value-of select="@title" /></title>
        <link rel="stylesheet" type="text/css" href="default.css" />
      </head>

      <body>
        <div style="background-color: #a4c4be;   border-style: solid;">
          <table width="100%"  cellspacing="0" cellpadding="0">
            <tr>
              <td align="center">
                <table width="60%"  style="margin: 0;" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td>
                      <a href="http://www.nongnu.org/aleona/"><img src="images/logo.png" style="margin: 0px; padding: 0px; border-style: none;" alt="Aleona's Tales" /></a>
                    </td>
                    <td align="center">
                      <xsl:apply-templates select="document('menu.xml')" />
                    </td>
                  </tr>
                </table>
                
                <table>
                  <tr>
                    <xsl:choose>
                      <xsl:when test="@group='races'">
                        <td align="center"><a class="submenuitem" href="races.html">Overview</a></td>
                        <td align="center"><a class="submenuitem" href="gormit-race.html">Gormits</a></td>
                        <td align="center"><a class="submenuitem" href="human-race.html">Humans</a></td>
                        <td align="center"><a class="submenuitem" href="mage-race.html">Mages</a></td>
                        <td align="center"><a class="submenuitem" href="forest-race.html">Forests</a></td>
                      </xsl:when>
                      <xsl:when test="@group='story'">
                        <td align="center"><a class="submenuitem" href="story.html">Story</a></td>
                        <td align="center"><a class="submenuitem" href="campaign.html">Campaign</a></td>
                      </xsl:when>
                      <xsl:otherwise>
                      </xsl:otherwise>
                    </xsl:choose>
                  </tr>
                </table>
              </td>
            </tr>
          </table>
        </div>
        
        <div style="background-color: #d2dddb;   border-style: solid; margin-top: .5em; padding: 0em 2em 1em 2em;">
          <xsl:apply-templates />
        </div>

        <div style="background-color: #a4c4be;   border-style: solid; margin-top: .5em; padding: .5em 2em .5em 2em;">
          <table width="100%" cellspacing="0" cellpadding="0">
            <tr>
              <td align="left" width="30%"><a href="https://savannah.nongnu.org/projects/aleona/">Aleona's Tales</a></td>
              <td align="center" width="40%">
                <a href="http://validator.w3.org/check/referer">html</a> / <a href="http://jigsaw.w3.org/css-validator/validator?uri=http%3A%2F%2Fwww.nongnu.org%2Faleona%2Fdefault.css&amp;warning=1&amp;profile=css2">css</a>
              </td>
              <td align="right" width="30%">Copyright &#169; 2002-2003 <a href="mailto:aleona-devel@nongnu.org">The Aleona Team</a></td>
            </tr>
          </table>
        </div>

      </body>
    </html>
  </xsl:template>

  
  <xsl:template match="section">
    <h2 id="{@title}"><xsl:value-of select="@title" /></h2>
    <xsl:apply-templates />
    <br clear="all" />
  </xsl:template>

  <xsl:template match="subsection">
    <h3><xsl:value-of select="@title" /></h3>
    <xsl:apply-templates />    
    <br clear="all" />
  </xsl:template>

  <xsl:template match="faq-list">
    <ul>
      <xsl:for-each select="faq/question">
        <li><a href="#faq{generate-id(.)}">
            <xsl:apply-templates/></a></li>
      </xsl:for-each>
    </ul>
    <hr/>
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="faq">
    <p></p>
    <table width="100%"  class="question">
      <colgroup width="60%" />
      <tr><td valign="top">
          <div id="faq{generate-id(question)}">
            <xsl:apply-templates select="question/node()"/>
          </div>
        </td>
        
        
        <td align="right" valign="top">
          <small>Last update:<xsl:value-of select="@date"/></small>
          [<small><a href="#faqtoc">Up</a></small>]
        </td>
      </tr>
    </table>

    <p class="answer"><xsl:apply-templates select="answer/node()"/> </p>
  </xsl:template>

  <xsl:template match="unit/description"><xsl:apply-templates /></xsl:template>
  <xsl:template match="unit/requires"><xsl:apply-templates /></xsl:template>
  <xsl:template match="unit/produced-in"><xsl:apply-templates /></xsl:template>
  <xsl:template match="unit/upgrades-to"><xsl:apply-templates /></xsl:template>
  <xsl:template match="unit/abilities"><xsl:apply-templates /></xsl:template>
  <xsl:template match="unit/field"><xsl:apply-templates /></xsl:template>
  <xsl:template match="unit/image"><xsl:apply-templates /></xsl:template>

  <xsl:template match="unit">
    <table cellspacing="0" cellpadding="0" width="100%">
      <tr><th colspan="2" align="left" style="border-bottom-style: solid;"><xsl:value-of select="name" /></th></tr>
      <tr>
        <td>
          <table cellspacing="0" cellpadding="0" width="100%" style="margin-bottom: 1em;">
            <colgroup>
              <col width="150" />
            </colgroup>

            <tr>
              <td valign="top">Description:</td>
              <td><xsl:apply-templates select="description" /></td>
            </tr>
            <tr>
              <td valign="top">Requires:</td>
              <td><xsl:apply-templates select="requires" /></td>
            </tr>      
            <tr>
              <td valign="top">Produced in:</td>
              <td><xsl:apply-templates select="produced-in" /></td>
            </tr>
            <tr>
              <td valign="top">Upgrades to:</td>
              <td><xsl:apply-templates select="upgrades-to" /></td>
            </tr>
            <tr>
              <td valign="top">Abilities:</td>
              <td><xsl:apply-templates select="abilities" /></td>
            </tr>

            <xsl:for-each select="field">
              <tr>
                <td valign="top"><xsl:value-of select="@name" /></td>
                <td><xsl:apply-templates select="." /></td>
              </tr>
            </xsl:for-each>
          </table>
        </td>
        <td>
          <xsl:if test="image!=''">
            <img src="{image}" alt="" style="float: right;" />
          </xsl:if>
        </td>
      </tr>
    </table>
  </xsl:template>

  <xsl:template match="newsbox">
    <div style="display: block; float: right; width: 30%; background-color: white; border-style: solid; border-color: black; padding: 2px; border-width: thin; margin-top: 1em; margin-left: .5em;">
      <div style="  background-color: #a4c4be; color: black; font-family: sans-serif;"><b>News</b></div>
      <dl class="newsbox">
        <xsl:apply-templates />
      </dl>
      <div align="right" style="margin: 0px;">
        <a href="news.html">Older News</a>
      </div>
    </div>
  </xsl:template>

  <xsl:template match="newsbox/item">
    <dt><b><xsl:value-of select="@date" /></b></dt>
    <dd><xsl:apply-templates /></dd>
  </xsl:template>

  <xsl:template match="menu">
    <table>
      <xsl:apply-templates />
    </table>
  </xsl:template>

  <xsl:template match="menu/row">
    <tr><xsl:apply-templates /></tr>
  </xsl:template>

  <xsl:template match="menu/row/item">
    <xsl:choose>
      <xsl:when test="@href=concat($filename, '.html')">
        <td><div class="menuitem"><a class="active" href="{@href}"><xsl:apply-templates /></a></div></td>
      </xsl:when>
      <xsl:otherwise>
        <td><div class="menuitem"><a href="{@href}"><xsl:apply-templates /></a></div></td>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>
