<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:java="java:dk.uni_c.fig.interfaces.webservice"
  exclude-result-prefixes="xsi java" >

  <xsl:output method="html" encoding="UTF-8"/>

  <xsl:template match="/" xmlns:env="http://www.w3.org/2003/05/soap-envelope"
    xmlns:m="http://infoguide.emu.dk/">
    <div class="box norm">
      <div class="box-i">
        <xsl:apply-templates select="env:Envelope/env:Body/m:getPopularResponse/return/java:Request/java:Metode"/>
        <xsl:apply-templates select="env:Envelope/env:Body/m:getLatestResponse/return/java:Request/java:Metode"/>
        <xsl:apply-templates select="env:Envelope/env:Body/m:getCategoryResponse/return/java:Request/java:Metode"/>
        <xsl:apply-templates select="env:Envelope/env:Body/m:searchSimpleResponse/return/java:Request/java:Metode"/>
        <p>
          <xsl:apply-templates select="env:Envelope/env:Body/m:getPopularResponse/return/java:Result"/>
          <xsl:apply-templates select="env:Envelope/env:Body/m:getLatestResponse/return/java:Result"/>
          <xsl:apply-templates select="env:Envelope/env:Body/m:getCategoryResponse/return/java:Result"/>
          <xsl:apply-templates select="env:Envelope/env:Body/m:searchSimpleResponse/return/java:Result/item"/>
        </p>
      </div>
    </div>
  </xsl:template>

  <xsl:template match="java:Metode">
    <xsl:choose>
      <xsl:when test="text() = 'LatestLink'">
        <h4 class="box-first-h">Nyeste <xsl:apply-templates xmlns:env="http://www.w3.org/2003/05/soap-envelope"
          xmlns:m="http://infoguide.emu.dk/"
          select="/env:Envelope/env:Body/m:getLatestResponse/return/java:Request/java:Fag"/>
        </h4>
      </xsl:when>
      <xsl:when test="text() = 'PopularLink'">
        <h4 class="box-first-h">Mest bes&#248;gte <xsl:apply-templates xmlns:env="http://www.w3.org/2003/05/soap-envelope"
          xmlns:m="http://infoguide.emu.dk/"
          select="/env:Envelope/env:Body/m:getPopularResponse/return/java:Request/java:Fag"/>
        </h4>
      </xsl:when>
      <xsl:when test="text() = 'Category'">
        <h4 class="box-first-h">
          <xsl:apply-templates xmlns:env="http://www.w3.org/2003/05/soap-envelope"
            xmlns:m="http://infoguide.emu.dk/"
            select="/env:Envelope/env:Body/m:getCategoryResponse/return/java:Request/java:Antal_max"/>
          nyeste <xsl:apply-templates xmlns:env="http://www.w3.org/2003/05/soap-envelope"
            xmlns:m="http://infoguide.emu.dk/"
            select="/env:Envelope/env:Body/m:getCategoryResponse/return/java:Request/java:Fag"/>
        </h4>
      </xsl:when>
      <xsl:when test="text() = 'Search'">
        <h4 class="box-first-h">S&#248;gning efter &#34;<xsl:apply-templates
            xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:m="http://infoguide.emu.dk/"
          select="/env:Envelope/env:Body/m:searchSimpleResponse/return/java:Request/java:Soegning"/>&#34; <xsl:apply-templates xmlns:env="http://www.w3.org/2003/05/soap-envelope"
            xmlns:m="http://infoguide.emu.dk/"
            select="/env:Envelope/env:Body/m:searchSimpleResponse/return/java:Request/java:Fag"/>
        </h4>
      </xsl:when>
    </xsl:choose>
  </xsl:template>


  <xsl:template match="java:Fag">
    <xsl:variable name="fag">
      <xsl:call-template name="href_or_text"/>
    </xsl:variable>
    <xsl:choose>
      <xsl:when test="string-length($fag) = 0"> </xsl:when>
      <xsl:otherwise> fra <xsl:value-of select="$fag"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="java:Soegning | java:Antal_total | java:Antal_max | java:Url | java:Description">
    <xsl:call-template name="href_or_text"/>
  </xsl:template>

  <xsl:template match="item[@xsi:type='java:PopularLink']" xml:space="preserve">
    <xsl:apply-templates select="java:Title"/>
  	<xsl:apply-templates select="java:Current_count"/>
    <br/>
  </xsl:template>

  <xsl:template match="item[@xsi:type='java:LatestLink']" xml:space="preserve">
  	<xsl:apply-templates select="java:Did"/>
  	<xsl:apply-templates select="java:Title"/>
    <br/>
  </xsl:template>

  <xsl:template match="item[@xsi:type='java:Link']" xml:space="preserve">
    <p>
      <xsl:apply-templates select="java:Did"/>
      <xsl:apply-templates select="java:Title"/><br/>
      <xsl:apply-templates select="java:Description"/>
    </p>
  </xsl:template>

  <xsl:template match="java:Title">
    <xsl:variable name="title">
      <xsl:call-template name="href_or_text"/>
    </xsl:variable>
    <xsl:variable name="url" select="../java:Url"/>
    <strong>
      <a target="_new" href="{$url}" title="{$url}">
        <xsl:value-of select="$title"/>
      </a>
    </strong>
  </xsl:template>

  <xsl:template match="java:Current_count" xmlns:env="http://www.w3.org/2003/05/soap-envelope"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <em>
      <xsl:call-template name="href_or_text"/>
    </em>
  </xsl:template>

  <xsl:template match="java:Did">
    <xsl:variable name="did" select="text()"/>
    <a href="http://infoguide.emu.dk/BookcardProcessor.pub?catid=9&amp;descrid={$did}">
      <img class="FIGinfo" src="http://infoguide.emu.dk/images/info.gif" border="0"
        title="Se beskrivelsen i Fagenes Infoguide"/>
    </a>&#160;
  </xsl:template>

  <xsl:template match="java:Category_path">
    <span class="FIGkategorier">Kategorier</span>
    <ul class="FIGkategoriliste">
      <xsl:apply-templates/>
    </ul>
  </xsl:template>

  <xsl:template match="xsd:string" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <li exclude-result-prefixes="xsd">
      <xsl:call-template name="href_or_text"/>
    </li>
  </xsl:template>

  <!--#####################      FUNCTION 	#####################-->
  <xsl:template name="href_or_text" xmlns:env="http://www.w3.org/2003/05/soap-envelope"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsl:choose>
      <xsl:when test="@href">
        <xsl:variable name="id" select="@href"/>
        <xsl:value-of select="/env:Envelope/env:Body/xsd:string[@id=substring-after($id,'#')]"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="text()"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>

