<?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:sk = "http://herbaer.de/xmlns/20150106/skeleton"
  xmlns:xl = "http://www.w3.org/1999/xlink"
  exclude-result-prefixes = "d xl"
  version = "1.0"
>
<d:info xmlns="http://herbaer.de/xmlns/20051201/doc">
  <title>skeleton_2.xslt</title>
  <subtitle>2. Schritt zur Erzeugung einer Gerüst-Datei</subtitle>
  <date>2015-02-13</date>
  <author>
    <personname>
      <firstname>Herbert</firstname>
      <surname>Schiemann</surname>
    </personname>
    <email>h.schiemann@herbaer.de</email>
  </author>
</d:info>

<d:section xmlns="http://herbaer.de/xmlns/20051201/doc" role="stylesheet">
<para>
Diese Datei definiert den zweiten Schritt zur Erzeugung einer Gerüst-Datei.
Elemente, die zu übersetzenden Text enthalten,
sind zu kennzeichnen und mit einer ID zu versehen.
Die Kennzeichnungen (Attribut <tag class="attribute">@sk:class</tag>) sind:
</para>
<variablelist>
  <varlistentry>
    <term><literal>text</literal></term>
    <listitem>
      <para>
Das Element enthält zu übersetzenden Text, der nicht untergliedert ist.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><literal>struct</literal></term>
    <listitem>
      <para>
Das Element enthält Text mit markierten Textstellen.
      </para>
    </listitem>
  </varlistentry>
  <varlistentry>
    <term><literal>fix</literal></term>
    <listitem>
      <para>
Der Textinhalt ist unabhängig von der Sprache.
Das gilt nicht unbedingt für Attribute.
      </para>
    </listitem>
  </varlistentry>
</variablelist>
</d:section>

<d:para>
Kommentare zur Fehlersuche einfügen / erhalten?
</d:para>
<xsl:param name="p_comments" select="1"/>

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

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

<d:para>
<d:tag class="element">sk:lang</d:tag>-Elemente wurden im ersten Schritt eingefügt.
Sie stehen für Attribute, die die Sprache bezeichnen.
</d:para>
<xsl:template match="sk:lang">
  <xsl:copy-of select="."/>
</xsl:template>

<d:para>
<d:tag class="element">sk:attribute</d:tag>-Elemente stehen für Attribute,
deren Werte zu übersetzen sind.
</d:para>
<xsl:template match="sk:attribute">
  <xsl:param name="plang" select="''"/>
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:attribute name="xliffid">
      <xsl:apply-templates select="." mode="xliffid"/>
    </xsl:attribute>
    <xsl:attribute name="class">text</xsl:attribute>
    <xsl:if test="string-length ($plang) &gt; 0">
      <xsl:attribute name="lang">
        <xsl:value-of select="$plang"/>
      </xsl:attribute>
    </xsl:if>
    <xsl:copy-of select="text() | *"/>
  </xsl:copy>
</xsl:template>

<d:para>
Zu den eingefügten Elementen
<d:tag class="element">sk:part</d:tag> und
<d:tag class="element">sk:contents</d:tag>
werden die XLIFF-Kennung und die Einordnung
<d:tag class="attribute">@class</d:tag>
hinzugefügt.
Das Attribut
<d:code><d:tag class="attribute">sk:unit</d:tag> = "<d:literal>unit</d:literal>"</d:code>
zeigt an, dass der Inhalt als eigener Baustein übersetzt werden kann.
Es ist nicht Teil eines umfassenderen zu übersetzenden Bausteins.
</d:para>
<xsl:template match="sk:part | sk:contents">
  <!-- Sprache -->
  <xsl:param name="plang" select="''"/>
  <!-- Einordnung des Elternelements -->
  <xsl:param name="pclass" select="''"/>
  <!-- Ist ein sk:unit-Attribut einzufügen? -->
  <xsl:param name="unit" select="''"/>
  <xsl:variable name="check">
    <xsl:choose>
      <xsl:when test="../@sk:chk">
        <xsl:value-of select="../@sk:chk"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:variable name="class">
    <xsl:choose>
      <xsl:when test="$pclass = '' and $check = ''"/>
      <xsl:when test="$pclass = 'fix' or $check = 'l'">fix</xsl:when>
      <xsl:when test="$pclass = 'move' or $check = 'm'">move</xsl:when>
      <xsl:when test="* [not (@sk:chk = 'm')]">struct</xsl:when>
      <xsl:otherwise>text</xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:variable name="thisunit">
    <xsl:if
      test = "
        ( ( string-length ($class) &gt; 0 and string-length ($pclass) = 0 )
        or string-length ($unit) &gt; 0
        ) and not (../@sk:wrap = 'wrap' or ../@sk:wrap = 'container')
      "
    >
      <xsl:text>unit</xsl:text>
    </xsl:if>
  </xsl:variable>
  <xsl:variable name="nunit">
    <xsl:if
      test = "
        ( ( string-length ($class) &gt; 0 and string-length ($pclass) = 0 )
        or string-length ($unit) &gt; 0
        ) and (../@sk:wrap = 'wrap' or ../@sk:wrap = 'container')
      "
    >
      <xsl:text>unit</xsl:text>
    </xsl:if>
  </xsl:variable>
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:if test="string-length ($class) &gt; 0">
      <xsl:attribute name="class">
        <xsl:value-of select="$class"/>
      </xsl:attribute>
      <xsl:if test="string-length ($thisunit) &gt; 0">
        <xsl:attribute name="unit">unit</xsl:attribute>
      </xsl:if>
    </xsl:if>
    <xsl:attribute name="xliffid">
      <xsl:apply-templates select="." mode="xliffid"/>
    </xsl:attribute>
    <xsl:if test="string-length ($plang) &gt; 0">
      <xsl:attribute name="lang">
        <xsl:value-of select="$plang"/>
      </xsl:attribute>
    </xsl:if>
    <xsl:if test="$p_comments">
      <xsl:comment>
        <xsl:value-of select="concat (' pclass = ', $pclass, ', class = ', $class, ', unit = ', $unit)"
        />
      </xsl:comment>
      <xsl:apply-templates select="comment()"/>
    </xsl:if>
    <xsl:apply-templates select="text() | *">
      <xsl:with-param name="plang" select="$plang"/>
      <xsl:with-param name="pclass" select="$class"/>
      <xsl:with-param name="unit" select="$nunit"/>
    </xsl:apply-templates>
  </xsl:copy>
</xsl:template>

<xsl:template match="*">
  <!-- Sprache, die auf einer höheren Ebene festgelegt ist -->
  <xsl:param name="plang" select="''"/>
  <!-- Einordnung zur Übersetzung des übergeordneten Elements -->
  <xsl:param name="pclass" select="''"/>
  <!-- Ist nachfolgend ein sk:unit-Attribut einzufügen? -->
  <xsl:param name="unit" select="''"/>
  <xsl:variable name="ll" select="sk:lang"/>
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:if test="$p_comments">
      <xsl:comment>
        <xsl:value-of select="concat (' plang = ', $plang, ', pclass = ', $pclass, ' ')"/>
      </xsl:comment>
      <xsl:apply-templates select="comment()"/>
    </xsl:if>
    <xsl:apply-templates select="text() | *">
      <xsl:with-param name="plang">
        <xsl:choose>
          <xsl:when test="string-length ($ll) &gt; 0">
            <xsl:value-of select="$ll"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$plang"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:with-param>
      <xsl:with-param name="pclass">
        <xsl:choose>
          <xsl:when test="string-length ($pclass) = 0"/>
          <xsl:when test="string-length ($ll) &gt; 0 and not ($plang = $ll)">
            <xsl:text>fix</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$pclass"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:with-param>
      <xsl:with-param name="unit" select="$unit"/>
    </xsl:apply-templates>
  </xsl:copy>
</xsl:template>

<d:para>
Im Modus <d:literal>excl_chk</d:literal> werden Attribute
mit Ausnahme des Attributs
<d:tag class="attribute">@ck:chk</d:tag>
kopiert
</d:para>
<xsl:template match="@sk:chk" mode="excl_chk"/>
<xsl:template match="@*" mode="excl_chk">
  <xsl:copy-of select="."/>
</xsl:template>

<d:para>
Die Kennung eines Elements ist seine Position im Quelldokument.
</d:para>
<xsl:template match="*" mode="xliffid">
  <xsl:text>e</xsl:text>
  <xsl:value-of select="count (preceding::*) + count (ancestor::*) + 1"/>
</xsl:template>

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

</xsl:stylesheet>
