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. -->
|
|
|
|
|
<!-- Philippe Tourigny, modified 12-9-2022, version 0.94
|
|
|
|
|
Enable the filter to read the language code from the first column
|
|
|
|
|
in each row. Also, add a SYSTEM DOCTYPE declaration to the output
|
|
|
|
|
XML file.-->
|
|
|
|
|
<!-- 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/. -->
|
|
|
|
|
<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 -->
|
|
|
|
|
|
2023-04-22 02:29:33 +02:00
|
|
|
|
<!-- Version 0.94: Add a SYSTEM DOCTYPE to output -->
|
|
|
|
|
<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">
|
|
|
|
|
<!-- Define variables to make code easier to manage.
|
|
|
|
|
Cells in the first row are language code headings.
|
|
|
|
|
The first target language is selected as the
|
|
|
|
|
administrative language for the output TMX.
|
|
|
|
|
The first column identifies the source language. -->
|
2023-04-21 17:38:49 +02:00
|
|
|
|
|
2023-04-22 02:29:33 +02:00
|
|
|
|
<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"/>
|
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>
|
|
|
|
|
<xsl:attribute name="creationtoolversion">0.94</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
|
|
|
|
|
|
|
|
|
<!-- Define the TMX body
|
|
|
|
|
Additional templates are called to make the code
|
|
|
|
|
easier to modify and maintain. -->
|
2023-04-21 12:10:28 +02:00
|
|
|
|
<body>
|
2023-04-22 02:29:33 +02:00
|
|
|
|
<!-- Call the template to insert <tu> elements -->
|
|
|
|
|
<xsl:apply-templates select="//table:table"/>
|
|
|
|
|
</body>
|
|
|
|
|
</tmx>
|
|
|
|
|
</xsl:template>
|
|
|
|
|
|
|
|
|
|
<!-- Templates to populate the <tu> and <tuv> elements-->
|
|
|
|
|
|
|
|
|
|
<!-- Template for <tu> elements:
|
|
|
|
|
Loop through each row, skipping the first one. -->
|
|
|
|
|
<xsl:template match="table:table">
|
|
|
|
|
<xsl:for-each select="table:table-row">
|
2023-04-21 12:10:28 +02:00
|
|
|
|
<tu>
|
2023-04-22 02:29:33 +02:00
|
|
|
|
<xsl:apply-templates select="//table:table-row[position()>1]"/>
|
|
|
|
|
</tu>
|
|
|
|
|
</xsl:for-each>
|
|
|
|
|
</xsl:template>
|
|
|
|
|
|
|
|
|
|
<!-- Template for the <tuv> elements:
|
|
|
|
|
Loop through each cell in the row, and assign the value
|
|
|
|
|
of the language for that column to the xml:lang attribute.
|
|
|
|
|
After that, add the <seg> element and populated it with the
|
|
|
|
|
text in the current cell. -->
|
|
|
|
|
<xsl:template match="table:table-row[position()>1]">
|
2023-04-21 12:10:28 +02:00
|
|
|
|
<xsl:for-each select="table:table-cell">
|
2023-04-22 02:29:33 +02:00
|
|
|
|
<xsl:variable name="currentLang"
|
|
|
|
|
select="//table:table/table:table-row[1]/table:table-cell"/>
|
|
|
|
|
<xsl:variable name="currentColumn"
|
|
|
|
|
select="position()"/>
|
|
|
|
|
<xsl:if test="normalize-space(text:p) != ''">
|
2023-04-21 17:38:49 +02:00
|
|
|
|
<tuv>
|
2023-04-22 02:29:33 +02:00
|
|
|
|
<xsl:attribute name="xml:lang">
|
|
|
|
|
<xsl:value-of select="$currentLang[$currentColumn]/text:p"/>
|
|
|
|
|
</xsl:attribute>
|
|
|
|
|
<seg>
|
|
|
|
|
<xsl:value-of select="text:p"/>
|
|
|
|
|
</seg>
|
2023-04-21 12:10:28 +02:00
|
|
|
|
</tuv>
|
2023-04-22 02:29:33 +02:00
|
|
|
|
</xsl:if>
|
2023-04-21 12:10:28 +02:00
|
|
|
|
</xsl:for-each>
|
|
|
|
|
</xsl:template>
|
2023-04-22 02:29:33 +02:00
|
|
|
|
|
2023-04-21 12:10:28 +02:00
|
|
|
|
</xsl:stylesheet>
|