<?xml version="1.0"?>
<?xml-stylesheet href="/pool/xslt_ht.xslt" type="application/xml"?>
<xsl:stylesheet
  xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"
  xmlns:d = "http://herbaer.de/xmlns/20051201/doc"
  xmlns:ht = "http://www.w3.org/1999/xhtml"
  xmlns = "http://www.w3.org/1999/xhtml"
  xmlns:sm = "http://www.sitemaps.org/schemas/sitemap/0.9"
  xmlns:c = "http://www.google.com/codesearch/schemas/sitemap/1.0"
  xmlns:t = "http://herbaer.de/xmlns/20110907/terms"
  exclude-result-prefixes = "xsl d ht sm c t"
  version = "1.0"
>

<d:info xmlns="http://herbaer.de/xmlns/20051201/doc">
  <title>sitemap_ht_ni.xslt</title>
  <subtitle>XHTML-Darstellung einer Sitemap ohne Bilder</subtitle>
  <date>2012-08-25</date>
  <author>
    <personname>
      <firstname>Herbert</firstname>
      <surname>Schiemann</surname>
    </personname>
    <email>h.schiemann@herbaer.de</email>
  </author>
</d:info>

<d:para>Die Website: URL der Wurzel</d:para>
<xsl:param name="p_baseurl">
  <xsl:variable name="loc" select="//sm:loc [1]"/>
  <xsl:if test="starts-with ($loc, 'http://')">
    <xsl:text>http://</xsl:text>
    <xsl:variable name="l2" select="substring-after ($loc, 'http://')"/>
    <xsl:choose>
      <xsl:when test="contains ($l2, '/')">
        <xsl:value-of select="substring-before ($l2, '/')"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$l2"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:if>
</xsl:param>

<d:para>
Relative Adresse der Wurzel.
Sie wird verwendet, wenn eine "location" mit "./" beginnt.
Nur die "Sitemap" der DVD enthält relative Adressen.
</d:para>
<xsl:param name="p_relbase" select="'../dvd/'"/>

<d:para>Die Länge der Basis-URL</d:para>
<xsl:variable name="g_baselen" select="string-length ($p_baseurl)"/>

<xsl:variable name="g_terms" select="document('')/xsl:stylesheet/t:terms"/>

<xsl:output method="xml" encoding="utf-8"/>

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

<d:para>
Der HTML-Rahmen
</d:para>
<xsl:template match="sm:urlset">
  <xsl:variable
    name = "title"
    select = "
      concat (
      'Sitemap ', substring-before (substring-after (sm:url[1]/sm:loc, 'http://'), '/') )
    "
  />
  <html>
    <head>
      <title><xsl:value-of select="$title"/></title>
      <xsl:element name="style">
        <xsl:attribute name="type">text/css</xsl:attribute>
        <xsl:text>
/* CSS-Regeln für eine Tabelle */
td + td             {padding-left: 1em; }
thead               {font-weight: bold; }
td[class~="date"]   {text-align: center; }
td[class~="number"] {text-align: right; }
td                  {vertical-align: top; }

/* Spaltenköpfe sortierbarer Tabellen */
table[class~="tabsort"] &gt; thead &gt; tr &gt; td[class~="date"]   {cursor: pointer; }
table[class~="tabsort"] &gt; thead &gt; tr &gt; td[class~="number"] {cursor: pointer; }
table[class~="tabsort"] &gt; thead &gt; tr &gt; td[class~="text"]   {cursor: pointer; }
        </xsl:text>
      </xsl:element>
      <xsl:element name="script">
        <xsl:attribute name="src">/pool/tabsort.js</xsl:attribute>
        <xsl:attribute name="type">text/javascript; charset=utf-8</xsl:attribute>
      </xsl:element>
      <xsl:element name="script">
        <xsl:attribute name="type">text/javascript</xsl:attribute>
        <xsl:text>
onload = function () {tabsort_initialize ();}
        </xsl:text>
      </xsl:element>
    </head>
    <body>
      <h1><xsl:value-of select="$title"/></h1>
      <table class="tabsort">
        <thead>
          <tr>
            <td class="text">Ort</td>
            <td class="date">geändert</td>
            <td class="text">Aktualisierung</td>
            <td class="number">Prio</td>
            <td class="text">Typ</td>
          </tr>
        </thead>
        <tbody>
          <xsl:apply-templates select="sm:url"/>
        </tbody>
      </table>
    </body>
  </html>
</xsl:template>

<d:para>
Eintrag zu einem Dokument
</d:para>
<xsl:template match="sm:url">
  <tr>
    <td><xsl:apply-templates select="sm:loc"/></td>
    <td><xsl:apply-templates select="sm:lastmod"/></td>
    <td><xsl:apply-templates select="sm:changefreq"/></td>
    <td><xsl:apply-templates select="sm:priority"/></td>
    <td><xsl:apply-templates select="c:codesearch/c:filetype"/></td>
  </tr>
</xsl:template>

<d:para>
Die URL mit einem Verweis
</d:para>
<xsl:template match="sm:loc">
  <a>
    <xsl:attribute name="href">
      <xsl:choose>
        <xsl:when test="starts-with (., './')">
          <xsl:value-of select="concat ($p_relbase, substring-after (., './'))"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="."/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:attribute>
    <xsl:choose>
      <xsl:when test="starts-with (., $p_baseurl) and string-length (.) &gt; $g_baselen">
        <xsl:value-of select="substring (., $g_baselen + 1)"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates/>
      </xsl:otherwise>
    </xsl:choose>
  </a>
</xsl:template>

<d:para>
Datum der letzten Änderung
</d:para>
<xsl:template match="sm:lastmod">
  <xsl:if test="string-length(.) &gt; 9">
    <xsl:value-of
      select = "
        concat ( substring (., 9, 2), '.', substring (., 6, 2), '.', substring (., 1, 4) )
      "
    />
  </xsl:if>
</xsl:template>

<d:para>
Änderungshäufigkeit
</d:para>
<xsl:template match="sm:changefreq">
  <xsl:variable name="f" select="."/>
  <xsl:value-of select="$g_terms/t:term [t:key = $f]/t:val"/>
</xsl:template>

<d:para>
Dateityp: "Übersetzung" suchen
</d:para>
<xsl:template match="c:codesearch/c:filetype">
  <xsl:variable name="f" select="."/>
  <xsl:apply-templates select="$g_terms/t:term [t:key = $f]/t:val"/>
</xsl:template>

<t:terms>
  <!-- Änderungshäufigkeit -->
  <t:term><t:key>always</t:key><t:val>immer</t:val></t:term>
  <t:term><t:key>hourly</t:key><t:val>stündlich</t:val></t:term>
  <t:term><t:key>daily</t:key><t:val>täglich</t:val></t:term>
  <t:term><t:key>weekly</t:key><t:val>wöchentlich</t:val></t:term>
  <t:term><t:key>monthly</t:key><t:val>monatlich</t:val></t:term>
  <t:term><t:key>yearly</t:key><t:val>jährlich</t:val></t:term>
  <t:term><t:key>never</t:key><t:val>nie</t:val></t:term>

  <!-- Dateityp (Quellcode) -->
  <t:term><t:key>css</t:key><t:val>CSS</t:val></t:term>
  <t:term><t:key>javascript</t:key><t:val>JavaScript</t:val></t:term>
  <t:term><t:key>perl</t:key><t:val>Perl</t:val></t:term>
  <t:term><t:key>shell</t:key><t:val>Shell</t:val></t:term>
  <t:term><t:key>xml</t:key><t:val>XML</t:val></t:term>
  <t:term><t:key>xslt</t:key><t:val>XSLT</t:val></t:term>
</t:terms>

</xsl:stylesheet>
