XSLT_TAO/filtres_TMX_pour_Calc/TMX-export.xsl

69 lines
3.7 KiB
XML
Raw Normal View History

<?xml version="1.0" encoding="UTF-8"?>
<!-- Dominique Meeùs, created 1-10-2013, version 0.9.
XSLT transformation of an Open Document Format spreadsheet in two columns
into a TMX translation memory exchange file.
Filter to install as an export filter for LibreOffice Calc. -->
<!-- Copyright 2013 Dominique Meeùs.
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this program.
If not, see http://www.gnu.org/licenses/. -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
exclude-result-prefixes="office table text">
<!-- Namespaces needed to access parts of the document -->
<xsl:output method = "xml" indent = "yes" encoding = "UTF-8" omit-xml-declaration = "no"/>
<xsl:variable name="headerCell" select="//table:table/table:table-row[1]/table:table-cell"></xsl:variable>
<xsl:template match="/">
<!-- Get the source and target languages from the first and second column of the first row. Code based on this answer https://forum.openoffice.org/en/forum/viewtopic.php?p=56627&sid=d4ebce191acc01d99d587fef28377db4#p56627 from the Apache Office forum -->
<xsl:variable name="adminlang" select="$headerCell[2]/text:p"></xsl:variable>
<xsl:variable name="srclang" select="$headerCell[1]/text:p"></xsl:variable>
<xsl:variable name="tgtlang" select="$headerCell[2]/text:p"></xsl:variable>
<tmx version="1.4">
<header>
<xsl:attribute name="creationtool">ods2tmx filter</xsl:attribute>
<xsl:attribute name="creationtoolversion">0.93</xsl:attribute>
<xsl:attribute name="segtype">sentence</xsl:attribute>
<xsl:attribute name="o-tmf">application/vnd.oasis.opendocument.spreadsheet</xsl:attribute>
<xsl:attribute name="adminlang"><xsl:value-of select="$adminlang"></xsl:value-of></xsl:attribute>
<xsl:attribute name="srclang"><xsl:value-of select="$srclang"></xsl:value-of></xsl:attribute>
<xsl:attribute name="datatype">plaintext</xsl:attribute>
</header>
<body>
<xsl:for-each select="//table:table-row[position()>1]">
<tu>
<xsl:for-each select="table:table-cell">
<xsl:choose>
<xsl:when test="position()=1">
<tuv>
<xsl:attribute name="xml:lang"><xsl:value-of select="$srclang"></xsl:value-of></xsl:attribute>
<seg><xsl:value-of select="text:p"/></seg>
</tuv>
</xsl:when>
<xsl:when test="position()=2">
<tuv>
<xsl:attribute name="xml:lang"><xsl:value-of select="$tgtlang"></xsl:value-of></xsl:attribute>
<seg><xsl:value-of select="text:p"/></seg>
</tuv>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</tu>
</xsl:for-each>
</body>
</tmx>
</xsl:template>
</xsl:stylesheet>