Refactoriser le code et réorganiser les commentaires

This commit is contained in:
Philippe Tourigny 2023-04-23 00:23:11 +09:00
parent 56ee55b5a7
commit a414abc6a4

View File

@ -5,7 +5,7 @@
Filter to install as an export filter for LibreOffice Calc. -->
<!-- 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.95
<!-- Philippe Tourigny, modified 12-9-2022, version 0.96
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. -->
@ -19,40 +19,39 @@
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/. -->
<!-- Declare the namespaces needed to access parts of 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: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 -->
<!-- Version 0.93: Add a SYSTEM DOCTYPE to output -->
<xsl:output method = "xml" indent = "yes" encoding = "UTF-8"
doctype-system="tmx14.dtd" omit-xml-declaration = "no"/>
<xsl:template match="/">
<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. -->
<!-- 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"/>
select="$headingCell[1]/text:p"/>
<!-- Since version 0.93: Add a SYSTEM DOCTYPE to output -->
<xsl:output method = "xml" indent = "yes" encoding = "UTF-8"
doctype-system="tmx14.dtd" omit-xml-declaration = "no"/>
<xsl:template match="/">
<tmx version="1.4">
<!-- Define the TMX header
The <xsl:attribute> element is used because variables
are not recognized if entered directly in attributes. -->
<header>
<xsl:attribute name="creationtool">TMX-export for LibreOffice</xsl:attribute>
<xsl:attribute name="creationtoolversion">0.95</xsl:attribute>
<xsl:attribute name="creationtoolversion">0.96</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">
@ -64,51 +63,39 @@
<xsl:attribute name="datatype">plaintext</xsl:attribute>
</header>
<!-- Define the TMX body
Additional templates are called to make the code
easier to modify and maintain. -->
<!-- Define the TMX body and use templates to populate
the <tu> and <tuv> elements. -->
<body>
<!-- Call the template to insert <tu> elements -->
<!-- Apply template to insert <tu> elements -->
<xsl:apply-templates select="//table:table-row[position()>1]"/>
</body>
</tmx>
</xsl:template>
<!-- Template to insert the <tu> elements:
Loop through each row, skipping the first one.
<xsl:template match="table:table">
<xsl:for-each select="table:table-row">
<xsl:apply-templates select="//table:table-row[position()>1]"/>
</xsl:for-each>
</xsl:template> -->
<!-- Template to build the <tu> and <tuv> elements:
Within each <tu>, loop through the celsl 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. -->
<!-- Populate the <tu> elements starting at the second row. -->
<xsl:template match="table:table-row[position()>1]">
<tu>
<xsl:for-each select="table:table-cell">
<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) != ''">
<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:for-each>
</tu>
<tu>
<xsl:apply-templates select="table:table-cell"/>
</tu>
</xsl:template>
<!-- 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>
</xsl:stylesheet>