<?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:is = "http://herbaer.de/xmlns/20080705/imgshow"
  xmlns:l = "http://herbaer.de/xmlns/20141210/localization"
  xmlns:sk = "http://herbaer.de/xmlns/20150106/skeleton"
  xmlns:ti = "http://herbaer.de/xmlns/201500703/transinfo/"
  xmlns:d = "http://herbaer.de/xmlns/20051201/doc"
  xmlns = "http://herbaer.de/xmlns/20080705/imgshow"
  exclude-result-prefixes = "d is l sk ti"
  version = "1.0"
>
<d:info xmlns="http://herbaer.de/xmlns/20051201/doc">
  <title>imgshow_post.xslt</title>
  <subtitle>Eine Bildergeschichte nach der Übersetzung aufbereiten</subtitle>
  <date>2015-08-12</date>
  <author>
    <personname>
      <firstname>Herbert</firstname>
      <surname>Schiemann</surname>
    </personname>
    <email>h.schiemann@herbaer.de</email>
  </author>
</d:info>

<d:para>
Dateipfad des Quelltextes der Lokalisierungsdatei
</d:para>
<xsl:param name="p_localsrc" select="'../style/local.xml.de'"/>

<d:para>
Dateipfad der übersetzten Lokalisierungsdatei
</d:para>
<xsl:param name="p_localweb" select="'../../docroot/local/local.xml.de.'"/>

<d:para>
Wurzelelement des Quelltextes der Lokalisierungsdatei
</d:para>
<xsl:variable name="g_locsrcroot" select="document($p_localsrc)/*"/>

<d:para>
Wurzelelement der übersetzten Lokalisierungsdatei
</d:para>
<xsl:variable name="g_locwebroot" select="document($p_localweb)/*"/>

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

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

<d:para>
Elemente werden "hohl" kopiert.
</d:para>
<xsl:template match="*">
  <xsl:copy>
    <xsl:apply-templates select="@* | *[not (@ti:hint = 'moved')] | text()"/>
    <xsl:apply-templates select="* [@ti:hint = 'moved']"/>
  </xsl:copy>
</xsl:template>

<d:para>
<d:tag class="element">sk:part</d:tag>-Elemente
dürfte es nicht geben, wenn doch, werden sie ignoriert.
</d:para>
<xsl:template match="sk:part">
  <xsl:apply-templates select="@* | *[not (@ti:hint = 'moved')] | text()"/>
  <xsl:apply-templates select="* [@ti:hint = 'moved']"/>
</xsl:template>

<d:para>
<d:tag class="element">f</d:tag>-Elemente werden aus dem übersetzten Dokument entfernt.
</d:para>
<xsl:template match="is:f">
  <xsl:apply-templates/>
</xsl:template>

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

<d:para>
Hinweise zur Übersetzung werden entfernt.
</d:para>
<xsl:template match="@ti:hint"/>

<d:para>
Bildverweise werden mit Inhalt gefüllt
</d:para>
<xsl:template match="is:jpg">
  <xsl:text> </xsl:text>
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:value-of select="concat ('[', count (preceding::is:jpg) + 1, ']')"/>
  </xsl:copy>
</xsl:template>

<d:para>
Verweise auf eine Puppe, eine Perücke oder ein Kleid
sollte es im Web nicht geben, trotzdem werden sie hier abgefangen.
</d:para>
<xsl:template
  match = "
    is:puppe
    [@ti:hint = 'moved'] | is:peruecke [@ti:hint = 'moved'] | is:kleid
    [@ti:hint = 'moved']
  "
>
  <xsl:text> </xsl:text>
  <xsl:copy>
    <xsl:apply-templates select="@*"/>
    <xsl:text>[</xsl:text>
    <xsl:value-of select="@ref"/>
    <xsl:text>]</xsl:text>
  </xsl:copy>
</xsl:template>

<d:para>
Verschobener Verweis auf eine Bildergeschichte
</d:para>
<xsl:template match="is:story [@ti:hint = 'moved']">
  <xsl:text> </xsl:text>
  <xsl:copy>
    <xsl:apply-templates select="@*"/>
    <xsl:text>[</xsl:text>
    <xsl:call-template name="gettext">
      <xsl:with-param name="id">bildergeschichte</xsl:with-param>
    </xsl:call-template>
    <xsl:text> </xsl:text>
    <xsl:choose>
      <xsl:when test="contains (@ref, '#')">
        <xsl:value-of select="substring-before (@ref, '#')"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="@ref"/>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:text>]</xsl:text>
  </xsl:copy>
</xsl:template>

<d:para>
Verschobener Verweis auf einen Textabschnitt
</d:para>
<xsl:template match="is:sect [@ti:hint = 'moved']">
  <xsl:text> </xsl:text>
  <xsl:copy>
    <xsl:apply-templates select="@*"/>
    <xsl:text>[</xsl:text>
    <xsl:call-template name="gettext">
      <xsl:with-param name="id">textabschnitt</xsl:with-param>
    </xsl:call-template>
    <xsl:text> </xsl:text>
    <xsl:choose>
      <xsl:when test="contains (@ref, '_')">
        <xsl:value-of select="substring-before (@ref, '_')"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="@ref"/>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:text>]</xsl:text>
  </xsl:copy>
</xsl:template>

<d:para>
Übersetzter Text anhand der ID im Quelltext der Lokalisierungsdatei
</d:para>
<xsl:template name="gettext">
  <!-- ID im Lokalisierungs-Quelltext -->
  <xsl:param name="id"/>
  <xsl:variable name="pos" select="count ($g_locsrcroot/l:t[@id = $id]/preceding-sibling::l:t) + 1"
  />
  <xsl:value-of select="$g_locwebroot/l:t[position() = $pos]"/>
</xsl:template>

</xsl:stylesheet>
