root/other-projects/gti/gti-xml-to-spreadsheet.xsl @ 31505

Revision 25288, 4.8 KB (checked in by ak19, 7 years ago)

For ease of import and export in Excel, these scripts no longer generates a spreadsheet .txt file of comma separated values but of tab separated values.

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:tmx="http://www.lisa.org/tmx14">
3  <!-- For character entities: http://www.w3.org/MarkUp/html3/latin1.html -->
4  <!-- The necessity for using xml namespaces all over and matching on namespaced element names http://www.stylusstudio.com/xsllist/200302/post70120.html -->
5
6  <!-- HOW AND WHEN TO USE THIS FILE
7       1. Generate an xml file containing the chunks requiring work.
8       GS2/bin/script> perl -S gti.pl get-first-n-chunks-requiring-work mi coredm 1000 > ../../macros/maori/mi-core.xml
9
10       2. Apply this XSLT to that XML file to obtain a unicode text file containing tab-separated values (a spreadsheet).
11       NOTE: Make sure the output is a *.txt file if you wish to open it in Excel without losing the unicode
12       (when opened with .csv extension, the unicode is not preserved).
13
14       GS2/bin/script> java -cp /research/ak19/gs2-svn/bin/java/ApplyXSLT.jar org.nzdl.gsdl.ApplyXSLT -x ../../macros/maori/mi-core.xml -t ../script/gti-xml-to-spreadsheet.xsl > ../../maori/core-mi-spreadsheet.txt
15
16       3. Translators wishing to read this text file into Excel, need to first open Excel.
17       Then go to File > Open, set the filetypes drop-down to show All Files *.*,
18       and choose to open the unicode .txt file containing the tab-separated values.
19
20       - A wizard will appear, allowing users to open this .txt file as a proper spreadsheet.
21       In the first frame of this dialog, need to specify
22       a. on the left that the file is "delimited"
23       b. in the drop down on the right, select unicode (UTF-8 or UTF-16)
24       c. Click next
25       In the second frame of the dialog, select "tab" as the delimiter. Click Finish to open the spreadsheet data.
26       
27       4. When translators have finished working on the file, save it as an Excel spreadsheet Unicode .txt file
28       (through File > Save As > Excel 2003 spreadsheet > choose Unicode .txt in the file types box)
29       and mail this text file back to Greenstone.
30
31       5. The file returned by the translator should first be processed with the new gti-process-google-spreadsheet.pl script:
32       GS2/bin/script>perl -S gti-process-google-spreadsheet.pl ~/Desktop/core-mi-xml2spreadsheet-out.txt > <language>-submission.xml
33
34       Then continue processing as usual
35       > cat <language>-submission.xml | perl -S gti.pl submit-translations <language-code> <module-name> <username>
36
37    -->
38
39  <xsl:output method="text" encoding="UTF-16"/> <!-- When we save as txt from Excel, we choose UTF-16 too -->
40
41  <xsl:template match="GTIResponse">
42    <xsl:text>Key&#09;Source&#09;Target</xsl:text><!--column headings separated by tabs-->
43    <xsl:text>&#10;</xsl:text> <!--newline--> 
44    <xsl:apply-templates select="ChunksRequiringUpdating"/>
45    <xsl:apply-templates select="ChunksRequiringTranslation"/>
46  </xsl:template>
47
48  <xsl:template match="ChunksRequiringTranslation">
49    <xsl:apply-templates select="Chunk">
50      <xsl:sort select="@key"/>
51    </xsl:apply-templates>
52  </xsl:template>
53
54  <xsl:template match="ChunksRequiringUpdating">
55    <xsl:apply-templates select="Chunk">
56      <xsl:sort select="@key"/>
57    </xsl:apply-templates>
58  </xsl:template>
59
60
61  <xsl:template match="Chunk">
62    <xsl:value-of select="@key"/>
63    <xsl:text>&#09;</xsl:text>
64    <xsl:for-each select="SourceFileText">
65      <xsl:variable name="escapedText" select='java:org.nzdl.gsdl.ApplyXSLT.replaceAll(., "\n", "&amp;#10;")'/>
66      <!--<xsl:variable name="tempText2" select="java:org.nzdl.gsdl.ApplyXSLT.replaceAll($tempText1, '&#92;&#34;', '&amp;#34;')"/>--> <!-- escape (backslash-)quote with entity for quote-->
67      <!--<xsl:variable name="escapedText" select='java:org.nzdl.gsdl.ApplyXSLT.replaceAll($tempText1, ",", "&amp;#44;")'/>--> <!--Escape commas in text, as they are not CSV delimiters-->
68      <xsl:value-of select='$escapedText' disable-output-escaping="yes"/>
69    </xsl:for-each>
70    <!--<xsl:value-of select="SourceFileText"/>-->
71    <xsl:text>&#09;</xsl:text>
72    <xsl:for-each select="TargetFileText">
73      <xsl:variable name="escapedText" select='java:org.nzdl.gsdl.ApplyXSLT.replaceAll(., "\n", "&amp;#10;")'/>
74      <!--<xsl:variable name="tempText2" select="java:org.nzdl.gsdl.ApplyXSLT.replaceAll($tempText1, '&#92;&#34;', '&amp;#34;')"/>--> <!-- escape (backslash-)quote with entity for quote-->
75      <!--<xsl:variable name="escapedText" select='java:org.nzdl.gsdl.ApplyXSLT.replaceAll($tempText1, ",", "&amp;#44;")'/>--> <!--Escape commas in text, as they are not CSV delimiters-->
76      <xsl:value-of select='$escapedText' disable-output-escaping="yes"/>
77    </xsl:for-each>
78    <!--<xsl:value-of select="TargetFileText"/>-->
79    <xsl:text>&#10;</xsl:text> 
80  </xsl:template>
81
82</xsl:stylesheet>
Note: See TracBrowser for help on using the browser.