Index: /other-projects/gti/gti-generate-tmx-xml.xsl
===================================================================
--- /other-projects/gti/gti-generate-tmx-xml.xsl	(revision 25286)
+++ /other-projects/gti/gti-generate-tmx-xml.xsl	(revision 25287)
@@ -6,4 +6,32 @@
 More information: http://xml.coverpages.org/tmxSpec971212.html#O-TMF-->
 
+   <!-- HOW AND WHEN TO USE THIS FILE
+	A Translation Memory eXchange (TMX) file is an openXML file that contains translated strings that can serve as 
+	a reference library for future translation work.
+
+	When users want to take all the up to date translated strings in Greenstone and use it in the Google Translator Kit 
+	(GTT) as the basis to continue their translation work on the remaining strings (yet to be translated), this XSLT file 
+	can be used to generate a TMX from the already-translated strings. The user can then upload this into the GTT.
+	Further translation work that the translator does in the GTT will be added to its growing internal TMX file which
+	appears to be inaccessible.
+
+	The process of generating a TMX file of Greenstone's up to date strings for a language is as follows:
+
+       1. Generate an xml file containing all the up to date chunks (those strings that don't require translation work).
+	GS2/bin/java>perl -S gti.pl get-uptodate-chunks mi coredm > ../../macros/maori/uptodatechunks_core.xml
+
+       2. Generate a TMX file from that XML file as follows:
+       GS2/bin/java>java -cp /research/ak19/gs2-svn/bin/java/ApplyXSLT.jar org.nzdl.gsdl.ApplyXSLT -x ../../macros/maori/uptodatechunks_core.xml -t ../script/gti-generate-tmx-xml.xsl -l mi > ../../maori/uptodatecore-mi.tmx
+
+       GS2/bin/java>less ../../maori/uptodatecore-mi.tmx
+
+       3. Send this to the user and they can upload it into GTT.
+
+   
+       (The DOCTYPE has only been commented out below in order to let a further XSLT process the output of this file into a spreadsheet .txt file.
+        Since a third XSLT file exists which operates on another XML file to obtain the spreadsheet .txt file, the DOCTYPE can be reinstated if required.)
+    -->
+
+
   <xsl:output method="xml" encoding="UTF-8"/>
   <xsl:param name="sourcelang"/>
@@ -11,5 +39,7 @@
 
   <xsl:template match="GTIResponse">
-    <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>
+    <!-- if applying this XSLT file results in an error mentioning ".../tmx14.dtd (No such file or directory)" 
+	 then comment out the DOCTYPE declaration below -->
+    <!--<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>-->
 
     <tmx version="1.4" xmlns="http://www.lisa.org/tmx14"><xsl:text>&#10;</xsl:text> <!--newline-->
@@ -21,5 +51,5 @@
        adminlang="en"
        srclang="{$sourcelang}"
-       o-tmf="GreenstoneTranslationFile"> <!--XLIFF 1.2-->
+       o-tmf="GreenstoneTranslationFile">
     </header><xsl:text>&#10;</xsl:text> <!--newline-->
     <body>
Index: /other-projects/gti/gti-tmx-to-spreadsheet.xsl
===================================================================
--- /other-projects/gti/gti-tmx-to-spreadsheet.xsl	(revision 25287)
+++ /other-projects/gti/gti-tmx-to-spreadsheet.xsl	(revision 25287)
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+  <!-- For character entities: http://www.w3.org/MarkUp/html3/latin1.html -->
+  <!-- The necessity for using xml namespaces all over and matching on namespaced element names http://www.stylusstudio.com/xsllist/200302/post70120.html -->
+
+   <!-- HOW AND WHEN TO USE THIS FILE
+       1. Generate an xml file containing the chunks requiring work.
+       GS2/bin/script> perl -S gti.pl get-first-n-chunks-requiring-work mi coredm 1000 > ../../macros/maori/mi-core.xml
+
+       2. Generate a TMX file from that XML file as follows:
+       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-generate-tmx-xml.xsl -l mi > ../../maori/core-mi.tmx
+
+       3. Apply this XSLT to that XML file to obtain a unicode text file containing comma-separated values (a spreadsheet). 
+       NOTE: Make sure the output is a *.txt file if you wish to open it in Excel without losing the unicode 
+       (when opened with .csv extension, the unicode is not preserved).
+
+       GS2/bin/script> java -cp /research/ak19/gs2-svn/bin/java/ApplyXSLT.jar org.nzdl.gsdl.ApplyXSLT -x ../../maori/core-mi.tmx -t ../script/gti-tmx-to-spreadsheet.xsl > ../../maori/core-mi-tmx2spreadsheet.txt
+
+       4. Translators wishing to read this text file into Excel, need to first open Excel. Then go to File > Open, 
+       and choose to open the unicode .txt file containing the comma-separated values.
+
+       - A wizard will appear, allowing users to open this .txt file as a proper spreadsheet.
+       In the first frame of this dialog, need to specify
+       a. on the left that the file is "delimited"
+       b. in the drop down on the right, select unicode (UTF-8 or UTF-16)
+       c. Click next
+       In the second frame of the dialog, select "comma" as the delimiter. Click Finish to open the spreadsheet data.
+       
+       5. When translators have finished working on the file, they can save it simply as an Excel spreadsheet .xls file 
+       (File > Save As > Excel 2003 spreadsheet) and mail it back to Greenstone.
+       Translators are advised against saving it as a .txt 2003 Excel spreadsheet, since it doesn't seem to preserve the
+       comma delimiters.
+    -->
+
+  <xsl:output method="text" encoding="UTF-16"/> <!-- When we save as txt from Excel, we choose UTF-16 too -->
+
+  <xsl:template match="tmx:tmx">
+    <xsl:apply-templates select="tmx:body"/>
+  </xsl:template>
+
+  <xsl:template match="tmx:body">
+    <xsl:text>Source key&#44;Source text&#44;Target key&#44;Target text</xsl:text><!--column headings-->
+    <xsl:text>&#10;</xsl:text> <!--newline-->  
+    <xsl:apply-templates select="tmx:tu"/>
+  </xsl:template>
+
+  <xsl:template match="tmx:tu">
+    <xsl:for-each select="tmx:tuv">
+      <xsl:if test="tmx:prop[@type='source']">
+	<xsl:text>source::</xsl:text>
+	<xsl:value-of select="tmx:prop"/>
+	<xsl:text>&#44;</xsl:text><!-- comma -->
+	<xsl:variable name="tempText1"><xsl:value-of select="tmx:seg"/></xsl:variable>
+	<xsl:variable name="tempText2" select='java:org.nzdl.gsdl.ApplyXSLT.replaceAll($tempText1, "&amp;#10;&#10;", "&amp;#10;")'/>
+	<xsl:variable name="tempText3" select='java:org.nzdl.gsdl.ApplyXSLT.replaceAll($tempText2, "&amp;lt;", "&#60;")'/>
+	<xsl:variable name="tempText4" select='java:org.nzdl.gsdl.ApplyXSLT.replaceAll($tempText3, "&amp;gt;", "&#62;")'/>
+	<xsl:variable name="escapedText" select='java:org.nzdl.gsdl.ApplyXSLT.replaceAll($tempText4, "&amp;amp;", "&#38;")'/>
+	<xsl:value-of select='$escapedText' disable-output-escaping="yes"/>
+	<xsl:text>&#44;</xsl:text><!-- comma -->
+	</xsl:if>
+    </xsl:for-each>
+
+    <xsl:for-each select="tmx:tuv">
+      <xsl:if test="tmx:prop[@type='target']">
+	<xsl:text>target::</xsl:text>
+	<xsl:value-of select="tmx:prop"/>
+	<xsl:text>&#44;</xsl:text><!-- comma -->
+	<xsl:variable name="tempText1"><xsl:value-of select="tmx:seg"/></xsl:variable>
+	<xsl:variable name="tempText2" select='java:org.nzdl.gsdl.ApplyXSLT.replaceAll($tempText1, "&amp;#10;&#10;", "&amp;#10;")'/>
+	<xsl:variable name="tempText3" select='java:org.nzdl.gsdl.ApplyXSLT.replaceAll($tempText2, "&amp;lt;", "&#60;")'/>
+	<xsl:variable name="tempText4" select='java:org.nzdl.gsdl.ApplyXSLT.replaceAll($tempText3, "&amp;gt;", "&#62;")'/>
+	<xsl:variable name="escapedText" select='java:org.nzdl.gsdl.ApplyXSLT.replaceAll($tempText4, "&amp;amp;", "&#38;")'/>
+	<xsl:value-of select='$escapedText' disable-output-escaping="yes"/>
+	<xsl:text>&#10;</xsl:text><!-- newline -->
+      </xsl:if>
+    </xsl:for-each>
+  </xsl:template>
+
+</xsl:stylesheet>
Index: /other-projects/gti/gti-tmx-to-txt.xsl
===================================================================
--- /other-projects/gti/gti-tmx-to-txt.xsl	(revision 25286)
+++ /other-projects/gti/gti-tmx-to-txt.xsl	(revision 25287)
@@ -1,5 +1,33 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <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">
+  <!-- For character entities: http://www.w3.org/MarkUp/html3/latin1.html -->
   <!-- The necessity for using xml namespaces all over and matching on namespaced element names http://www.stylusstudio.com/xsllist/200302/post70120.html -->
+
+  <!-- HOW AND WHEN TO USE THIS FILE
+       This file (obsolete) is used to produce the intermediate text file required from a translated TMX file sent in by the user. This intermediate text file, consisting of
+       2 columns of data, is then fed into the existing pipeline of processing translated spreadsheets, so that translation updates can be committed back into the GS repository.
+       
+       This assumes that the file returned by the translator is a TMX file also. In practice, this is unlikely to be the case when using GTT, since it does not allow downloading
+       of GTT files. That is why this XSLT file is obsolete.
+       However, it's use on an input TMX file is explained below.
+
+
+       1. Generate an xml file containing the chunks requiring work.
+       GS2/bin/script> perl -S gti.pl get-first-n-chunks-requiring-work mi coredm 1000 > ../../macros/maori/mi-core.xml
+
+       2. Generate a TMX file from that XML file as follows:
+       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-generate-tmx-xml.xsl -l mi > ../../maori/core-mi.tmx
+
+       3. Once the user has finished translating, and ONLY ASSUMING the file they return is a TMX file again, apply this XSLT to obtain the .txt required:
+       GS2/bin/java>java -cp /research/ak19/gs2-svn/bin/java/ApplyXSLT.jar org.nzdl.gsdl.ApplyXSLT -x ../../maori/core-mi.tmx -t ../script/gti-tmx-to-txt.xsl > ../../maori/core-mi.txt
+  
+  
+       4. Try processing this UTF-16 text file as before, as explained on the wiki: http://internal.greenstone.org/wiki/GTI
+
+       > perl -S gti-process-spreadsheet.pl language.txt > language-submission.xml
+       > cat language-submission.xml | perl -S gti.pl submit-translations language-code module-name username
+       (There are extra steps when GLI help files are translated, see the internal.greenstone wiki page again).
+
+    -->
 
   <xsl:output method="text" encoding="UTF-16"/> <!-- When we save as txt from Excel, we choose UTF-16 too -->
Index: /other-projects/gti/gti-xml-to-spreadsheet.xsl
===================================================================
--- /other-projects/gti/gti-xml-to-spreadsheet.xsl	(revision 25287)
+++ /other-projects/gti/gti-xml-to-spreadsheet.xsl	(revision 25287)
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+  <!-- For character entities: http://www.w3.org/MarkUp/html3/latin1.html -->
+  <!-- The necessity for using xml namespaces all over and matching on namespaced element names http://www.stylusstudio.com/xsllist/200302/post70120.html -->
+
+  <!-- HOW AND WHEN TO USE THIS FILE
+       1. Generate an xml file containing the chunks requiring work.
+       GS2/bin/script> perl -S gti.pl get-first-n-chunks-requiring-work mi coredm 1000 > ../../macros/maori/mi-core.xml
+
+       2. Apply this XSLT to that XML file to obtain a unicode text file containing comma-separated values (a spreadsheet). 
+       NOTE: Make sure the output is a *.txt file if you wish to open it in Excel without losing the unicode 
+       (when opened with .csv extension, the unicode is not preserved).
+
+       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
+
+       3. Translators wishing to read this text file into Excel, need to first open Excel. Then go to File > Open, 
+       and choose to open the unicode .txt file containing the comma-separated values.
+
+       - A wizard will appear, allowing users to open this .txt file as a proper spreadsheet.
+       In the first frame of this dialog, need to specify
+       a. on the left that the file is "delimited"
+       b. in the drop down on the right, select unicode (UTF-8 or UTF-16)
+       c. Click next
+       In the second frame of the dialog, select "comma" as the delimiter. Click Finish to open the spreadsheet data.
+       
+       4. When translators have finished working on the file, they can save it simply as an Excel spreadsheet .xls file 
+       (File > Save As > Excel 2003 spreadsheet) and mail it back to Greenstone.
+       Translators are advised against saving it as a .txt 2003 Excel spreadsheet, since it doesn't seem to preserve the
+       comma delimiters.
+
+    -->
+
+  <xsl:output method="text" encoding="UTF-16"/> <!-- When we save as txt from Excel, we choose UTF-16 too -->
+
+  <xsl:template match="GTIResponse">
+    <xsl:text>Key&#44;Source&#44;Target</xsl:text><!--column headings-->
+    <xsl:text>&#10;</xsl:text> <!--newline-->  
+    <xsl:apply-templates select="ChunksRequiringUpdating"/>
+    <xsl:apply-templates select="ChunksRequiringTranslation"/>
+  </xsl:template>
+
+  <xsl:template match="ChunksRequiringTranslation">
+    <xsl:apply-templates select="Chunk">
+      <xsl:sort select="@key"/>
+    </xsl:apply-templates>
+  </xsl:template>
+
+  <xsl:template match="ChunksRequiringUpdating">
+    <xsl:apply-templates select="Chunk">
+      <xsl:sort select="@key"/>
+    </xsl:apply-templates>
+  </xsl:template>
+
+
+  <xsl:template match="Chunk">
+    <xsl:value-of select="@key"/>
+    <xsl:text>&#44;</xsl:text>
+    <xsl:for-each select="SourceFileText">
+      <xsl:variable name="escapedText" select='java:org.nzdl.gsdl.ApplyXSLT.replaceAll(., "\n", "&amp;#10;")'/>
+      <xsl:value-of select='$escapedText' disable-output-escaping="yes"/>
+    </xsl:for-each>
+    <!--<xsl:value-of select="SourceFileText"/>-->
+    <xsl:text>&#44;</xsl:text>
+    <xsl:for-each select="TargetFileText">
+      <xsl:variable name="escapedText" select='java:org.nzdl.gsdl.ApplyXSLT.replaceAll(., "\n", "&amp;#10;")'/>
+      <xsl:value-of select='$escapedText' disable-output-escaping="yes"/>
+    </xsl:for-each>
+    <!--<xsl:value-of select="TargetFileText"/>-->
+    <xsl:text>&#10;</xsl:text>  
+  </xsl:template>
+
+</xsl:stylesheet>
