Refactoriser en modèles, et mettre les commentaires à jour
This commit is contained in:
parent
b0a6f0e6e1
commit
82727f434d
@ -10,6 +10,8 @@
|
|||||||
Streamline namespaces to only those used in the transformation.
|
Streamline namespaces to only those used in the transformation.
|
||||||
Improve formatting for attributes too long to fit on a single line and
|
Improve formatting for attributes too long to fit on a single line and
|
||||||
fix awkward indentation. -->
|
fix awkward indentation. -->
|
||||||
|
<!-- Philippe Tourigny, modified 5-6-2023, version 0.97
|
||||||
|
Refactor code to use templates. -->
|
||||||
<!-- Copyright 2013 Dominique Meeùs, and 2022 Philippe Tourigny.
|
<!-- Copyright 2013 Dominique Meeùs, and 2022 Philippe Tourigny.
|
||||||
This program is free software: you can redistribute it and/or modify it
|
This program is free software: you can redistribute it and/or modify it
|
||||||
under the terms of the GNU Lesser General Public License
|
under the terms of the GNU Lesser General Public License
|
||||||
@ -21,26 +23,19 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License along with this program.
|
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/. -->
|
If not, see http://www.gnu.org/licenses/. -->
|
||||||
|
|
||||||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
<!-- Declare the namespaces needed to create the document. -->
|
||||||
|
<xsl:stylesheet version="1.0"
|
||||||
<!-- Define variables used to identify the languages
|
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||||
In a TMX with three or more languages, all translation unit
|
|
||||||
(<tuv>) elements are assumed to contain the same number of
|
|
||||||
languages, and the first <tu> is used to identify them. -->
|
|
||||||
|
|
||||||
<!-- 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. -->
|
|
||||||
<xsl:variable name="firstTU" select="tmx/body/tu[1]"/>
|
|
||||||
<xsl:variable name="numLangs" select="count($firstTU/tuv)"/>
|
|
||||||
|
|
||||||
<xsl:template match="/">
|
|
||||||
<office:document-content
|
|
||||||
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
|
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
|
||||||
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style: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:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
|
||||||
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table: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"
|
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0">
|
||||||
office:version="1.0">
|
|
||||||
|
|
||||||
|
<xsl:template match="/">
|
||||||
|
<office:document-content>
|
||||||
|
|
||||||
|
<!-- Define styles to make the table easier to read. -->
|
||||||
<office:automatic-styles>
|
<office:automatic-styles>
|
||||||
|
|
||||||
<!-- Column properties (for all languages) -->
|
<!-- Column properties (for all languages) -->
|
||||||
@ -50,16 +45,17 @@
|
|||||||
</style:style>
|
</style:style>
|
||||||
|
|
||||||
<!-- Row properties -->
|
<!-- Row properties -->
|
||||||
<!-- All rows are set to “optimal height” -->
|
<!-- All rows are set to “optimal height”. -->
|
||||||
<style:style style:name="ro1" style:family="table-row">
|
<style:style style:name="ro1" style:family="table-row">
|
||||||
<style:table-row-properties fo:break-before="auto"
|
<style:table-row-properties fo:break-before="auto"
|
||||||
style:use-optimal-row-height="true"/>
|
style:use-optimal-row-height="true"
|
||||||
|
/>
|
||||||
</style:style>
|
</style:style>
|
||||||
|
|
||||||
<!-- Cell properties -->
|
<!-- Cell properties -->
|
||||||
<!-- Language code heading cells
|
<!-- Language code heading cells
|
||||||
The language codes are centered and set in bold
|
Language codes are centered and set in bold
|
||||||
in the first column. -->
|
in the first row. -->
|
||||||
<style:style style:name="heading" style:family="table-cell"
|
<style:style style:name="heading" style:family="table-cell"
|
||||||
style:parent-style-name="Default">
|
style:parent-style-name="Default">
|
||||||
<style:table-cell-properties style:text-align-source="fix"
|
<style:table-cell-properties style:text-align-source="fix"
|
||||||
@ -69,7 +65,7 @@
|
|||||||
<style:text-properties fo:font-weight="bold"/>
|
<style:text-properties fo:font-weight="bold"/>
|
||||||
</style:style>
|
</style:style>
|
||||||
|
|
||||||
<!-- Style for cells with the segment text -->
|
<!-- Style for the cells that contain the segment text. -->
|
||||||
<style:style style:name="ce2" style:family="table-cell"
|
<style:style style:name="ce2" style:family="table-cell"
|
||||||
style:parent-style-name="Default">
|
style:parent-style-name="Default">
|
||||||
<style:table-cell-properties fo:wrap-option="wrap"
|
<style:table-cell-properties fo:wrap-option="wrap"
|
||||||
@ -79,42 +75,60 @@
|
|||||||
|
|
||||||
<office:body>
|
<office:body>
|
||||||
<office:spreadsheet>
|
<office:spreadsheet>
|
||||||
<table:table table:style-name="ta1">
|
<table:table>
|
||||||
<!-- Set the format for a number of columns equal to
|
|
||||||
the number of languages in the imported TMX file -->
|
<!-- Get the number of languages in the TMX. -->
|
||||||
<table:table-column table:style-name="co1"
|
<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'
|
||||||
table:number-columns-repeated="{$numLangs}"
|
table:number-columns-repeated="{$numLangs}"
|
||||||
table:default-cell-style-name="ce2"/>
|
table:default-cell-style-name="ce2"/>
|
||||||
|
|
||||||
<!-- Fill in the language headers in the first row
|
<!-- Create the header row and retrieve the languages.
|
||||||
The use of the "local-name()" function enables
|
Use the mode attribute to retrieve the language attribute
|
||||||
the filter to handle older versions that use the
|
from the <tuv> segment text. -->
|
||||||
"lang" attribute as well as recent versions that
|
|
||||||
use the "xml:lang"` attributes -->
|
<!-- 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">
|
<table:table-row table:style-name="ro1">
|
||||||
<xsl:for-each select="$firstTU/tuv">
|
<xsl:apply-templates select="//tu[1]/tuv" mode="lang"/>
|
||||||
<table:table-cell table:style-name="heading">
|
<table:table-column table:style-name="co1"/>
|
||||||
<text:p>
|
|
||||||
<xsl:value-of select="@*[local-name()='lang']"/>
|
|
||||||
</text:p>
|
|
||||||
</table:table-cell>
|
|
||||||
</xsl:for-each>
|
|
||||||
</table:table-row>
|
</table:table-row>
|
||||||
|
|
||||||
<!-- Process the <tu> and <tuv> elements in the TMX file:
|
<!-- Get the text of each <tuv> in each <tu>. -->
|
||||||
One row per tu, one column per segment in each <tuv>. -->
|
<xsl:apply-templates select="//tu"/>
|
||||||
<xsl:for-each select="tmx/body/tu">
|
|
||||||
<table:table-row table:style-name="ro1">
|
|
||||||
<xsl:for-each select="tuv">
|
|
||||||
<table:table-cell>
|
|
||||||
<text:p><xsl:value-of select="seg"/></text:p>
|
|
||||||
</table:table-cell>
|
|
||||||
</xsl:for-each>
|
|
||||||
</table:table-row>
|
|
||||||
</xsl:for-each>
|
|
||||||
</table:table>
|
</table:table>
|
||||||
</office:spreadsheet>
|
</office:spreadsheet>
|
||||||
</office:body>
|
</office:body>
|
||||||
</office:document-content>
|
</office:document-content>
|
||||||
</xsl:template>
|
</xsl:template>
|
||||||
|
|
||||||
|
<!-- 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>
|
||||||
|
<xsl:value-of select="seg"/>
|
||||||
|
</text:p>
|
||||||
|
</table:table-cell>
|
||||||
|
</xsl:template>
|
||||||
</xsl:stylesheet>
|
</xsl:stylesheet>
|
Loading…
Reference in New Issue
Block a user