<?xml version="1.0"?>
<xsl:stylesheet
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:ws="http://joachim-breitner.de/2004/Website"
  xmlns:s="http://joachim-breitner.de/2004/Song"
  xmlns:fl="http://joachim-breitner.de/2004/Filelist"
  xmlns:strings="http://exslt.org/strings"
  xmlns:bib="http://joachim-breitner.de/2004/Website/Bibliography"
  version="2.0"
  exclude-result-prefixes="ws s fl strings"
>
<!-- This file is © 2004-2014 Joachim Breitner. All Rights Reserved, but feel free to ask for a Free Licence (MIT, GPL): mail@joachim-breitner.de -->

<xsl:import href="news.xsl"/>
<xsl:import href="bibliography.xsl"/>
<xsl:import href="xml-to-string.xsl"/>

<xsl:output method="text" />
 <xsl:output
	method="html"
	indent="no"
	omit-xml-declaration="yes"
	name="xhtml"
	/>
<!--
	media-type="text/html"
	doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
	doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
-->
 <xsl:output
	method="xml"
	indent="yes"
	name="rss"
	/>

<xsl:template match="/">
 <xsl:for-each select="/ws:website/ws:section[./ws:title] | //s:song | //ws:entry">
  <xsl:variable name="path"><xsl:call-template name="calcpath"/></xsl:variable>
  <xsl:variable name="filename" select="concat($lang,$path,'.html')"/>
  <xsl:variable name="this" select="."/>
  <xsl:value-of select="$filename" /><xsl:text>&#10;</xsl:text>
  <xsl:result-document href="{$filename}" format="xhtml">
   <xsl:call-template name="layout">
   </xsl:call-template>
  </xsl:result-document>

  <xsl:choose>
   <xsl:when test="ws:blog">
    <xsl:variable name="feedfilename2" select="concat($lang,$path,'_feed.rss')"/>
    <xsl:value-of select="$feedfilename2" /><xsl:text>&#10;</xsl:text>
    <xsl:result-document href="{$feedfilename2}" format="rss">
     <xsl:call-template name="rss">
      <xsl:with-param name="variant" tunnel="yes" select="'archive'"/>
      <xsl:with-param name="entries" select=".//ws:entry"/>
     </xsl:call-template>
    </xsl:result-document>

    <xsl:for-each select="distinct-values(.//ws:entry//ws:tag)">
     <xsl:variable name="tag" select="."/>
     <!-- hack to recover context after for-each :-( -->
     <xsl:for-each select="$this">

     <xsl:variable name="mangledtag" select="translate($tag,' /:%?.','______')"/>

     <xsl:variable name="filename3" select="concat($lang,$path,'/tag/',$mangledtag,'.html')"/>
     <xsl:value-of select="$filename3" /><xsl:text>&#10;</xsl:text>
      <xsl:result-document href="{$filename3}" format="xhtml">
       <xsl:call-template name="layout">
	<xsl:with-param name="variant" tunnel="yes" select="'tags'"/>
	<xsl:with-param name="tag" tunnel="yes" select="$tag"/>
       </xsl:call-template>
      </xsl:result-document>

     <xsl:variable name="feedfilename3" select="concat($lang,$path,'/tag/',$mangledtag,'_feed.rss')"/>
      <xsl:value-of select="$feedfilename3" /><xsl:text>&#10;</xsl:text>
      <xsl:result-document href="{$feedfilename3}" format="rss">
       <xsl:call-template name="rss">
	<xsl:with-param name="variant" tunnel="yes" select="'archive'"/>
	<xsl:with-param name="entries" select=".//ws:entry[
		.//ws:tag[text() = $tag] |
                   (for $thisTag in .//ws:tag
		   return //ws:tagtree//ws:tag[@name = $tag]//ws:tag[@name = $thisTag/text()]/@name)]" />
       </xsl:call-template>
      </xsl:result-document>

     </xsl:for-each>
    </xsl:for-each>
   </xsl:when>
  </xsl:choose>
 </xsl:for-each>

 <xsl:variable name="templateelement">
   <ws:template/>
 </xsl:variable>
 <xsl:variable name="templatefilename" select="concat($lang,'/template.html')"/>
 <xsl:value-of select="$templatefilename" /><xsl:text>&#10;</xsl:text>
 <xsl:result-document href="{$templatefilename}" format="xhtml">
  <xsl:call-template name="layout">
   <xsl:with-param name="template" tunnel="yes" select="true()"/>
  </xsl:call-template>
 </xsl:result-document>
</xsl:template>

<xsl:template name="rss">
 <xsl:param name="mode" />
 <xsl:param name="entries" />

 <rss version="2.0"
      xmlns:content="http://purl.org/rss/1.0/modules/content/"
      xmlns:atom="http://www.w3.org/2005/Atom"
      xmlns=""
      >
  <channel>
    <title>nomeata’s mind shares</title>
    <link>https://www.joachim-breitner.de<xsl:call-template name="calcpath-uri"/></link>
    <atom:link rel="self" type="application/rss+xml">
     <xsl:attribute name="href">https://www.joachim-breitner.de<xsl:call-template name="calcpath-uri"/>_feed.rss</xsl:attribute></atom:link>
    <description>Joachim Breitners Denkblogade</description>
    <image>
        <url>https://joachim-breitner.de/avatars/avatar_128.png</url>
        <title>nomeata’s mind shares</title>
        <link>https://www.joachim-breitner.de<xsl:call-template name="calcpath-uri"/></link>
        <width>128</width>
        <height>128</height>
    </image>

   <xsl:for-each select="$entries[position() &lt;= 15]">
   <item>
    <title><xsl:value-of select="ws:title" /></title>
    <link>https://www.joachim-breitner.de<xsl:call-template name="calcpath-uri"/></link>
    <guid>https://www.joachim-breitner.de<xsl:call-template name="calcpath-uri"/></guid>
    <comments>https://www.joachim-breitner.de<xsl:call-template name="calcpath-uri"/>#comments</comments>
    <!-- <slash:comments>0</slash:comments> -->
    <author>mail@joachim-breitner.de (Joachim Breitner)</author>
    <description>
     <xsl:call-template name="xml-to-string">
      <!-- does not work <xsl:with-param name="force-exclude-all-namespaces" select="true()"/> -->
      <xsl:with-param name="node-set">
       <xsl:apply-templates />
      </xsl:with-param>
     </xsl:call-template>
    </description>

    <pubDate>
     <xsl:value-of select="format-dateTime(@date,
                '[FNn,*-3], [D01] [MNn,*-3] [Y0001] [H01]:[m01]:[s01]',
                'en', 'AD', 'US')"/>
     <xsl:text> </xsl:text>
     <!-- this is required to get a proper RFC-822 datetime -->
     <xsl:value-of select="replace(format-dateTime(@date,
                '[Z]',
		'en', 'AD', 'US'), ':', '')"/>
     </pubDate>
    <!--
    <guid isPermaLink="false">https://www.joachim-breitner.de/blog/archives/653-guid.html</guid>
    -->
   </item>
   </xsl:for-each>
  </channel>
 </rss>
</xsl:template>

<xsl:template name="layout">
  <xsl:param name="template" tunnel="yes"/>
  <xsl:param name="mode" />
  <xsl:text disable-output-escaping='yes'>&lt;!DOCTYPE html&gt;</xsl:text>
  <html lang="{$lang}">
    <xsl:attribute name="class">random-background-<xsl:value-of select="(string-length() mod 6) + 1" /></xsl:attribute>
  <head>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
   <meta http-equiv="X-UA-Compatible" content="IE=edge" />
   <meta name="viewport" content="width=device-width, initial-scale=1" />
   <title>
    <xsl:choose>
     <xsl:when test="$template"> ##TITLE## </xsl:when>
     <xsl:otherwise>
      <xsl:for-each select="ancestor-or-self::*/(ws:title | s:title)">
       <xsl:sort select="position()" data-type="number" order="descending"/>
       <xsl:value-of select="."/>
       <xsl:if test="position() != last()">
	<xsl:text> – </xsl:text>
       </xsl:if>
      </xsl:for-each>
     </xsl:otherwise>
    </xsl:choose>
   </title>
   <link rel="stylesheet" type="text/css" href="/styles/website.css"/>
   <link rel="stylesheet" type="text/css" href="/styles/hk-pyg.css" />
   <link rel="shortcut icon" href="/favicon.ico"/>
   <!--
   <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js">
   </script>
   -->
   <link rel="pavatar" href="https://www.joachim-breitner.de/avatars/avatar_80.png"/>
   <link rel="me" href="https://mastodon.online/@nomeata"/>
   <xsl:call-template name="feedurls"/>
  </head>
  <body>
   <xsl:call-template name="navi2"/>
   <div class="main">
    <!--
    <div id="header">
     <h1>
      <xsl:value-of select="/ws:website/ws:title"/>
     </h1>
    </div>
     -->

    <xsl:choose>
     <xsl:when test="$template"> ##CONTENT## </xsl:when>
     <xsl:otherwise><xsl:apply-templates select="."/></xsl:otherwise>
    </xsl:choose>

    <xsl:call-template name="footer" />

     <!-- Piwik -->
     <!--
     <script type="text/javascript">
       var _paq = _paq || [];
       _paq.push(['trackPageView']);
       _paq.push(['enableLinkTracking']);
       (function() {
	 var u=(("https:" == document.location.protocol) ? "https" : "http") + "://nomeata.de/piwik/";
	 _paq.push(['setTrackerUrl', u+'piwik.php']);
	 _paq.push(['setSiteId', 3]);
	 var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript';
	 g.defer=true; g.async=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
       })();
     </script>
     <noscript><p><img src="https://nomeata.de/piwik/piwik.php?idsite=3" style="border:0;" alt="" /></p></noscript>
     -->
     <!-- End Piwik Code -->
  </div>
 </body>
 </html>
</xsl:template>

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

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

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

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

<xsl:template match="s:copyright">
 <div id="footer">
<!--   <xsl:value-of select="$lang.thisWebsiteIs"/><xsl:text> </xsl:text> -->
  <a href="{//ws:footer/ws:copyright/@href}" title="e-Mail senden">
    © <xsl:value-of select="."/>
  </a>.<br/>
  <!-- <xsl:value-of select="$lang.lastChange"/>: <xsl:value-of select="//ws:footer/ws:last-modified" /> -->
  </div>
</xsl:template>

<xsl:template match="s:song">
  <xsl:apply-templates />
  <!-- <xsl:call-template name="uplink"/> -->
</xsl:template>

<xsl:template name="uplink">
  <div class="uplink">
  <a href="#top"><xsl:value-of select="$lang.goUp"/></a>
  </div>
</xsl:template>

<xsl:template match="ws:section">
 <xsl:param name="variant" tunnel="yes"/>
 <xsl:param name="tag" tunnel="yes"/>
 <xsl:variable name="depth"><xsl:call-template name="section-depth"/></xsl:variable>

 <xsl:choose>
  <!-- Empty: Skip -->
  <xsl:when test="not(./*[not(self::ws:title | self::ws:navi-title | self::bib:bibliography[not(./*)])])">
  </xsl:when>

  <!-- Section -->
  <xsl:when test="$depth = 1">
   <xsl:if test="./ws:title">
    <h2 id="{@id}" class="section"><xsl:value-of select="./ws:title"/>
    <xsl:choose><xsl:when test="$variant = 'tags'"> (Tag <xsl:value-of select="$tag"/>)</xsl:when></xsl:choose>
    </h2>
   </xsl:if>

   <xsl:call-template name="navibox"/>

   <xsl:apply-templates />

  </xsl:when>

  <!-- Subsection -->
  <xsl:when test="$depth = 2">
   <h3 id="{@id}" class="subsection"><xsl:value-of select="./ws:title"/></h3>


   <!-- List of files -->
   <!-- Removed in new layout (we have the links in the text anyways)
   <xsl:variable name="files">
    <xsl:for-each select=".//ws:file">
     <xsl:variable name="filedepth"><xsl:call-template name="section-depth"/></xsl:variable>
     <xsl:if test="$filedepth = $depth">
      X
     </xsl:if>
    </xsl:for-each>
   </xsl:variable>
   <xsl:if test="contains($files,'X')">
    <div class="sidebox right filebox">
    <div class="title">
     <xsl:choose>
      <xsl:when test="@navi-title">
       <xsl:value-of select="@navi-title"/>
      </xsl:when>
      <xsl:otherwise>
       <xsl:value-of select="./ws:title"/>
      </xsl:otherwise>
     </xsl:choose>
    – <xsl:value-of select="$lang.files"/>
    </div>
    <ul>
    <xsl:for-each select=".//ws:file">
     <xsl:variable name="filedepth"><xsl:call-template name="section-depth"/></xsl:variable>
     <xsl:if test="$filedepth = $depth">
      <li><a href="{@href}" title="{@date}"><xsl:value-of select="@title"/></a></li>
     </xsl:if>
    </xsl:for-each>
    </ul>
    </div>
   </xsl:if>
   -->

   <xsl:apply-templates select="*[not(self::ws:projectlinks)]"/> 
   <xsl:apply-templates select="ws:projectlinks" />

   <xsl:call-template name="uplink"/>
  </xsl:when>

  <!-- Further sections -->
  <xsl:otherwise>
   <h4 id="{@id}" class="subsubsection"><xsl:value-of select="./ws:title"/></h4>
   <xsl:apply-templates />
  </xsl:otherwise>
 </xsl:choose>
</xsl:template>

<xsl:template match="ws:introduction">
  <p class="introduction">
    <xsl:apply-templates />
  </p>
</xsl:template>

<xsl:template match="ws:project-image">
  <div class="project-image">
    <img>
      <xsl:attribute name="src"><xsl:value-of select="@src" /></xsl:attribute>
    </img>
  </div>
</xsl:template>

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

<xsl:template match="ws:file">
 <xsl:if test="text()">
  <a>
    <xsl:attribute name="href">
     <xsl:value-of select="@href" />
    </xsl:attribute>
    <xsl:attribute name="title">
     <xsl:value-of select="@title" />
    </xsl:attribute>
    <xsl:apply-templates />
  </a>
 </xsl:if>
</xsl:template>

<xsl:template match="ws:target">
  <a>
    <xsl:attribute name="href">
      <xsl:value-of select="@href" />
    </xsl:attribute>
    <xsl:apply-templates/>
  </a>
</xsl:template>

<xsl:template match="ws:facts">
  <table class="facts">
   <xsl:apply-templates/>
  </table>
</xsl:template>

<xsl:template match="ws:fact">
  <tr><th>
       <xsl:value-of select="@what"/>
      </th>
      <td>
       <xsl:apply-templates/>
      </td></tr>
</xsl:template>
    
<xsl:template match="ws:links">
  <table class="links">
   <xsl:apply-templates/>
  </table>
</xsl:template>

<xsl:template match="ws:links//ws:link">
  <tr><th>
       <xsl:if test="position()=2">
        <xsl:attribute name="class">firstline</xsl:attribute>
       </xsl:if>
       <xsl:value-of select="@to"/>
      </th>
      <td>
       <xsl:if test="position()=2">
        <xsl:attribute name="class">firstline</xsl:attribute>
       </xsl:if>
       <a>
        <xsl:attribute name="href"><xsl:value-of select="@href"/></xsl:attribute>
        <xsl:attribute name="title"><xsl:value-of select="@to"/></xsl:attribute>
        <xsl:apply-templates/>
       </a></td></tr>
</xsl:template>

<xsl:template match="ws:projectlinks">
    <!--
    <div class="title">
     <xsl:choose>
      <xsl:when test="../@navi-title">
       <xsl:value-of select="../@navi-title"/>
      </xsl:when>
      <xsl:otherwise>
       <xsl:value-of select="../ws:title"/>
      </xsl:otherwise>
     </xsl:choose>
     – Links
    </div>
    -->
<!--  <p><strong>Links:</strong> -->
 <ul class="linklist"><xsl:apply-templates/></ul>
<!--  </p> -->
</xsl:template>

<xsl:template match="ws:blogentry">
 <li><a>
   <xsl:attribute name="href">
        <xsl:value-of select="@href"/>
   </xsl:attribute>
     <xsl:choose>
      <xsl:when test="* or text()">
        <xsl:apply-templates />
      </xsl:when>
      <xsl:otherwise>
       <xsl:value-of select="$lang.blogEntry"/>
      </xsl:otherwise>
     </xsl:choose>
 </a></li>
</xsl:template>

<xsl:template match="ws:otherlink">
 <li><a>
   <xsl:attribute name="href">
        <xsl:value-of select="@href"/>
   </xsl:attribute>
   <xsl:apply-templates />
 </a></li>
</xsl:template>

<xsl:template match="ws:debian-bin">
 <li><a>
   <xsl:attribute name="href">https://packages.debian.org/sid/<xsl:value-of select="@pkg"/></xsl:attribute>
     <xsl:choose>
      <xsl:when test="* or text()">
        <xsl:apply-templates />
      </xsl:when>
      <xsl:otherwise>
       <xsl:value-of select="$lang.debianBinary"/>
      </xsl:otherwise>
     </xsl:choose>
 </a></li>
</xsl:template>

<xsl:template match="ws:debian-src">
 <li><a>
   <xsl:attribute name="href">https://packages.qa.debian.org/<xsl:value-of select="@pkg"/></xsl:attribute>
    <xsl:value-of select="$lang.debianSrc"/>
 </a></li>
 <li><a>
   <xsl:attribute name="href">https://bugs.debian.org/cgi-bin/pkgreport.cgi?src=<xsl:value-of select="@pkg"/></xsl:attribute>
       <xsl:value-of select="$lang.debianBugs"/>
 </a></li>
</xsl:template>

<xsl:template match="ws:homepage">
 <li>
  <a>
   <xsl:attribute name="href"><xsl:value-of select="@href"/></xsl:attribute>
   <xsl:value-of select="$lang.homepage"/>
 </a>
 </li>
</xsl:template>

<xsl:template match="ws:github">
 <li>
  <a>
   <xsl:attribute name="href">https://github.com/<xsl:value-of select="@repo"/></xsl:attribute>
   <xsl:value-of select="$lang.githubRepo"/>
 </a>
 </li>
</xsl:template>

<xsl:template match="ws:releaselink">
 <li>
  <a>
   <xsl:attribute name="href">/archive/<xsl:value-of select="@name"/>/<xsl:value-of select="@name"/>-<xsl:value-of select="@version"/>.tar.gz</xsl:attribute>
   <xsl:value-of select="$lang.downloadLink"/> (<xsl:value-of select="@version"/>)
 </a>
 </li>
</xsl:template>

<xsl:template match="ws:windows-installer">
 <li>
  <a>
   <xsl:attribute name="href">/archive/<xsl:value-of select="@name"/>/<xsl:value-of select="@name"/>-setup-<xsl:value-of select="@version"/>.exe</xsl:attribute>
   <xsl:value-of select="$lang.windowsDownloadLink"/> (<xsl:value-of select="@version"/>)
 </a>
 </li>
</xsl:template>

<xsl:template match="ws:contact">
   <xsl:apply-templates/>
</xsl:template>

<xsl:template match="ws:where">
  <h3 class="subsection"><xsl:value-of select="@place"/></h3>
  <ul>
  <xsl:apply-templates/>
  </ul>
</xsl:template>

<xsl:template match="ws:via">
  <li><strong>Via <xsl:value-of select="@medium"/></strong>:<br />
<!--    <xsl:apply-templates/> -->
    <xsl:for-each select="*">
      <xsl:apply-templates select="."/>
      <xsl:if test="position()!=last()">
       <br />
      </xsl:if>
    </xsl:for-each>
  </li>
</xsl:template>

<xsl:template match="ws:email">
  <a>
    <xsl:attribute name="href">mailto:<xsl:value-of select="."/></xsl:attribute>
    <xsl:value-of select="."/>
   </a>
</xsl:template>
    
<xsl:template match="ws:icq">
  <xsl:value-of select="."/>
    <!-- 
  <br/>
  <img>
    <xsl:attribute name="alt"><xsl:value-of select="$lang.onlineStatusOf"/> <xsl:value-of select="."/> </xsl:attribute>
    <xsl:attribute name="src">https://wwp.icq.com/scripts/online.dll?icq=<xsl:value-of select="."/>&amp;img=2 </xsl:attribute>
  </img>
    -->
</xsl:template>
    
<xsl:template match="ws:jid">
  <xsl:value-of select="."/>
  <xsl:if test="@status-url">
  <br/>
  <img>
    <xsl:attribute name="alt"><xsl:value-of select="$lang.onlineStatusOf"/> <xsl:value-of select="."/> </xsl:attribute>
    <xsl:attribute name="src"><xsl:value-of select="@status-url" /></xsl:attribute>
  </img>
  </xsl:if>
</xsl:template>
    
<xsl:template match="ws:indicator">
  <img alt="Jabber-Status">
  <xsl:attribute name="src"><xsl:value-of select="."/></xsl:attribute>
  </img>
</xsl:template>
    
<xsl:template match="ws:telefone">
 <xsl:value-of select="ws:number"/> (<xsl:value-of select="ws:location"/>)
</xsl:template>

<xsl:template match="ws:address">
 <xsl:value-of select="ws:name"/><br />
 <xsl:if test="ws:co">
  <xsl:value-of select="ws:co"/><br />
 </xsl:if>
 <xsl:if test="ws:room">
   <xsl:value-of select="$lang.room"/> <xsl:value-of select="ws:room"/><br />
 </xsl:if>
 <xsl:value-of select="ws:street"/><br />
 <xsl:if test="ws:plz">
  <xsl:value-of select="ws:plz"/><xsl:text> </xsl:text>
 </xsl:if>
 <xsl:value-of select="ws:city"/>
 <xsl:if test="ws:country">
  <br />
  <xsl:value-of select="ws:country"/>
 </xsl:if>
</xsl:template>

<xsl:template match="ws:CVE">
 <a>
  <xsl:attribute name="href">https://cve.mitre.org/cgi-bin/cvename.cgi?name=<xsl:value-of select="."/></xsl:attribute>
  <xsl:value-of select="."/>
 </a>
</xsl:template>

<!-- 
<xsl:template match="ws:filelisting">
<ul>
 <xsl:for-each select="document(@path)/fl:filelist/fl:file">
 <li>
  <a>
   <xsl:attribute name="href">
    <xsl:value-of select="substring-before(.,'.xml')"/>
   </xsl:attribute>
   <xsl:value-of select="document(concat('../xmls/',.))//s:title"/>
  </a>
 </li>
 </xsl:for-each>
</ul>
</xsl:template>
-->

<xsl:template name="footer">
 <div id="footer">
<!--   <xsl:value-of select="$lang.thisWebsiteIs"/><xsl:text> </xsl:text> -->
  <a href="{/ws:website/ws:footer/ws:copyright/@href}" title="e-Mail senden">
    © <xsl:value-of select="/ws:website/ws:footer/ws:copyright"/>
  </a>.
  <!--
  <br/>
  <xsl:value-of select="$lang.lastChange"/>: <xsl:value-of select="/ws:website/ws:footer/ws:last-modified" />
  -->
  </div>
</xsl:template>

<xsl:template name="navi2">
 <xsl:param name="template" tunnel="yes" />
 <xsl:variable name="mainnode" select="generate-id(ancestor-or-self::ws:section[last()])"/>

 <div id="toppage">
  <div id="toptitle">
    <a href="/">Joachim Breitner</a>
  </div>
  <div id="navi2">
   <xsl:for-each select="/ws:website/ws:section
	[./ws:title]
	[not(@navi) or @navi != 'hide']
        ">
    <a href="/{@id}">
     <xsl:if test="$mainnode = generate-id(.)">
       <xsl:attribute name="class">current</xsl:attribute>
     </xsl:if>
     <xsl:choose>
      <xsl:when test="./ws:navi-title">
       <xsl:attribute name="title"><xsl:value-of select="./ws:title"/></xsl:attribute>
       <xsl:value-of select="./ws:navi-title"/>
      </xsl:when>
      <xsl:otherwise>
       <xsl:value-of select="./ws:title"/>
      </xsl:otherwise>
     </xsl:choose>
    </a>
    <xsl:text> </xsl:text>
   </xsl:for-each>

   <!-- <span/> -->

   <xsl:for-each select="/ws:website/ws:subsite[@title]">
    <a class="subsite">
    <xsl:attribute name="title"> <xsl:value-of select="@title"/> </xsl:attribute>
    <xsl:attribute name="href"> <xsl:value-of select="@href"/> </xsl:attribute>
     <xsl:if test="@href = '/bilder/' and $template">
       <xsl:attribute name="class">current</xsl:attribute>
     </xsl:if>
    <!--
    <img class="linkimg" src="/img/extern.gif" width="12" height="9" alt="ext.">
     <xsl:attribute name="title"> <xsl:value-of select="$lang.externalLink"/></xsl:attribute>
    </img>
    -->
     <xsl:choose>
      <xsl:when test="@navi-title">
       <xsl:value-of select="@navi-title"/>
      </xsl:when>
      <xsl:otherwise>
       <xsl:value-of select="@title"/>
      </xsl:otherwise>
     </xsl:choose>
    </a>
    <xsl:if test="position() != last()"><xsl:text> </xsl:text></xsl:if>
   </xsl:for-each>
  </div>
 </div>
</xsl:template>

<xsl:template name="navibox">
<!-- <xsl:for-each select="ws:section[starts-with($path,concat('/',@id))]"> -->
  <xsl:if test="ws:section">
   <div class="navibox">
    <div class="frame tree">
     <xsl:choose>
       <xsl:when test="@navi-title">
	 <xsl:value-of select="@navi-title"/>
       </xsl:when>
       <xsl:when test="./ws:navi-title">
	 <xsl:value-of select="./ws:navi-title"/>
       </xsl:when>
       <xsl:otherwise>
	 <xsl:value-of select="./ws:title"/>
       </xsl:otherwise>
     </xsl:choose>
     <ul>
      <xsl:for-each select="ws:section
	[./*[not(self::ws:title | self::ws:navi-title | self::bib:bibliography[not(./*)])]]
      ">
       <li><a class="subsection">
	<xsl:attribute name="href"><xsl:text>/</xsl:text>
	 <xsl:value-of select="../@id"/>
	 <xsl:choose>
	  <!-- this only works if the more element is a direct child of the section -->
	  <xsl:when test="ws:more">/</xsl:when>
	  <xsl:otherwise>#</xsl:otherwise>
	 </xsl:choose>
	 <xsl:value-of select="@id"/>
	</xsl:attribute>
	<xsl:choose>
	 <xsl:when test="@navi-title">
	  <xsl:value-of select="@navi-title"/>
	 </xsl:when>
	 <xsl:when test="./ws:navi-title">
	  <xsl:value-of select="./ws:navi-title"/>
	 </xsl:when>
	 <xsl:otherwise>
	  <xsl:value-of select="./ws:title"/>
	 </xsl:otherwise>
	</xsl:choose>
       </a></li>
      </xsl:for-each>
     </ul>
    </div>
    <!--
    <div class="title">
    Navigation
    </div>
    -->
    <!--
      <xsl:choose>
        <xsl:when test="@navi-title">
          <xsl:value-of select="@navi-title"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="./ws:title"/>
        </xsl:otherwise>
      </xsl:choose>
      -->
   </div>
  </xsl:if>
<!-- </xsl:for-each> -->

  <!--
 <xsl:if test="ws:tagtree | self::ws:entry">
  <xsl:call-template name="tagtree"/>
 </xsl:if>
  -->
</xsl:template>


<xsl:template name="navi">
  <table><tr>
  <xsl:for-each select="ws:section[./ws:title]">
    <td>
    <div class="section">
     <a class="title" href="/{@id}">
     <xsl:choose>
       <xsl:when test="@navi-title">
         <xsl:value-of select="@navi-title"/>
       </xsl:when>
       <xsl:otherwise>
         <xsl:value-of select="./ws:title"/>
       </xsl:otherwise>
     </xsl:choose>
    </a>
    <xsl:if test="ws:section">
     <xsl:for-each select="ws:section">
      <a class="subsection" href="/{../@id}#{@id}">
     <xsl:choose>
       <xsl:when test="@navi-title">
         <xsl:value-of select="@navi-title"/>
       </xsl:when>
       <xsl:otherwise>
         <xsl:value-of select="./ws:title"/>
       </xsl:otherwise>
     </xsl:choose>
      </a>
     </xsl:for-each>
    </xsl:if>
    </div>
    </td>
  </xsl:for-each>
  </tr></table>
</xsl:template>

<xsl:template match="ws:link">
  <xsl:if test="@type='old'">
   <span class="oldlink"> 
    <xsl:attribute name="title"> <xsl:value-of select="$lang.oldLink"/></xsl:attribute>
   <xsl:apply-templates /> </span>
  </xsl:if>
  <xsl:if test="@type!='old'">
 <a href="{@href}">
  <xsl:if test="@title">
   <xsl:attribute name="title"> <xsl:value-of select="@title"/> </xsl:attribute>
  </xsl:if>
  <xsl:apply-templates />
  <!-- 
  <xsl:if test="@type='external'">
   <xsl:text> </xsl:text>
   <img class="linkimg" src="/img/extern.gif" width="12" height="9" alt="ext.">
    <xsl:attribute name="title"> <xsl:value-of select="$lang.externalLink"/></xsl:attribute>
   </img>
  </xsl:if>
  -->
 </a>
  </xsl:if>
</xsl:template>

<xsl:template match="ws:figure">
 <div class="leftfigure">
  <div class="frame">
   <xsl:apply-templates />
  </div>
  <div class="title">
    <xsl:value-of select="ws:title" />
  </div>
 </div>
</xsl:template>

<xsl:template match="ws:blog-preview">
  <h3 id="{@id}" class="subsection">
    <xsl:value-of select="$lang.latest-blog-entries" />
  </h3>
  <ul>
  <xsl:for-each select="//ws:blog/*[position() &lt;=10]/ws:entry">
    <li>
     <xsl:value-of select="format-dateTime(@date,$lang.date-format)" />:
     <a>
      <xsl:attribute name="href">
       <xsl:call-template name="calcpath-uri"/>
      </xsl:attribute>
      <xsl:value-of select="ws:title"/>
     </a>
    </li>
   </xsl:for-each>
   <li>
    <a>
     <xsl:attribute name="href">
       <xsl:for-each select="//ws:blog">
        <xsl:call-template name="calcpath-uri"/>
       </xsl:for-each>
     </xsl:attribute>
     … <xsl:value-of select="$lang.viewMore" />
    </a>
   </li>
  </ul>

  <h3 id="{@id}" class="subsection">
    <xsl:value-of select="$lang.blog-categories" />
  </h3>

  <xsl:call-template name="tagtree"/>
</xsl:template>

<xsl:template name="tagtree">
 <!-- change context -->
 <xsl:for-each select="//ws:tagtree">
   <div class="tree">
    <a>
     <xsl:attribute name="href">
       <xsl:call-template name="calcpath-uri"/>
     </xsl:attribute>
     <xsl:value-of select="$lang.all" />
    </a>
    <ul>
     <xsl:apply-templates select="ws:tag" mode="tagtree"/>
    </ul>
   </div>
 </xsl:for-each>
</xsl:template>

<xsl:template match="ws:tag" mode="tagtree">
 <li>
  <a>
   <xsl:attribute name="href">
    <xsl:call-template name="calcpath-uri"/>/tag/<xsl:value-of select="translate(@name,' /:%?.','______')"/>
   </xsl:attribute>
   <xsl:value-of select="@name"/>
  </a>
  <xsl:if test="ws:tag">
   <ul>
    <xsl:apply-templates select="ws:tag" mode="tagtree"/>
   </ul>
  </xsl:if>
 </li>
</xsl:template>

<xsl:template name="entrylist">
 <xsl:param name="entries" />
 <xsl:for-each-group select="$entries" group-by="year-from-dateTime(ws:entry/@date)">
  <h3><xsl:value-of select="current-grouping-key()"/></h3>
  <ul>
   <xsl:for-each select="current-group()">
    <li>
     <a>
      <xsl:attribute name="href">
       <xsl:call-template name="calcpath-uri"/>
      </xsl:attribute>
      <xsl:value-of select="ws:entry/ws:title"/>
     </a>
    </li>
   </xsl:for-each>
  </ul>
 </xsl:for-each-group>
</xsl:template>

<xsl:template name="feedurls">
 <xsl:param name="variant" tunnel="yes"/>
 <xsl:param name="tag" tunnel="yes"/>

 <!-- if this is blog related, add an RSS link header -->
 <xsl:if test=".//ws:blog | .//ws:entry | self::ws:entry">
  <xsl:for-each select="//ws:blog">
   <xsl:choose>
    <xsl:when test="$variant = 'tags'">
     <link rel="alternate"  type="application/rss+xml" title="nomeata’s mind shares – tag {$tag}">
      <xsl:attribute name="href">
       <xsl:call-template name="calcpath-uri"/>
       <xsl:text>/tag/</xsl:text>
       <xsl:value-of select="translate($tag,' /:%?.','______')"/>
       <xsl:text>_feed.rss</xsl:text>
      </xsl:attribute>
     </link>
    </xsl:when>

    <xsl:otherwise>
     <link rel="alternate"  type="application/rss+xml" title="nomeata’s mind shares">
      <xsl:attribute name="href">
       <xsl:call-template name="calcpath-uri"/>
       <xsl:text>_feed.rss</xsl:text>
      </xsl:attribute>
     </link>
    </xsl:otherwise>
   </xsl:choose>
  </xsl:for-each>
 </xsl:if>
</xsl:template>

<xsl:template match="ws:blog">
 <xsl:param name="variant" tunnel="yes"/>
 <xsl:param name="tag" tunnel="yes"/>

 <xsl:choose>
  <xsl:when test="$variant = 'tags'">
   <xsl:call-template name="entrylist">
    <xsl:with-param name="entries" select="ws:more[
		.//ws:tag[text() = $tag] |
                   (for $thisTag in .//ws:tag
		   return //ws:tagtree//ws:tag[@name = $tag]//ws:tag[@name = $thisTag/text()]/@name)]" />
   </xsl:call-template>
  </xsl:when>

  <xsl:otherwise>
   <xsl:call-template name="entrylist">
    <xsl:with-param name="entries" select="ws:more"/>
   </xsl:call-template>
  </xsl:otherwise>
 </xsl:choose>
</xsl:template>


<xsl:template match="ws:entry">
 <xsl:param name="variant" tunnel="yes"/>

 <div class="blogentry">
  <h2 class="serendipity_title">
   <a>
    <xsl:attribute name="href">
     <xsl:call-template name="calcpath-uri"/>
    </xsl:attribute>
    <xsl:value-of select="ws:title"/>
   </a>
  </h2>

  <div class="blogintro">
    <xsl:value-of select="$lang.published"/>
    <xsl:text> </xsl:text>
    <span>
      <xsl:attribute name="title">
        <xsl:value-of select="format-dateTime(@date,'[Y0001]-[M01]-[D01] [H01]:[m01] [Z]')" />
      </xsl:attribute>
      <xsl:value-of select="format-dateTime(@date,$lang.date-format)" />
    </span>
    <xsl:if test="ws:tag">
      <xsl:text> </xsl:text>
      <xsl:value-of select="$lang.in-sections"/>
      <xsl:text> </xsl:text>
      <xsl:for-each select="ws:tag">
       <a>
        <xsl:attribute name="href">
	 <xsl:text>/blog/tag/</xsl:text>
	 <xsl:value-of select="translate(.,' /:%?.','______')"/>
	</xsl:attribute>
        <xsl:value-of select="."/>
       </a>
       <xsl:if test="position() != last()">, </xsl:if>
      </xsl:for-each></xsl:if>.
  </div>

  <div class="blogbody">
    <xsl:apply-templates />
  </div>

  <xsl:if test="$variant = 'overview'">
    <div class='blogfooter'>
     <a>
      <xsl:attribute name="href">
       <xsl:call-template name="calcpath-uri"/>
       <xsl:text>#comments</xsl:text>
      </xsl:attribute>
      <xsl:choose>
       <xsl:when test="count(.//ws:comment) = 0">
        <xsl:value-of select="$lang.no-comments"/>
       </xsl:when>
       <xsl:when test="count(.//ws:comment) = 1">
        <xsl:value-of select="$lang.one-comment"/>
       </xsl:when>
       <xsl:otherwise>
	<xsl:value-of select="count(.//ws:comment)"/>
	<xsl:text> </xsl:text>
        <xsl:value-of select="$lang.comments"/>
       </xsl:otherwise>
      </xsl:choose>
     </a>
     <xsl:text>. </xsl:text>
    </div>
   </xsl:if>


  <xsl:if test="$variant != 'overview'">
   <h2 id="comments" class="serendipity_commentsTitle">
    <xsl:value-of select="$lang.Comments"/>
   </h2>
   <xsl:if test="ws:comment">
    <xsl:for-each select=".//ws:comment">
     <div class="comment">
      <xsl:attribute name="id">
       <xsl:text>comment_</xsl:text>
       <xsl:value-of select="position()"/>
      </xsl:attribute>
      <xsl:attribute name="style">
       <xsl:text>padding-left:</xsl:text>
       <xsl:value-of select="10 + 20 * count(ancestor::ws:comment)"/>
       <xsl:text>px</xsl:text>
      </xsl:attribute>
      <div class="commentbody">
       <xsl:apply-templates />
      </div>
      <div class="commentsource">
       <a class="commentnum">
	<xsl:attribute name="href">
	 <xsl:text>#comment_</xsl:text>
	 <xsl:value-of select="position()"/>
	</xsl:attribute>
	<xsl:text>#</xsl:text>
	<xsl:value-of select="position()"/>
       </a>
       <xsl:text> </xsl:text>
       <span class="author">
	<xsl:value-of select="@author"/>
       </span>
       <xsl:if test="@homepage">
	 <xsl:text> (</xsl:text>
	 <a class="homepage">
	  <xsl:attribute name="href"><xsl:value-of select="@homepage" /></xsl:attribute>
	  <xsl:attribute name="title"><xsl:value-of select="@homepage" /></xsl:attribute>
	  <xsl:text>Homepage</xsl:text>
	 </a>
	 <xsl:text>)</xsl:text>
       </xsl:if>

       <xsl:text> am </xsl:text>
       <span class="date">
	 <xsl:attribute name="title">
	   <xsl:value-of select="format-dateTime(@date,'[Y0001]-[M01]-[D01] [H01]:[m01] [Z]')" />
	 </xsl:attribute>
	 <xsl:value-of select="format-dateTime(@date,$lang.date-format)" />
       </span>
      </div>
     </div>
    </xsl:for-each>
   </xsl:if>
   <div class="commentinfo">
    <xsl:call-template name="lang.commentinfo"/>
   </div>
  </xsl:if>

  <xsl:call-template name="uplink"/>
 </div>
</xsl:template>

<!-- Subpage handling -->
<xsl:template match="ws:songlist">
<ul>
 <xsl:for-each select="ws:more">
 <li>
  <a>
   <xsl:attribute name="href">
    <xsl:call-template name="calcpath-uri"/>
   </xsl:attribute>
   <xsl:value-of select="s:song/s:title"/>
  </a>
 </li>
 </xsl:for-each>
</ul>
</xsl:template>

<xsl:template name="calcpath">
 <xsl:choose>
  <xsl:when test="ancestor-or-self::*[@id]">
   <xsl:for-each select="ancestor-or-self::*[@id]">
    <xsl:text>/</xsl:text>
    <xsl:value-of select="@id"/>
    <!-- blog entries have nicer paths -->
    <xsl:if test="./ws:entry">
     <xsl:text>-</xsl:text>
     <xsl:value-of select="translate(./ws:entry/ws:title,' /:&quot;?#%.','________')"/>
    </xsl:if>
   </xsl:for-each>
  </xsl:when>
  <xsl:otherwise>
   <xsl:text>/index</xsl:text>
  </xsl:otherwise>
 </xsl:choose>
</xsl:template>

<xsl:template name="calcpath-uri">
 <xsl:choose>
  <xsl:when test="ancestor-or-self::*[@id]">
   <xsl:for-each select="ancestor-or-self::*[@id]">
    <xsl:text>/</xsl:text>
    <xsl:value-of select="@id"/>
    <!-- blog entries have nicer paths -->
    <xsl:if test="./ws:entry">
     <xsl:text>-</xsl:text>
     <xsl:value-of select="encode-for-uri(translate(./ws:entry/ws:title,' /:&quot;?#%.','________'))"/>
    </xsl:if>
   </xsl:for-each>
  </xsl:when>
  <xsl:otherwise>
   <xsl:text>/</xsl:text>
  </xsl:otherwise>
 </xsl:choose>
</xsl:template>

<!-- TODO: How many sections have been displayed so far? -->
<xsl:template name="section-depth">
 <xsl:variable name="sections">
  <xsl:for-each select="ancestor-or-self::*[self::ws:section or self::ws:website]">
   <!--
   <xsl:variable name="subpath"><xsl:call-template name="calcpath"/></xsl:variable>
    <xsl:if test="starts-with($subpath,$path)">
     X
    </xsl:if>
   -->
   X
   </xsl:for-each>
  </xsl:variable>
  <xsl:value-of select="string-length(translate(normalize-space($sections),'X ','X'))-1"/> <!-- TODO: the -1 is a hack -->
</xsl:template>

<!-- Do not show unmatched elements -->
<xsl:template match="ws:*"/>
<xsl:template match="s:*"/>

<!-- xsl:template match="*|@*">
 <xsl:copy>
  <xsl:apply-templates select="*|@*|node()" />
 </xsl:copy>
</xsl:template -->

<!-- <xsl:template  match="*|@*">
 <xsl:copy>
  <xsl:apply-templates select="*|@*|node()" />
 </xsl:copy>
 <xsl:message terminate="yes">Found unknown node</xsl:message>
</xsl:template> -->

<!-- Allow inline html -->
<xsl:template match="*[namespace-uri()='http://www.w3.org/1999/xhtml']">
 <xsl:element name="{local-name(.)}">
  <xsl:apply-templates select="*|@*|node()" />
 </xsl:element>
</xsl:template>

<xsl:template match="@*">
 <xsl:copy/>
</xsl:template>


</xsl:stylesheet>
