<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

  <xsl:output method="html"/>

  <xsl:template match="/faq">
    <html>
      <head>
        <title><xsl:value-of select="@name" /></title>
        <link rel="stylesheet" href="infobahn.css" type="text/css" />
      </head>

      <body>
        <h1 align="center"><xsl:value-of select="@name" /></h1>

        <xsl:call-template name="show_description" />

        <!-- show the list of maintainers -->
        <xsl:call-template name="show_maintainers" />

        <!-- create the table of contents -->
        <a name="table_of_contents" />
        <xsl:call-template name="show_table_of_contents" />

        <hr />

        <!-- now display the actual contents of the FAQ -->
        <xsl:call-template name="display_faqs" />

        <hr />

        <font size="-1">
          This document was generated automatically using <strong>faq2html.xsl</strong>, by 
          <a href="mailto:mcpierce@myrealbox.com?subject=faq2html.xsl">Darryl L. Pierce</a>.<br />
          You may use the stylesheet for your own purposes, but this authorship notice <em>MUST</em> remain intact.
        </font>
      </body>
    </html>
  </xsl:template>

  <!-- shows the description for the FAQ -->
  <xsl:template name="show_description">
    <xsl:if test="description!=''">
      <table align="center" bgcolor="lightGreen" cellpadding="5" width="75%">
        <tr>
          <td>
            <xsl:for-each select="description">
              <xsl:apply-templates />
            </xsl:for-each>
          </td>
        </tr>
      </table>
    </xsl:if>
  </xsl:template>

  <!-- takes the list of person tags and converts it into an unsorted list,
       complete with homepage reference if included -->
  <xsl:template name="show_maintainers">
    <h3>Maintained by:</h3>
    <ul>
      <xsl:for-each select="maintainers/person">
        <li>
          <xsl:element name="a">
            <xsl:attribute name="href">
              mailto:<xsl:value-of select="@email" />
            </xsl:attribute>
            <xsl:value-of select="@name" />
          </xsl:element>
          
          <xsl:if test="@homepage!=''">
            [
            <xsl:element name="a">
              <xsl:attribute name="href">
                <xsl:value-of select="@homepage" />
              </xsl:attribute>
              homepage
            </xsl:element>
            ]
          </xsl:if>
        </li>
      </xsl:for-each>
    </ul>
  </xsl:template>
  
  <!-- displays a table of contents displaying the topics and questions 
       for this FAQ -->
  <xsl:template name="show_table_of_contents">
    <h2>Table of Contents</h2>
    <ol>
      <xsl:for-each select="topics/topic">
        <li>
          <xsl:element name="a">
            <xsl:attribute name="href">
              #<xsl:value-of select="@name" />
            </xsl:attribute>
            <xsl:attribute name="rel">
              chapter
            </xsl:attribute>
            <xsl:value-of select="@description" />
          </xsl:element>          
        </li>

        <ol>
          <xsl:for-each select="question">
            <li>
              <xsl:element name="a">
                <xsl:attribute name="href">
                  #<xsl:value-of select="@name" />
                </xsl:attribute>
                <xsl:attribute name="rel">
                  section
                </xsl:attribute>
                <xsl:value-of select="@text" />
              </xsl:element>
            </li>
          </xsl:for-each>
        </ol>
      </xsl:for-each>
    </ol>
  </xsl:template>

  <xsl:template name="display_faqs">    
  <xsl:element name="ol">
    <xsl:for-each select="topics/topic">
      <xsl:element name="a">
        <xsl:attribute name="name">
          <xsl:value-of select="@name" />
        </xsl:attribute>
      </xsl:element>

      <h2><xsl:element name="li"><xsl:value-of select="@description" /></xsl:element></h2>

      <xsl:element name="ol">
        <xsl:for-each select="question">
          <xsl:element name="a">
            <xsl:attribute name="name">
              <xsl:value-of select="@name" />
            </xsl:attribute>
          </xsl:element>
          
          <xsl:element name="li">
            <em><xsl:value-of select="@text" /></em>
            
            <blockquote><xsl:apply-templates /></blockquote>
            
            <font size="-1">
              <p /><a href="#table_of_contents" rel="contents">Table of Contents</a>
            </font>
          </xsl:element>
          
        </xsl:for-each>
      </xsl:element>

    </xsl:for-each>
  </xsl:element>
  </xsl:template>

  <xsl:template match="a">
    <xsl:copy-of select="." />
  </xsl:template>

  <xsl:template match="b">
    <xsl:copy-of select="." />
  </xsl:template>

  <xsl:template match="cite">
    <xsl:copy-of select="." />
  </xsl:template>

  <xsl:template match="code">
    <xsl:element name="pre">
      <xsl:apply-templates />
    </xsl:element>
  </xsl:template>

  <xsl:template match="p">
    <xsl:copy-of select="." />
  </xsl:template>

  <xsl:template match="pre">
    <xsl:copy-of select="." />
  </xsl:template>

  <xsl:template match="table">
    <xsl:copy-of select="." />
  </xsl:template>

  <xsl:template match="ul">
    <xsl:copy-of select="." />
  </xsl:template>

</xsl:stylesheet>
