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

<!--
akffaq: xslt stylesheet for making FAQs
Copyright (c) 2008 Andreas K. Förster

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
-->

<!-- Download address relevant to section 13 of AGPLv3 -->
<xsl:param name="download" select="'http://akfoerster.de/akffaq/'"/>

<xsl:output method="html" encoding="UTF-8" doctype-system="about:legacy-compat"/>

<!-- hooks for site-specific definitions -->
<!-- can be overwritten by site-specific XSLT file -->
<xsl:template name="site-header"></xsl:template>
<xsl:template name="site-footer"></xsl:template>
<xsl:template name="site-htmlhead">
 <style type="text/css">
 <xsl:text>
 div#content { margin-left:10%; margin-right:10% }
 blockquote.question { font-size:110%; font-weight:bold; font-style:italic }
 @media screen { 
   h1, h2, blockquote.question { color:#631C0D } 
   code, pre.code-block, kbd { color:#000; background-color:#ddd; }
   }
 </xsl:text>
 </style>
</xsl:template>

<xsl:template match="/akffaq">
 <html>
 <xsl:if test="@xml:lang">
   <xsl:attribute name="lang"><xsl:value-of select="@xml:lang"/></xsl:attribute>
 </xsl:if>
 <head>
 <meta name="generator" content="akffaq"/>
 <xsl:choose>
 <xsl:when test="@title">
 <title><xsl:value-of select="@title"/></title>
 </xsl:when>
 <xsl:when test="heading">
 <title><xsl:value-of select="normalize-space(heading)"/></title>
 </xsl:when>
 <xsl:otherwise>
 <title>Frequently Asked Questions</title>
 </xsl:otherwise>
 </xsl:choose>
 <xsl:if test="@css">
   <link rel="stylesheet" type="text/css" href="{@css}"/>
 </xsl:if>
 <xsl:if test="@author">
   <meta name="author" content="{normalize-space(@author)}"/>
 </xsl:if>
 <xsl:if test="@description">
   <meta name="description" 
    content="{normalize-space(@description)}"/>
 </xsl:if>
 <xsl:call-template name="site-htmlhead"/>
 <style type="text/css">
 @media print, embossed { 
        div.back { display:none } 
        abbr, acronym { border-style:none }
        a:link, a:visited 
          { color:black; background-color:transparent;
            text-decoration:none }
        }
 </style>
 </head>
 <body>
 <xsl:call-template name="site-header"/>

 <div id="content">
 <xsl:apply-templates/>
 </div>

 <xsl:call-template name="site-footer"/>
 <div style="text-align:right">
 created using <a href="{$download}">AKFFAQ</a>
 </div>
 </body></html>
</xsl:template>

<xsl:template match="heading">
<h1><xsl:apply-templates/></h1>
</xsl:template>

<xsl:template match="overview">
<!-- attribute "back" is used in "answers" -->
<div class="overview" id="overview">
<xsl:for-each select="/akffaq/section">
  <xsl:if test="@title">
  <h2><a>
  <xsl:attribute name="href">
  <xsl:text>#</xsl:text>
  <xsl:choose>
  <xsl:when test="@id">
  <xsl:value-of select="@id"/>
  </xsl:when>
  <xsl:otherwise>
  <xsl:value-of select="generate-id()"/>
  </xsl:otherwise>
  </xsl:choose>
  </xsl:attribute>
  <xsl:value-of select="@title"/>
  </a></h2>
  </xsl:if>
  <ul>
  <xsl:for-each select="./question">
    <li><a>
    <xsl:attribute name="href">
    <xsl:text>#</xsl:text>
    <xsl:choose>
    <xsl:when test="@id">
    <xsl:value-of select="@id"/>
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="generate-id()"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:attribute>
    <xsl:apply-templates/>
    </a></li>
  </xsl:for-each>
  </ul>
</xsl:for-each>
</div>
</xsl:template>

<xsl:template match="section">
<hr/>
<xsl:if test="@title">
<h2>
<xsl:attribute name="id">
<xsl:choose>
<xsl:when test="@id">
<xsl:value-of select="@id"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="generate-id()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="@title"/></h2>
</xsl:if>
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="question">
<blockquote class="question">
<xsl:attribute name="id">
<xsl:choose>
<xsl:when test="@id">
<xsl:value-of select="@id"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="generate-id()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<p><xsl:apply-templates/></p></blockquote>
</xsl:template>

<xsl:template match="answer">
<div class="answer">
<xsl:apply-templates/>

<xsl:if test="/akffaq/overview/@back">
<div class="back"><a href="#overview">
<xsl:value-of select="/akffaq/overview/@back"/>
</a></div>
</xsl:if>

</div>
</xsl:template>

<xsl:template match="link">
<a><xsl:attribute name="href"><xsl:value-of select="."/></xsl:attribute>
<xsl:value-of select="."/></a>
</xsl:template>

<xsl:template match="quote">
<xsl:choose>
<xsl:when test=
"lang('de-ch') or lang('fr-ch') or lang('it') or lang('tr') or lang('gr') or lang('no') or lang('es') or lang('ru')">
&#xAB;<xsl:apply-templates/>&#xBB;
</xsl:when>
<xsl:when test=
"lang('de') or lang('nl') or lang('pl') or lang('ro') or lang('hu') or lang('cs') or lang('bg')">
&#x201E;<xsl:apply-templates/>&#x201C;
</xsl:when>
<xsl:when test="lang('fr')">
&#xAB;&#xA0;<xsl:apply-templates/>&#xA0;&#xBB;
</xsl:when>
<xsl:otherwise>&#x201C;<xsl:value-of select="."/>&#x201D;</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="a">
<xsl:copy>
<xsl:attribute name="href"><xsl:value-of select="@href"/></xsl:attribute>
<xsl:if test="@rel">
  <xsl:attribute name="rel"><xsl:value-of select="@rel"/></xsl:attribute>
</xsl:if>
<xsl:if test="@lang">
  <xsl:attribute name="lang"><xsl:value-of select="@lang"/></xsl:attribute>
</xsl:if>
<xsl:if test="@hreflang">
  <xsl:attribute name="hreflang">
  <xsl:value-of select="@hreflang"/>
  </xsl:attribute>
</xsl:if>
<xsl:value-of select="."/></xsl:copy>
</xsl:template>

<xsl:template match="abbr | acronym">
<xsl:copy>
<xsl:if test="@title">
 <xsl:attribute name="title"><xsl:value-of select="@title"/></xsl:attribute>
 <xsl:attribute name="style">cursor:help</xsl:attribute>
</xsl:if>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

<xsl:template match="p | em | ul | ol | li | kbd | code">
<xsl:copy><xsl:apply-templates/></xsl:copy>
</xsl:template>

<xsl:template match="pre">
<xsl:copy><xsl:apply-templates/></xsl:copy>
</xsl:template>

<xsl:template match="code-block">
<pre class="code-block"><xsl:value-of select="."/></pre>
</xsl:template>

</xsl:stylesheet>


