<?xml version="1.0" encoding="iso-8859-2" ?>
<!-- $Id: pmla2h.xsl,v 1.1.1.1 2003/01/02 21:00:55 tomek Exp $ -->
<!-- Szablon formatujący uproszczony dokument typu pmla do HTMLa  -->
<!-- (c) t. przechlewski, 2002 (tomasz@gnu.univ.gda.pl)           -->
<!-- Zezwala się na wykorzystanie na warunkach licencji GPL       -->
<!-- patrz: //www.gnu.org/licenses/gpl.html                       -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

  <xsl:output method="html"
       encoding="iso-8859-2"
       doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" 
       indent="no"
       saxon:character-representation="native;decimal"
       xmlns:saxon="http://icl.com/saxon" />

<!-- ========== tytulatura: =================================== -->
  <xsl:template match="/">
    <html>
      <head>
      <title>
       <xsl:value-of select="/article/title"/>
      </title>
      </head>
      <body bgcolor="white">
        <!-- ;;; tytulatura: tytuł/autor/email ;;; -->
        <h2><xsl:value-of select="/article/title"/></h2>
        <xsl:text>&#10;</xsl:text>
        <p><xsl:value-of select="/article/author"/></p>
        <xsl:text>&#10;</xsl:text>
        <p><xsl:value-of select="/article/email"/></p>
        <xsl:text>&#10;</xsl:text>
        <hr/>
        <!-- ;;; spisek treściwy ;;; -->
        <xsl:call-template name="toc"/>
        <hr/>
        <xsl:apply-templates/>
      </body>
    </html>
  </xsl:template>

<!-- ========== spis treści =================================== -->
  <xsl:template name="toc">
    <div>
      <h2>Spis treści</h2>
      <xsl:apply-templates select="//section | //subsection | 
          //subsubsection | //abstract" mode="toc"/>
    </div>
  </xsl:template>

  <xsl:template match="article/title|article/author|article/email"/>

<xsl:template match="section" mode="toc">
  <div>
   <a href="#{generate-id(.)}">
   <xsl:apply-templates select="title" mode="toc"/>
   </a>
  </div>
  <xsl:text>&#10;</xsl:text>
</xsl:template>

<xsl:template match="subsection" mode="toc">
  <div>
   <a href="#{generate-id(.)}">
   <xsl:apply-templates select="title" mode="toc"/>
   </a>
  </div>
  <xsl:text>&#10;</xsl:text>
</xsl:template>

<xsl:template match="subsubsection" mode="toc">
  <div>
   <a href="#{generate-id(.)}">
   <xsl:apply-templates select="title" mode="toc"/>
   </a>
  </div>
  <xsl:text>&#10;</xsl:text>
</xsl:template>

<xsl:template match="section/title" mode="toc">
  <xsl:apply-templates/> 
</xsl:template>

<xsl:template match="abstract" mode="toc">
 <a href="#abstract"> Streszczenie </a>
</xsl:template>

<xsl:template match="subsection/title" mode="toc">
  <xsl:apply-templates/> 
</xsl:template>

<xsl:template match="subsubsection/title" mode="toc">
  <xsl:apply-templates/> 
</xsl:template>

<!-- ========== elementy struktury blokowej [bez wyliczeń]: === -->

<xsl:template match="section | subsection | subsubsection ">
  <xsl:variable name="id" select="generate-id()"/>
  <div>
    <!-- wstaw <a name jeżeli `figure' ma atrybut `id'      -->
    <xsl:if test="@id"> <A name="{@id}"/> </xsl:if>
    <!-- wstaw drugą <a name do spisu treści                -->
    <a name="{$id}"/>
    <xsl:apply-templates/>
  </div>
</xsl:template>

  <xsl:template match="section/title">
    <h2> <xsl:apply-templates/> </h2>
  </xsl:template>

  <xsl:template match="abstract">
    <div> <a name="abstract"/> <h3>Streszczenie</h3>
    <xsl:apply-templates/>
    </div>
  </xsl:template>

  <xsl:template match="subsection/title">
    <h3> <xsl:apply-templates/> </h3>
  </xsl:template>

  <xsl:template match="subsubsection/title">
    <h4> <xsl:apply-templates/> </h4>
  </xsl:template>

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

  <xsl:template match="para">
    <p> <xsl:apply-templates/> </p>
  </xsl:template>

<!-- ========== elementy wierszowe [inline]: ================== -->
  <xsl:template match="verb">
    <code> <xsl:apply-templates/> </code>
  </xsl:template>

  <xsl:template match="emph">
    <em> <xsl:apply-templates/> </em>
  </xsl:template>

<!-- ============ wyliczenia ================================== -->
  <xsl:template match="itemize">
    <ul> <xsl:apply-templates/> </ul>
  </xsl:template>

  <xsl:template match="enumerate">
    <ol> <xsl:apply-templates/> </ol>
  </xsl:template>

  <xsl:template match="item">
    <li> <xsl:apply-templates/> </li>
  </xsl:template>

  <xsl:template match="description">
    <dl> <xsl:apply-templates/> </dl>
  </xsl:template>

  <xsl:template match="term">
    <dt> <xsl:apply-templates/> </dt>
  </xsl:template>

  <xsl:template match="descr">
    <dd> <xsl:apply-templates/> </dd>
  </xsl:template>

<!-- ============ rysunki ================================== -->
  <xsl:template match="figure">
    <div class="figure">
     <!-- wstaw <a name jeżeli `figure' ma atrybut `id'      -->
     <xsl:if test="@id"> <A name="{@id}"/> </xsl:if>
     <xsl:apply-templates select="graphic"/>
     <!-- wstaw ostrzeżenie jeżeli nie ma elementu graphic   -->
     <!-- o wartości atrybutu `format' równej png            -->
     <xsl:if test="not(./graphic[@format='PNG' or 
        @format='JPG' or @format='GIF'])">
       <xsl:text>**rysunek**</xsl:text>
     </xsl:if>
     <xsl:apply-templates select="title"/>
    </div>
  </xsl:template>

  <xsl:template match="graphic[@format='PNG'
      or @format='JPG' or @format='GIF'][position()=1]">
    <!-- pierwszy element zawierający PNG/JPG lub GIF -->
    <img src="{@src}" alt="{../title}"/>
  </xsl:template>

  <xsl:template match="figure/title">
    <div class="figuretitle">
     <xsl:text>Rysunek: </xsl:text>
     <xsl:apply-templates/>
    </div>
  </xsl:template>

<!-- ============ bibliografia ============================= -->
<!-- Dodać bibliografię do spisu treści                      -->
  <xsl:template match="bibliography">
    <h2>Bibliografia</h2>
    <ol>
     <xsl:apply-templates/>
    </ol>
  </xsl:template>

  <xsl:template match="bibitem">
    <li><p><A name="{@id}"/>
      <xsl:apply-templates/> </p></li>
  </xsl:template>

  <!-- Ustalenie numeru pozycji bibliograficznej w spisie; szablon        -->
  <!-- wywoływany przez `cite'                                            -->
  <xsl:template match="bibitem" mode="xref">
    <xsl:number value="count(preceding::bibitem) +1" format="1" />
  </xsl:template>

  <xsl:template match="cite">
    <xsl:variable name="text" select="normalize-space(text())"/>
    <xsl:variable name="bibliolab" select="@src"/>
    <xsl:text>[</xsl:text>
     <a class="bibcite" href="#{@src}">
      <xsl:apply-templates select="//bibitem[@id=$bibliolab]" mode="xref"/>
      <xsl:if test="string-length($text) &gt; 0">
       <xsl:text>, </xsl:text>
       <xsl:value-of select="."/> 
      </xsl:if>
     </a>
    <xsl:text>]</xsl:text>
  </xsl:template>

<!-- =============== inne ============================== -->
  <xsl:template match="url">
  <!-- jezeli zawartosc elementu url jest pusta skopiuj  -->
  <!-- atrybut `src' jako wartosc htmlowego elementu <a> -->
    <xsl:variable name="text" select="normalize-space(text())"/>
    <xsl:choose>
     <xsl:when test="string-length($text) &lt; 1">
       <a href="{@src}">
         <code><xsl:value-of select="@src"/></code> 
       </a>
     </xsl:when>
     <xsl:otherwise>
       <a href="{@src}">
        <code> <xsl:value-of select="."/></code> 
       </a>
     </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  
  <xsl:template match="ref">
    <xsl:variable name="reflabel" select="@src"/>
    <a class="ref" href="#{@src}">
     <!-- wstaw tytuł elementu do którego jest odesłanie:  -->
     <!-- źle: <xsl:value-of select="//*[@id=@src]/title" />         -->
     <!-- źle: <xsl:value-of select="//*[@id='$reflabel']/title" />  -->
     <xsl:value-of select="//*[@id=$reflabel]/title" /> 
    </a>
  </xsl:template>

  <xsl:template match="footnote" >
    <xsl:text>[Przypis: </xsl:text>
      <xsl:apply-templates/>
    <xsl:text>]</xsl:text>
  </xsl:template>

  <!-- wersja html nie ma skorowidza: -->
  <xsl:template match="index"/>

</xsl:stylesheet>

