XSLT_TAO/filtres_TMX_pour_Calc/TMX-import.xsl

98 lines
5.1 KiB
XML

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- 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. -->
<!-- Copyright 2013 Dominique Meeùs.
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:template match="/">
<office:document-content
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:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
xmlns:math="http://www.w3.org/1998/Math/MathML"
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
xmlns:ooo="http://openoffice.org/2004/office"
xmlns:ooow="http://openoffice.org/2004/writer"
xmlns:oooc="http://openoffice.org/2004/calc"
xmlns:dom="http://www.w3.org/2001/xml-events"
xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
office:version="1.0">
<office:automatic-styles>
<!-- Properties of the table -->
<style:style style:name="ta1" style:family="table" style:master-page-name="Default">
<style:table-properties table:display="true" style:writing-mode="lr-tb"/>
</style:style>
<!-- Properties of the columns -->
<!-- I consider the case of a two-languages TMX -->
<!-- Todo : pass the source and target languages as attributes to the text in Calc -->
<style:style style:name="co1" style:family="table-column"><!-- source language -->
<style:table-column-properties fo:break-before="auto" style:column-width="16.000cm"/>
</style:style>
<style:style style:name="co2" style:family="table-column"><!-- target language -->
<style:table-column-properties fo:break-before="auto" style:column-width="16.000cm"/>
</style:style>
<!-- Properties of the rows -->
<!-- The rows are “optimal height” but do not expand for the “wrap option” of the cells -->
<style:style style:name="ro1" style:family="table-row">
<style:table-row-properties fo:break-before="auto" style:use-optimal-row-height="true"/>
</style:style>
<!-- Properties of the cells -->
<style:style style:name="ce1" style:family="table-cell" style:parent-style-name="Default">
<style:table-cell-properties fo:wrap-option="wrap"/>
</style:style>
<style:style style:name="ce2" style:family="table-cell" style:parent-style-name="Default">
<style:table-cell-properties fo:wrap-option="wrap"/>
</style:style>
</office:automatic-styles>
<office:body>
<office:spreadsheet>
<table:table>
<!-- Format of the columns -->
<!-- How about a free number of columns ? -->
<table:table-column table:style-name="co1" table:default-cell-style-name="ce1"/>
<table:table-column table:style-name="co2" table:default-cell-style-name="ce2"/>
<!-- Process XML of the input TMX file: one row for each tu, one cell for the segment in each tuv -->
<xsl:for-each select="tmx/body/tu">
<table:table-row>
<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>
</office:spreadsheet>
</office:body>
</office:document-content>
</xsl:template>
</xsl:stylesheet>