2023-04-21 12:10:28 +02:00
<?xml version="1.0" encoding="UTF-8"?>
<!-- Dominique Meeùs, created 30 - 9 - 2013, version 0.9.
XSLT transformation of a TMX translation memory exchange file
into an Open Document Format spreadsheet in two columns.
Filter to install as an import filter for LibreOffice Calc. -->
2023-06-03 04:29:42 +02:00
<!-- Philippe Tourigny, modified 12 - 9 - 2022, version 0.95
2023-04-22 02:29:33 +02:00
Allow the filter to retrieve the languages in the TMX from its
first <tu > element, and create a column for each language. -->
2023-06-03 04:29:42 +02:00
<!-- Philippe Tourigny, modified 3 - 6 - 2023, version 0.96
2023-06-03 04:35:59 +02:00
Streamline namespaces to only those used in the transformation.
2023-06-03 04:39:22 +02:00
Improve formatting for attributes too long to fit on a single line and
2023-06-05 16:58:07 +02:00
fix awkward indentation. -->
<!-- Philippe Tourigny, modified 5 - 6 - 2023, version 0.97
2024-07-27 05:48:32 +02:00
Refactor code to use templates. -->
<!-- Philippe Tourigny, modified 26 - 7 - 2024, version 0.97.1
Fix incorrect retrieval of text in segments with
content format tags. -->
2023-04-22 02:29:33 +02:00
<!-- Copyright 2013 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-06-03 05:44:38 +02:00
2023-06-05 16:58:07 +02:00
<!-- Declare the namespaces needed to create the document. -->
<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:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0">
2023-06-03 05:44:38 +02:00
2023-04-21 12:10:28 +02:00
<xsl:template match= "/" >
2023-06-05 16:58:07 +02:00
<office:document-content >
2023-04-21 12:10:28 +02:00
2023-06-05 16:58:07 +02:00
<!-- Define styles to make the table easier to read. -->
2023-04-21 12:10:28 +02:00
<office:automatic-styles >
2023-06-03 05:44:38 +02:00
2023-04-22 02:29:33 +02:00
<!-- Column properties (for all languages) -->
<style:style style:name= "co1" style:family= "table-column" >
2023-06-03 04:35:59 +02:00
<style:table-column-properties fo:break-before= "auto"
style:column-width="14.000cm"/>
2023-04-21 12:10:28 +02:00
</style:style>
2023-04-22 02:29:33 +02:00
<!-- Row properties -->
2023-06-05 16:58:07 +02:00
<!-- All rows are set to “optimal height”. -->
2023-04-21 12:10:28 +02:00
<style:style style:name= "ro1" style:family= "table-row" >
2023-06-03 04:35:59 +02:00
<style:table-row-properties fo:break-before= "auto"
2023-06-05 16:58:07 +02:00
style:use-optimal-row-height="true"
/>
2023-04-21 12:10:28 +02:00
</style:style>
2023-04-22 02:29:33 +02:00
<!-- Cell properties -->
<!-- Language code heading cells
2023-06-05 16:58:07 +02:00
Language codes are centered and set in bold
in the first row. -->
2023-04-22 02:29:33 +02:00
<style:style style:name= "heading" style:family= "table-cell"
2023-06-03 04:35:59 +02:00
style:parent-style-name="Default">
2023-04-22 02:29:33 +02:00
<style:table-cell-properties style:text-align-source= "fix"
2023-06-03 04:35:59 +02:00
style:repeat-content="false"
fo:wrap-option="wrap"/>
2023-04-22 02:29:33 +02:00
<style:paragraph-properties fo:text-align= "center" />
<style:text-properties fo:font-weight= "bold" />
2023-04-21 12:10:28 +02:00
</style:style>
2023-04-22 02:29:33 +02:00
2023-06-05 16:58:07 +02:00
<!-- Style for the cells that contain the segment text. -->
2023-06-03 04:35:59 +02:00
<style:style style:name= "ce2" style:family= "table-cell"
style:parent-style-name="Default">
2023-06-03 05:44:38 +02:00
<style:table-cell-properties fo:wrap-option= "wrap"
style:vertical-align="top"/>
2023-04-21 12:10:28 +02:00
</style:style>
</office:automatic-styles>
2023-04-22 02:29:33 +02:00
2023-04-21 12:10:28 +02:00
<office:body >
<office:spreadsheet >
2023-06-05 16:58:07 +02:00
<table:table >
<!-- Get the number of languages in the TMX. -->
<xsl:variable name= "numLangs" select= "count(//tu[1]/tuv)" />
<!-- Set column width for a number of columns equal to the
number of languages in the TMX file. -->
<table:table-column table:style-name= 'co1'
2023-06-03 04:35:59 +02:00
table:number-columns-repeated="{$numLangs}"
2023-06-05 16:58:07 +02:00
table:default-cell-style-name="ce2"/>
<!-- Create the header row and retrieve the languages.
Use the mode attribute to retrieve the language attribute
from the <tuv > segment text. -->
2023-04-21 12:10:28 +02:00
2023-06-05 16:58:07 +02:00
<!-- Todo: Identify the <tu> with the largest highest number of <tuv> elements to identify all languages in a TMX file with more languages in some <tu> elements than others. -->
<table:table-row table:style-name= "ro1" >
<xsl:apply-templates select= "//tu[1]/tuv" mode= "lang" />
<table:table-column table:style-name= "co1" />
2023-04-21 17:38:49 +02:00
</table:table-row>
2023-06-05 16:58:07 +02:00
<!-- Get the text of each <tuv> in each <tu>. -->
<xsl:apply-templates select= "//tu" />
2023-04-21 12:10:28 +02:00
</table:table>
</office:spreadsheet>
</office:body>
</office:document-content>
</xsl:template>
2023-06-05 16:58:07 +02:00
<!-- Retrieve the languages to use as headers in the first row.
The "local-name()" function enables the filter to handle both older
versions with the "lang" attribute and newer versions with the
"xml:lang"` attribute. -->
<xsl:template match= "tu[1]/tuv" mode= "lang" >
<table:table-cell table:style-name= "heading" >
<text:p >
<xsl:value-of select= "@*[local-name()='lang']" />
</text:p>
</table:table-cell>
</xsl:template>
<!-- Process the <tu> elements. -->
<xsl:template match= "tu" >
<table:table-row table:style-name= "ro1" >
<xsl:apply-templates select= "tuv" mode= "text" />
</table:table-row>
</xsl:template>
<!-- Retrieve the text of the segments in each <tuv> in the <tu>. -->
<xsl:template match= "tuv" mode= "text" >
<table:table-cell table:style-name= "ce2" >
<text:p >
2024-07-27 05:48:32 +02:00
<xsl:value-of select= "seg/text()" />
2023-06-05 16:58:07 +02:00
</text:p>
</table:table-cell>
</xsl:template>
2023-04-21 12:10:28 +02:00
</xsl:stylesheet>