Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Copy source to translation when type equals unfinished

From: Thomas <thomasvackier@-----.--->
To: NULL
Date: 7/11/2008 2:13:00 AM
Hi,

I have the following XML file:


<TS>
 <context>
  <name>ElementName</name>
  <message>
   <location line="16" filename="build/debug/xslt/
xml_ApplicationDefaults.cpp" />
   <source>Application</source>
   <translation>Programm</translation>
  </message>
  <message>
   <location line="24" filename="build/debug/xslt/
xml_ElementsPaneLayout_PS.cpp" />
   <source>Archive hierarchy</source>
   <translation type="unfinished" />
  </message>
  <message>
   <location line="18" filename="build/debug/xslt/
xml_ElementsPaneLayout_PS.cpp" />
   <source>Folder</source>
   <translation>Ordner</translation>
  </message>
  <message>
   <location line="28" filename="build/debug/xslt/
xml_ElementsPaneLayout_PS.cpp" />
   <source>Job assembler</source>
   <translation type="unfinished" />
  </message>
  <message>
   <location line="26" filename="build/debug/xslt/
xml_ElementsPaneLayout_PS.cpp" />
   <source>Job dismantler</source>
   <translation>Jobs zerlegen</translation>
  </message>
</context>
</TS>


To process this file in our translation environment I would need an
XSL transformation that copies this file with the following change:
whenever the attribute type of the element translation equals
unfinished, I want the content of the element source copied to the
element target.


So the desired output would look like this:


<TS>
 <context>
  <name>ElementName</name>
  <message>
   <location line="16" filename="build/debug/xslt/
xml_ApplicationDefaults.cpp" />
   <source>Application</source>
   <translation>Programm</translation>
  </message>
  <message>
   <location line="24" filename="build/debug/xslt/
xml_ElementsPaneLayout_PS.cpp" />
   <source>Archive hierarchy</source>
   <translation type="unfinished">Archive hierarchy</translation>
  </message>
  <message>
   <location line="18" filename="build/debug/xslt/
xml_ElementsPaneLayout_PS.cpp" />
   <source>Folder</source>
   <translation>Ordner</translation>
  </message>
  <message>
   <location line="28" filename="build/debug/xslt/
xml_ElementsPaneLayout_PS.cpp" />
   <source>Job assembler</source>
   <translation type="unfinished">Job assembler</translation>
  </message>
  <message>
   <location line="26" filename="build/debug/xslt/
xml_ElementsPaneLayout_PS.cpp" />
   <source>Job dismantler</source>
   <translation>Jobs zerlegen</translation>
  </message>
</context>
</TS>


I recycled a previous XSLT but this doesn't quite produce the right
output:


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
        <xsl:output indent="yes" encoding="UTF-8"/>
        <xsl:template match="*">
                <xsl:call-template name="createNode"/>
        </xsl:template>


        <xsl:template name="createNode">
                <xsl:variable name="tagName">
                        <xsl:value-of select="local-name()"/>
                </xsl:variable>
                <xsl:choose>
                        <xsl:when test="$tagName = 'translation'">
                                <xsl:element name="translation">
                                        <xsl:attribute name="type">
                                                <xsl:value-of
select="./@type"/>
                                        </xsl:attribute>


                                        <xsl:value-of select="../
source"/>


                                        <xsl:for-each select="./*">
                                                <xsl:call-template
name="createNode"/>
                                        </xsl:for-each>
                                </xsl:element>
                        </xsl:when>
                        <xsl:otherwise>
                                <xsl:element name="{$tagName}">
                                        <xsl:if test="count(./*) =
0">
                                                <xsl:value-of
select="."/>
                                        </xsl:if>


                                        <xsl:for-each select="./*">
                                                <xsl:call-template
name="createNode"/>
                                        </xsl:for-each>
                                </xsl:element>
                        </xsl:otherwise>
                </xsl:choose>
        </xsl:template>
</xsl:stylesheet>


Thanks!
Thomas



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent