Skip to content

Instantly share code, notes, and snippets.

@msoutopico
Created June 11, 2023 23:17
Show Gist options
  • Save msoutopico/aec471fda89aef0ad80cd528f5fbd088 to your computer and use it in GitHub Desktop.
Save msoutopico/aec471fda89aef0ad80cd528f5fbd088 to your computer and use it in GitHub Desktop.
xlf2tmx_gVhEaiQ.xsl
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<!-- run as:
java -jar saxon-he-12.2.jar -s:path/to/file.xlf -xsl:xlf2tmx_gVhEaiQ.xsl -o:path/to/file.tmx
-->
<xsl:template match="xliff">
<xsl:element name="tmx">
<xsl:attribute name="version">1.4</xsl:attribute>
<xsl:element name="header">
<xsl:attribute name="creationtool">G11NToolKit</xsl:attribute>
<xsl:attribute name="creationtoolversion">1.6.0</xsl:attribute>
<xsl:attribute name="datatype">unknown</xsl:attribute>
<xsl:attribute name="segtype">sentence</xsl:attribute>
<xsl:attribute name="adminlang"><xsl:value-of select="/xliff/file/@source-language"/></xsl:attribute>
<xsl:attribute name="srclang"><xsl:value-of select="/xliff/file/@source-language"/></xsl:attribute>
<xsl:attribute name="o-tmf">sdlxTM</xsl:attribute>
</xsl:element>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="body">
<xsl:element name="{local-name()}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="trans-unit">
<xsl:element name="tu">
<xsl:attribute name="tuid"><xsl:value-of select="@id"/></xsl:attribute>
<xsl:apply-templates>
<xsl:sort select="position()" order="descending"/>
</xsl:apply-templates>
</xsl:element>
</xsl:template>
<xsl:template match="prop-group/prop">
<xsl:element name="prop">
<xsl:attribute name="type">
<xsl:value-of select="@prop-type"/>
</xsl:attribute>
<xsl:value-of select="."/>
</xsl:element>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="source">
<xsl:element name="tuv">
<xsl:attribute name="xml:lang">
<xsl:value-of select="@xml:lang"/>
</xsl:attribute>
<xsl:element name="seg">
<xsl:value-of select="."/>
</xsl:element>
</xsl:element>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="target">
<xsl:element name="tuv">
<xsl:attribute name="xml:lang">
<xsl:value-of select="@xml:lang"/>
</xsl:attribute>
<!-- <xsl:element name="prop">
<xsl:attribute name="type">x-ALS:Source File</xsl:attribute>
<xsl:value-of select="../context-group/context[@context-type='sourcefile']/text()"/>
</xsl:element>
<xsl:element name="prop">
<xsl:attribute name="type">x-ALS:Context</xsl:attribute>
<xsl:value-of select="../context-group/context[@context-type='x-key']/text()"/>
</xsl:element>
-->
<xsl:element name="seg">
<xsl:value-of select="."/>
</xsl:element>
</xsl:element>
<xsl:apply-templates/>
</xsl:template>
<!-- delete these elements -->
<!-- xsl:template match="prop-group">
</xsl:template-->
<xsl:template match="text()"></xsl:template>
<xsl:template match="alt-trans"></xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment