Thomas J.S.: Knoten positionsabhängig einfügen

Beitrag lesen

Hallo,

<xsl:template match="*[text()='Kunde']">

Und das willst du für jedes Wort so schreiben?  Dann bist du schneller wenn du die Übersetzung/Ersetzung von Hand machst.

<xsl:variable name="trans" select="text()"/>
  <xsl:variable name="pos" select="number(document('lexikon.xml')//seg[text()=$trans]/position())"/>

<xsl:variable name="ersetze" select="string(document('lexikon.xml')//wort[$pos][1])"/>
...

Die lexikon.xml sieht so aus :

<tu>
  <wort xml:lang="en"><seg>customer</seg></wort>
  <wort xml:lang="de"><seg>Kunde</seg></wort>
</tu>

Ich würde folgendes versuchen:
<xsl:variable name="lexikon" select="document('lexikon.xml')" />
...

fo:table-row
         <fo:table-cell border-width="0.5pt">
          <fo:block text-align="left" line-height="25pt">
          <xsl:apply-templates />
          </fo:block>
         </fo:table-cell>
         <fo:table-cell border-width="0.5pt" line-height="25pt">
          <fo:block text-align="left">
           <xsl:value-of select="Kunde/@Nachnachme"/>
          </fo:block>
         </fo:table-cell>
  </fo:table-row>

...

<xsl:template match="fo:block[string-length(normalize-space(.)) != 0]">
 <xsl:variable name="thisWord" select="normalize-space(.)" />
 <xsl:variable name="lexWord_de" select="$lexikon//seg[. = $thisWord]" />
 <xsl:variable name="lexWord_en" select="$lexikon//seg[../../wort/seg[. = $thisWord]]" />
 xsl:choose
  <xsl:when test="not($lexWord_de = '') and not($lexWord_en = '')">
  <xsl:value-of select="$lexWord_en" />
 </xsl:when>
 xsl:otherwise
  <xsl:value-of select="$thisWord" />
 </xsl:otherwise>
</xsl:choose>
</xsl:template>

fo:block[string-length(normalize-space(.)) != 0] verhindert, dass z.B. auch solche Sachen wie:
<fo:block text-align="left" line-height="25pt">
          <xsl:apply-templates />
          </fo:block>
betroffen werden.

Die choose-Abfrage soll sicherstellen, dass im lexikon.xml sowohl ein deutsches als auch ein englisches Wort vorhanden ist.

Du kannst "lexWord_en" auch so notieren:
 <xsl:variable name="lexWord_en" select="$lexikon//seg[parent::wort[@xml:lang = 'en']][../../wort[@xml:lang = 'de']/seg[. = $thisWord]]" />

HTH
Grüße
Thomas