<?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 = "urn:oasis:names:tc:xliff:document:2.0"
  exclude-result-prefixes = "d"
  version = "1.0"
>
<d:info xmlns="http://herbaer.de/xmlns/20051201/doc">
  <title>skeleton_xliff.xslt</title>
  <subtitle>XLIFF aus Skeleton</subtitle>
  <date>2015-03-03</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">
  <title>Besonderheiten des erzeugten XLIFF-Dokuments</title>
  <para>
Markierte Stellen,
deren markierendes Element an das Ende des Elternelements verschoben werden kann,
sind durch das Attribut
<code>xl:mrk/@type = "herbaer:move"</code>
gekennzeichnet.
  </para>
</d:section>

<d:para>
Vorlage <d:literal>txt.makedotword</d:literal>
und <d:literal>txt.break</d:literal>
</d:para>
<xsl:include href="/pool/txt.xslt"/>

<d:para>
Pfad des Quelldokuments,
dient zur Erzeugung des Wertes von
<d:code>file/@id</d:code>
</d:para>
<xsl:param name="p_file" select="''"/>

<xsl:output method="xml" indent="yes"/>

<d:para>
Wurzelelement
</d:para>
<xsl:template match="/">
  <xliff>
    <file>
      <xsl:if test="string-length ($p_file) &gt; 0">
        <xsl:attribute name="id">
          <xsl:text>f_</xsl:text>
          <xsl:call-template name="txt.makedotword">
            <xsl:with-param name="txt" select="$p_file"/>
          </xsl:call-template>
        </xsl:attribute>
      </xsl:if>
      <xsl:for-each select="//sk:attribute">
        <unit id="u_{@xliffid}">
          <segment id="s_{@xliffid}">
            <source xml:lang="{@lang}">
              <xsl:value-of select="."/>
            </source>
          </segment>
        </unit>
      </xsl:for-each>
      <xsl:apply-templates select="(//sk:contents | //sk:part) [@unit = 'unit' and not (@class = 'fix')]"
      />
    </file>
  </xliff>
</xsl:template>

<d:section xmlns="http://herbaer.de/xmlns/20051201/doc">
  <para>
Ein zu übersetzender Baustein.
  </para>
  <para>
Das erzeugte
<tag class="element">unit</tag>-Element kann leer sein.
Das verstößt gegen die XLIFF-Spezifikation 2.0.
Eine folgende Transformation entfernt
<tag class="element">unit</tag>-Elemente,
die kein
<tag class="element">segment</tag>- oder
<tag class="element">ignorable</tag>-Element
enthalten.
  </para>
</d:section>
<xsl:template match="sk:contents [@unit = 'unit'] | sk:part [@unit = 'unit']">
  <unit id="u_{@xliffid}">
    <xsl:apply-templates select=". | .//sk:contents | .//sk:part" mode="segment"/>
  </unit>
</xsl:template>

<d:para>
"Umhüllungen" werden ignoriert.
</d:para>
<xsl:template match="sk:contents [@wrap = 'wrap']" mode="segment"/>

<d:para>
Nicht zu übersetzende Teile werden ebenfalls ignoriert.
</d:para>
<xsl:template match="sk:contents [@class = 'fix']" mode="segment"/>
<xsl:template match="sk:part     [@class = 'fix']" mode="segment"/>

<d:para>
Zu übersetzende Teile mit innerer Struktur
</d:para>
<xsl:template match="sk:contents | sk:part" mode="segment">
  <xsl:variable name="sid" select="@xliffid"/>
  <segment id="s_{$sid}">
    <source>
      <xsl:apply-templates select="@lang"/>
      <xsl:apply-templates select="text() | *" mode="mark">
        <xsl:with-param name="sid" select="$sid"/>
      </xsl:apply-templates>
    </source>
  </segment>
</xsl:template>

<d:para role="mode.mark">
Der Modus <d:literal>mark</d:literal> liefert den Textinhalt mit Markierungen
verschachtelter Elemente
</d:para>

<d:para>
Text
</d:para>
<xsl:template match="text()" mode="mark">
  <xsl:value-of select="."/>
</xsl:template>

<d:para>
Attribute tragen nicht zum Textinhalt bei.
</d:para>
<xsl:template match="sk:attribute | sk:lang" mode="mark"/>

<d:para>
"Umhüllungen" und verschiebbare Markierungen sind "transparent".
</d:para>
<xsl:template match="sk:contents | sk:part" mode="mark">
  <xsl:param name="sid"/>
  <xsl:choose>
    <xsl:when test="@wrap = 'wrap'">
      <xsl:apply-templates select="text() | *" mode="mark">
        <xsl:with-param name="sid" select="$sid"/>
      </xsl:apply-templates>
    </xsl:when>
    <xsl:when test="@class = 'move'">
      <mrk id="m_{@xliffid}_{$sid}" type="herbaer:move">
        <xsl:apply-templates select="text() | *" mode="mark">
          <xsl:with-param name="sid" select="$sid"/>
        </xsl:apply-templates>
      </mrk>
    </xsl:when>
    <xsl:when test="@class = 'fix'">
      <mrk translate="no" id="m_{@xliffid}_{$sid}">
        <xsl:apply-templates select="text() | *" mode="mark">
          <xsl:with-param name="sid" select="$sid"/>
        </xsl:apply-templates>
      </mrk>
    </xsl:when>
    <xsl:otherwise>
      <mrk id="m_{@xliffid}_{$sid}">
        <xsl:apply-templates select="text() | *" mode="mark">
          <xsl:with-param name="sid" select="$sid"/>
        </xsl:apply-templates>
      </mrk>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<d:para>
Trennende Elemente tragen ein Leerzeichen zum Textinhalt bei,
andere Elemente sind "transparent".
</d:para>
<xsl:template match="*" mode="mark">
  <xsl:param name="sid"/>
  <xsl:choose>
    <xsl:when test="@sk:chk = 's'">
      <xsl:value-of select="$txt.break"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:apply-templates select="text() | *" mode="mark">
        <xsl:with-param name="sid" select="$sid"/>
      </xsl:apply-templates>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<d:para>
Sprache
</d:para>
<xsl:template match="@lang">
  <xsl:attribute name="xml:lang">
    <xsl:value-of select="."/>
  </xsl:attribute>
</xsl:template>

</xsl:stylesheet>
