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

  <xsl:import href="../../../system/api-v001.xsl" /> 
  <xsl:import href="../../../felles/komponenter/overskrift/v001/overskrift.xsl"/>
  <xsl:import href="../../../felles/komponenter/tabell/v001/tabell.xsl"/>
  <xsl:import href="../../ressurser/indexnumber-v001.xsl" /> 
  <xsl:import href="../../ressurser/diverse-v001.xsl" /> 
  <xsl:import href="../../komponenter/saksinfo/v001/saksinfo.xsl"/>


  <xsl:include href="../../../felles/ressurser/output-method-html-v001.xsl" />

  <xsl:template match="/">
    <head>
      <title><xsl:value-of select="/reglement/tittel"/></title>
      <meta name="redaksjon.navn" content="Admhb" />
      <meta name="redaksjon.vev" content="http://www.admin.uio.no/opa/opaorg.html" />
      <meta name="keywords" content="Regelh&#229;ndbok" />
    </head>
    <body>
      <xsl:call-template name="sti-og-sokeboks" />
      <xsl:apply-templates />
      <xsl:call-template name="skriv-ut-fotnoter" />
      <xsl:call-template name="bunnsignatur" />
   </body>
  </xsl:template>
 
  <xsl:template match="reglement">
    <xsl:apply-templates />
  </xsl:template>

  <xsl:template match="tittel">
    <xsl:variable name="last-token-pos"> 
      <xsl:call-template name="find-last-pos">
        <xsl:with-param name="string" select="$CURRENT-URL" />
      </xsl:call-template>
    </xsl:variable>

    <h1>
      <xsl:call-template name="indexnumber">
        <xsl:with-param name="indexfolder" select="$PARENT-COLLECTION" /> <!-- variabel spesifisert i resurser/indexnumber.xsl -->
        <xsl:with-param name="lookupname" select="substring($CURRENT-URL, $last-token-pos + 1, string-length($CURRENT-URL))" /> <!-- filnavnet -->
        </xsl:call-template>
        <xsl:text>:</xsl:text>&#160;
      <xsl:value-of select="." />
    </h1>
  </xsl:template>

  <!-- ******************************************************************** -->
  <!-- * Templates for fritekst (dvs. avsnitt, liste og listepunkt med    * -->
  <!-- * tilhørende underelementer                                        * -->
  <!-- ******************************************************************** -->

  <xsl:template match="avsnitt">
    <xsl:if test="not(.='')">
      <p><xsl:apply-templates /></p>
    </xsl:if>
  </xsl:template>

  <xsl:template match="liste">
    <xsl:if test="not(.='')"> 
      <xsl:choose>
        <xsl:when test="@type='bokstav'">
          <ol type="A"><xsl:apply-templates /></ol>          
        </xsl:when>
        <xsl:when test="@type='tall'">
          <ol><xsl:apply-templates /></ol>          
        </xsl:when>
        <xsl:otherwise> <!-- @type='punkt' er defaultverdi i schema -->
          <ul><xsl:apply-templates /></ul>          
        </xsl:otherwise> 
      </xsl:choose>
    </xsl:if>
  </xsl:template>

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

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

  <xsl:template match="kursiv">
    <i><xsl:value-of select="."/></i>
  </xsl:template>

  <xsl:template match="weblenke">
    <a href="{webadresse}"><xsl:value-of select="lenketekst"/></a>
  </xsl:template>

  <xsl:template match="epost">
    <a href="mailto:{.}"><xsl:value-of select="." /></a>
  </xsl:template>

  <xsl:template match="fotnote">
    <xsl:variable name="nummer">
      <xsl:number level="any" />
    </xsl:variable>
    <a href="{concat('#fotnote',$nummer)}"><sup><xsl:value-of select="concat('Fotnote ',$nummer)" /></sup></a>
  </xsl:template>


  <!-- ******************************************************************** -->
  <!-- * Hjelpetemplater                                                  * -->
  <!-- ******************************************************************** -->

  <xsl:template name="skriv-ut-fotnoter">
    <xsl:if test="//fotnote[1]"> <!-- hvis det finnes fotnoe i dokumentet -->
      <h2>Fotnoter</h2>
      <ol>
        <xsl:for-each select="//fotnote">
          <li id="{concat('fotnote',position())}"><xsl:value-of select="." /></li>
        </xsl:for-each>
      </ol>
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>

