root/other-projects/gti/gti-generate-tmx-xml.xsl @ 25286

Revision 25286, 6.2 KB (checked in by ak19, 8 years ago)

Updated to deal with paperspast.dm: added a new module into gti.pl for this. Because getting chunks from the paperspast.dm file results in attribute like values in the source and target strings, there are now functions in ApplyXSLT.java to remove and retrieve these. Finally, the function to remove these attribute-like values in the source and target strings is called in the gti-generate-tmx-xml.xslt file.

Line 
1<?xml version="1.0" encoding="UTF-8"?>
2<!--<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:java="http://xml.apache.org/xslt/java" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">-->
3<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:java="http://xml.apache.org/xslt/java">
4<!--On Translation Memory eXchange open-XML: http://www.opentag.com/tmx.htm and http://www.gala-global.org/oscarStandards/tmx/tmx14b.html
5And for character entities: http://www.w3.org/MarkUp/html3/latin1.html
6More information: http://xml.coverpages.org/tmxSpec971212.html#O-TMF-->
7
8  <xsl:output method="xml" encoding="UTF-8"/>
9  <xsl:param name="sourcelang"/>
10  <xsl:param name="targetlang"/>
11
12  <xsl:template match="GTIResponse">
13    <xsl:text disable-output-escaping="yes">&#10;&lt;!DOCTYPE tmx PUBLIC &quot;-//LISA OSCAR:1998//DTD for Translation Memory eXchange//EN&quot; &quot;tmx14.dtd&quot; &gt;&#10;</xsl:text>
14
15    <tmx version="1.4" xmlns="http://www.lisa.org/tmx14"><xsl:text>&#10;</xsl:text> <!--newline-->
16    <header
17       creationtool="Greenstone Translator Interface"
18       creationtoolversion="Greenstone2.85"
19       datatype="PlainText"
20       segtype="sentence"
21       adminlang="en"
22       srclang="{$sourcelang}"
23       o-tmf="GreenstoneTranslationFile"> <!--XLIFF 1.2-->
24    </header><xsl:text>&#10;</xsl:text> <!--newline-->
25    <body>
26      <xsl:text>&#10;&#10;</xsl:text> <!--2 newlines-->
27      <xsl:apply-templates select="TranslationFile"/>
28
29
30      <xsl:apply-templates select="Chunks"/>
31
32      <xsl:apply-templates select="UptodateChunks"/>
33
34      <!-- control the order: first all the strings needing to be updated, then all those that need translating-->
35      <xsl:apply-templates select="ChunksRequiringUpdating"/>
36      <xsl:apply-templates select="ChunksRequiringTranslation"/>
37    </body>
38    </tmx>
39  </xsl:template>
40
41
42  <!-- The input file contains information as follows:
43     <TranslationFile key="coredm" target_file_path="macros/mongolian.dm" num_chunks_translated="353" num_chunks_requiring_translation="32" num_chunks_requiring_updating="18"/>
44     We want this useful information to be present in the output TMX file too. Each attribute of a TranslationFile element will be a separate <prop> property value,
45       where the TranslationFile attribute names become the values of each property's type attribute, and the TranslationFile attribute values are the property contents.-->
46  <xsl:template match="TranslationFile">
47    <xsl:for-each select="@*">
48      <prop type="{name()}"><xsl:value-of select="."/></prop>
49      <xsl:text>&#10;</xsl:text><!--newline-->
50    </xsl:for-each>
51  </xsl:template>
52
53  <xsl:template match="UptodateChunks">
54    <xsl:text>&#10;</xsl:text>
55    <note><xsl:text xml:lang="en">Uptodate chunks</xsl:text></note><xsl:text>&#10;</xsl:text>
56    <xsl:apply-templates select="Chunk">
57      <xsl:sort select="@key"/>
58    </xsl:apply-templates>
59  </xsl:template>
60
61  <xsl:template match="ChunksRequiringTranslation">
62    <xsl:text>&#10;</xsl:text> <!--newline-->
63    <note><xsl:text xml:lang="en">Chunks requiring translating</xsl:text></note><xsl:text>&#10;</xsl:text> <!--newline-->
64    <xsl:apply-templates select="Chunk">
65      <xsl:sort select="@key"/>
66    </xsl:apply-templates>
67  </xsl:template>
68
69  <xsl:template match="ChunksRequiringUpdating">
70    <xsl:text>&#10;</xsl:text> <!--newline-->     
71    <note><xsl:text xml:lang="en">Chunks requiring updating</xsl:text></note><xsl:text>&#10;</xsl:text> <!--newline-->
72    <xsl:apply-templates select="Chunk">
73      <xsl:sort select="@key"/>
74    </xsl:apply-templates>
75  </xsl:template>
76
77  <xsl:template match="Chunks">
78    <xsl:text>&#10;</xsl:text>
79    <note><xsl:text xml:lang="en">All chunks</xsl:text></note><xsl:text>&#10;</xsl:text>
80    <xsl:apply-templates select="Chunk">
81      <xsl:sort select="@key"/>
82    </xsl:apply-templates>
83  </xsl:template>
84
85
86  <xsl:template match="Chunk">
87    <tu><xsl:text>&#10;</xsl:text> <!--newline-->
88      <tuv xml:lang="{$sourcelang}">
89    <prop type="source"><xsl:value-of select="@key"/></prop><xsl:text>&#10;</xsl:text> <!--newline-->
90    <seg>
91      <xsl:for-each select="SourceFileText">
92        <xsl:variable name="tempText0" select='java:org.nzdl.gsdl.ApplyXSLT.getChunkString(.)'/> <!-- removes collection-specific attribute-like prefix in paperspast.dm-->
93        <xsl:variable name="tempText1" select='java:org.nzdl.gsdl.ApplyXSLT.replaceAll($tempText0, "\n", "&amp;#10;&#10;")'/>
94        <xsl:variable name="tempText2" select='java:org.nzdl.gsdl.ApplyXSLT.replaceAll($tempText1, "&#60;", "&amp;lt;")'/>
95        <xsl:variable name="tempText3" select='java:org.nzdl.gsdl.ApplyXSLT.replaceAll($tempText2, "&#62;", "&amp;gt;")'/>
96        <xsl:variable name="escapedText" select='java:org.nzdl.gsdl.ApplyXSLT.replaceAll($tempText3, "&#38;", "&amp;amp;")'/> <!-- ampersands-->
97        <xsl:value-of select='$escapedText' disable-output-escaping="yes"/>
98          </xsl:for-each>
99    </seg><xsl:text>&#10;</xsl:text> <!--newline-->
100      </tuv><xsl:text>&#10;</xsl:text> <!--newline-->
101      <tuv xml:lang="{$targetlang}">
102    <prop type="target"><xsl:value-of select="@key"/></prop><xsl:text>&#10;</xsl:text> <!--newline-->
103    <seg>
104      <xsl:for-each select="TargetFileText">
105        <xsl:variable name="tempText0" select='java:org.nzdl.gsdl.ApplyXSLT.getChunkString(.)'/> <!-- removes collection-specific attribute-like prefix in paperspast.dm-->
106        <xsl:variable name="tempText1" select='java:org.nzdl.gsdl.ApplyXSLT.replaceAll($tempText0, "\n", "&amp;#10;&#10;")'/>
107        <xsl:variable name="tempText2" select='java:org.nzdl.gsdl.ApplyXSLT.replaceAll($tempText1, "&#60;", "&amp;lt;")'/>
108        <xsl:variable name="tempText3" select='java:org.nzdl.gsdl.ApplyXSLT.replaceAll($tempText2, "&#62;", "&amp;gt;")'/>
109        <xsl:variable name="escapedText" select='java:org.nzdl.gsdl.ApplyXSLT.replaceAll($tempText3, "&#38;", "&amp;amp;")'/> <!-- ampersands-->
110        <xsl:value-of select='$escapedText' disable-output-escaping="yes"/>
111          </xsl:for-each>
112    </seg><xsl:text>&#10;</xsl:text> <!--newline-->
113      </tuv><xsl:text>&#10;</xsl:text> <!--newline-->
114    </tu><xsl:text>&#10;&#10;</xsl:text> <!--newline-->
115  </xsl:template>
116
117  <!--<xsl:template match="*">Do nothing for all other templates matched</xsl:template>-->
118
119</xsl:stylesheet>
Note: See TracBrowser for help on using the browser.