<?xml version="1.0" encoding="utf-8"?>
<?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:h = "http://herbaer.de/xmlns/20121015/hash"
  xmlns:kb = "http://herbaer.de/xmlns/20151211/kalenderbilder/"
  xmlns:l = "http://herbaer.de/xmlns/20141210/localization"
  xmlns:lt = "http://herbaer.de/xmlns/20151212/loctext/"
  xmlns = "http://herbaer.de/xmlns/20151211/kalenderbilder/"
  exclude-result-prefixes = "d lt h kb l"
  version = "1.0"
  xml:lang = "de"
>

<d:info xmlns="http://herbaer.de/xmlns/20051201/doc">
  <title>kal_addkeywords.xslt</title>
  <subtitle>Schlüsselwörter zu Kalenderbildern hinzufügen</subtitle>
  <date>2015-12-23</date>
  <author>
    <personname>
      <firstname>Herbert</firstname>
      <surname>Schiemann</surname>
    </personname>
    <email>h.schiemann@herbaer.de</email>
  </author>
</d:info>

<d:para role="stylesheet">
Diese Transformation fügt &#x201e;<d:literal
>Kalender</d:literal>&#x201d; als Stichwort für Suchmaschinen in den angebotenen Sprachen hizu.
</d:para>

<d:para>
Pfad des XML-Dokuments mit den kurzen IDs der Platzhalter
</d:para>
<xsl:param name="p_shortids" select="'shortids.xml'"/>

<d:para>
Document Root - Verzeichnis des Webservers
</d:para>
<xsl:param name="p_docroot" select="'docroot/'"/>

<d:para>
Textkennung für <d:literal>kalender</d:literal>
</d:para>
<xsl:param name="g_kalid" select="document($p_shortids)/h:hash/h:value [@key = 'kalender']"
/>

<xsl:template match="/">
  <xsl:apply-templates select="* | processing-instruction()"/>
</xsl:template>

<d:para>
Zum Wurzelelement wird ein HTML-Meta-Element mit Schlüsselwörtern
hinzugefügt.
</d:para>
<xsl:template match="kb:kalenderbilder">
  <kalenderbilder>
    <xsl:apply-templates select="@*"/>
    <xsl:if test="not (ht:meta [@name = 'keywords'])">
      <xsl:choose>
        <xsl:when test="kb:t/lt:v/lt:t">
          <xsl:apply-templates select="kb:t/lt:v/lt:t" mode="meta"/>
        </xsl:when>
        <xsl:when test="kb:y">
          <ht:meta name="keywords" content="Kalender {kb:y}" lang="de"/>
        </xsl:when>
        <xsl:otherwise>
          <ht:meta name="keywords" content="Kalender" lang="de"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:if>
    <xsl:apply-templates select="*"/>
  </kalenderbilder>
</xsl:template>

<d:para>
Stichwort in einer angebotenen Sprache
</d:para>
<xsl:template match="lt:t" mode="meta">
  <xsl:variable name="lang" select="@l"/>
  <xsl:variable name="cont">
    <xsl:value-of
      select = "
        document(concat($p_docroot, '/local/local.xml.', $lang, '.'))
        /l:localization/l:t[@id=$g_kalid]
      "
    />
    <xsl:if test="/kb:kalenderbilder/kb:y">
      <xsl:text> </xsl:text>
      <xsl:value-of select="/kb:kalenderbilder/kb:y"/>
    </xsl:if>
  </xsl:variable>
  <ht:meta name="keywords" content="{$cont}" lang="{$lang}"/>
</xsl:template>

<d:para>
Elemente werden absteigend kopiert.
</d:para>
<xsl:template match="*">
  <xsl:copy>
    <xsl:apply-templates select="@* | text() | *"/>
  </xsl:copy>
</xsl:template>

<d:para>
Attribute werden kopiert.
</d:para>
<xsl:template match="@*">
  <xsl:copy-of select="."/>
</xsl:template>

<d:para>
Verarbeitungsanweisungen werden kopiert.
</d:para>
<xsl:template match="processing-instruction()">
  <xsl:copy-of select="."/>
</xsl:template>

</xsl:stylesheet>
