2023-04-21 12:10:28 +02:00
|
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
|
<!-- Dominique Meeùs, created 1-10-2013, version 0.9.
|
2023-04-22 02:29:33 +02:00
|
|
|
|
XSLT transformation of an Open Document Format spreadsheet in five columns
|
2023-04-21 12:10:28 +02:00
|
|
|
|
into a TMX translation memory exchange file.
|
|
|
|
|
Filter to install as an export filter for LibreOffice Calc. -->
|
2023-04-22 02:29:33 +02:00
|
|
|
|
<!-- Dominique Meeùs, modified 21-5-2020, version 0.92.
|
|
|
|
|
Hardcoded languages of the columns are : nl-BE, fr-BE, de-DE, en-GB, es-ES. -->
|
2023-04-23 06:06:45 +02:00
|
|
|
|
<!-- Philippe Tourigny, modified 12-9-2022, version 0.95
|
2023-04-22 02:29:33 +02:00
|
|
|
|
Enable the filter to read the language code from the first column
|
|
|
|
|
in each row. Also, add a SYSTEM DOCTYPE declaration to the output
|
2023-04-22 05:50:09 +02:00
|
|
|
|
XML file. -->
|
2023-04-23 06:06:45 +02:00
|
|
|
|
<!-- Philippe Tourigny, modified 23-4-2023, version 0.96
|
|
|
|
|
Refactor code to use templates correctly and clean up comments. -->
|
2023-04-22 02:29:33 +02:00
|
|
|
|
<!-- Copyright 2013, 2020 Dominique Meeùs, and 2022 Philippe Tourigny@.
|
2023-04-21 12:10:28 +02:00
|
|
|
|
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/. -->
|
2023-04-22 17:23:11 +02:00
|
|
|
|
|
|
|
|
|
<!-- Declare the namespaces needed to access parts of the document. -->
|
2023-04-21 12:10:28 +02:00
|
|
|
|
<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">
|
|
|
|
|
|
2023-04-22 17:23:11 +02:00
|
|
|
|
<!-- Define variables to make code easier to manage.
|
|
|
|
|
The first row contains the language code headings, with
|
|
|
|
|
the source language in the first column. The target language
|
|
|
|
|
in the second column is used as the administrative language. -->
|
|
|
|
|
<xsl:variable name="headingCell"
|
|
|
|
|
select="//table:table/table:table-row[1]/table:table-cell"/>
|
|
|
|
|
<xsl:variable name="adminlang"
|
|
|
|
|
select="$headingCell[2]/text:p"/>
|
|
|
|
|
<xsl:variable name="srclang"
|
|
|
|
|
select="$headingCell[1]/text:p"/>
|
|
|
|
|
|
|
|
|
|
<!-- Since version 0.93: Add a SYSTEM DOCTYPE to output -->
|
2023-04-22 02:29:33 +02:00
|
|
|
|
<xsl:output method = "xml" indent = "yes" encoding = "UTF-8"
|
|
|
|
|
doctype-system="tmx14.dtd" omit-xml-declaration = "no"/>
|
2023-04-21 17:38:49 +02:00
|
|
|
|
|
2023-04-21 12:10:28 +02:00
|
|
|
|
<xsl:template match="/">
|
2023-04-22 02:29:33 +02:00
|
|
|
|
<tmx version="1.4">
|
2023-04-21 17:38:49 +02:00
|
|
|
|
|
2023-04-22 02:29:33 +02:00
|
|
|
|
<!-- Define the TMX header
|
|
|
|
|
The <xsl:attribute> element is used because variables
|
|
|
|
|
are not recognized if entered directly in attributes. -->
|
2023-04-21 17:38:49 +02:00
|
|
|
|
<header>
|
2023-04-22 02:29:33 +02:00
|
|
|
|
<xsl:attribute name="creationtool">TMX-export for LibreOffice</xsl:attribute>
|
2023-04-22 17:23:11 +02:00
|
|
|
|
<xsl:attribute name="creationtoolversion">0.96</xsl:attribute>
|
2023-04-21 17:38:49 +02:00
|
|
|
|
<xsl:attribute name="segtype">sentence</xsl:attribute>
|
|
|
|
|
<xsl:attribute name="o-tmf">application/vnd.oasis.opendocument.spreadsheet</xsl:attribute>
|
2023-04-22 02:29:33 +02:00
|
|
|
|
<xsl:attribute name="adminlang">
|
|
|
|
|
<xsl:value-of select="$adminlang"/>
|
|
|
|
|
</xsl:attribute>
|
|
|
|
|
<xsl:attribute name="srclang">
|
|
|
|
|
<xsl:value-of select="$srclang"/>
|
|
|
|
|
</xsl:attribute>
|
2023-04-21 17:38:49 +02:00
|
|
|
|
<xsl:attribute name="datatype">plaintext</xsl:attribute>
|
2023-04-21 12:10:28 +02:00
|
|
|
|
</header>
|
2023-04-22 02:29:33 +02:00
|
|
|
|
|
2023-04-22 17:23:11 +02:00
|
|
|
|
<!-- Define the TMX body and use templates to populate
|
|
|
|
|
the <tu> and <tuv> elements. -->
|
2023-04-21 12:10:28 +02:00
|
|
|
|
<body>
|
2023-04-22 17:23:11 +02:00
|
|
|
|
<!-- Apply template to insert <tu> elements -->
|
2023-04-22 05:50:09 +02:00
|
|
|
|
<xsl:apply-templates select="//table:table-row[position()>1]"/>
|
2023-04-22 02:29:33 +02:00
|
|
|
|
</body>
|
|
|
|
|
</tmx>
|
|
|
|
|
</xsl:template>
|
|
|
|
|
|
2023-04-22 17:23:11 +02:00
|
|
|
|
<!-- Populate the <tu> elements starting at the second row. -->
|
2023-04-22 02:29:33 +02:00
|
|
|
|
<xsl:template match="table:table-row[position()>1]">
|
2023-04-22 17:23:11 +02:00
|
|
|
|
<tu>
|
|
|
|
|
<xsl:apply-templates select="table:table-cell"/>
|
|
|
|
|
</tu>
|
2023-04-21 12:10:28 +02:00
|
|
|
|
</xsl:template>
|
2023-04-22 02:29:33 +02:00
|
|
|
|
|
2023-04-22 17:23:11 +02:00
|
|
|
|
<!-- Populate the <tuv> elements. -->
|
|
|
|
|
<xsl:template match="table:table-cell">
|
|
|
|
|
|
|
|
|
|
<!-- Get the language from the column heading -->
|
|
|
|
|
<xsl:variable name="currentLang" select="$headingCell"/>
|
|
|
|
|
<xsl:variable name="currentColumn" select="position()"/>
|
|
|
|
|
|
|
|
|
|
<!-- Make sure the cell is not empty -->
|
|
|
|
|
<xsl:if test="normalize-space(text:p) != ''">
|
|
|
|
|
<tuv>
|
|
|
|
|
<xsl:attribute name="xml:lang">
|
|
|
|
|
<xsl:value-of select="$currentLang[$currentColumn]/text:p"/>
|
|
|
|
|
</xsl:attribute>
|
|
|
|
|
<seg>
|
|
|
|
|
<xsl:value-of select="text:p"/>
|
|
|
|
|
</seg>
|
|
|
|
|
</tuv>
|
|
|
|
|
</xsl:if>
|
|
|
|
|
</xsl:template>
|
2023-04-21 12:10:28 +02:00
|
|
|
|
</xsl:stylesheet>
|