Index: /main/trunk/greenstone2/build-src/src/java/org/nzdl/gsdl/ApplyXSLT.java
===================================================================
--- /main/trunk/greenstone2/build-src/src/java/org/nzdl/gsdl/ApplyXSLT.java	(revision 28972)
+++ /main/trunk/greenstone2/build-src/src/java/org/nzdl/gsdl/ApplyXSLT.java	(revision 28973)
@@ -160,4 +160,10 @@
 		
       }
+
+      //if(br != null) {
+      //  br.close();
+      //  br = null;
+      //}
+      
     }catch (Exception e)
       {
@@ -166,4 +172,40 @@
 				
     return false;
+  }
+  
+    // reads xml from stdin, but no <?DocStart?><?DocEnd?> markers, and sends output to STDOUT
+  private boolean processPipedFromStdIn()
+  {
+      try{
+	  //System.err.println("Received nothing\n");      
+	  
+	  ReadStreamGobbler readInStreamGobbler = new ReadStreamGobbler(System.in, true);
+	  readInStreamGobbler.start();
+	  readInStreamGobbler.join();
+	  String outputstr = readInStreamGobbler.getOutput();
+
+	  // Using join() above, even though we use only one streamGobbler thread, and even
+	  // though we're not dealing with the input/output/error streams of a Process object.
+	  // But the join() call here didn't break things.
+	  // http://www.javaworld.com/article/2071275/core-java/when-runtime-exec---won-t.html?page=2
+	  
+	  boolean result = false;
+	  if (mapping_file !=null && !mapping_file.equals("")){
+	      result = translateXMLWithMapping(outputstr, null); // null: no outputfile, send to STDOUT
+	  }
+	  else{
+	      result = translateXML(outputstr, null); // null: no outputfile, send to STDOUT
+	  }
+	  
+	  if (!result){
+	      System.err.println("Translation Failed!!");
+	      return false;
+	  } else {
+	      return true;   
+	  }
+      }catch (Exception e) {
+	  System.err.println("Receiving piped data error!" + e.toString());
+      } 
+      return false;
   }
     
@@ -180,5 +222,9 @@
     setTransformerParams(transformer); // sourcelang and targetlang and any further custom parameters to be passed into the XSLT
 
-    transformer.transform(new StreamSource(str), new StreamResult(new FileOutputStream(output_file)));
+    if(output_file != null) {
+	transformer.transform(new StreamSource(str), new StreamResult(new FileOutputStream(output_file)));
+    } else {
+	transformer.transform(new StreamSource(str), new StreamResult(System.out));
+    }
     return true;
   }
@@ -437,4 +483,6 @@
     String targetlang="";
 
+    boolean readFromStdInFlag = false;
+
     HashMap paramMap = new HashMap();
     int index = -1; // index of the '=' sign in cmdline argument specifying custom parameters to be passed into the XSLT
@@ -470,4 +518,7 @@
       else if(args[i].equals("-l") && i+1 < args.length && !args[i+1].startsWith("-")){
 	targetlang = args[++i];	    
+      }
+      else if(args[i].equals("-c")){
+	  readFromStdInFlag = true;
       }
       else if(args[i].equals("-h")){
@@ -489,5 +540,5 @@
          
     ApplyXSLT core = null;
-	
+
     if (xml_file.equals("") && !xsl_file.equals("")){//read from pipe line
       if (mapping_file.equals("")){ 
@@ -499,5 +550,8 @@
             
       if (core != null){
-	core.process();
+	  if(readFromStdInFlag) { // ApplyXSLT was run with -c: read from pipe but no <?DocStart?><?DocEnd?> markers
+	      core.processPipedFromStdIn();
+	  }
+	core.process(); //read from pipe line, but expecting <?DocStart?><?DocEnd?> embedding markers
       }
       else{
@@ -533,4 +587,5 @@
     System.out.println("Usage: ApplyXSLT -x File -t File [-m File] [-o File] [-s sourcelang] [-l targetlang] [param-name=param-value]");
     System.out.println("\t-x specifies the xml file (Note: optional for piped xml data)");
+    System.out.println("\t-c read xml file piped from stdin but without DocStart/DocEnd markers. Writes to stdout");
     System.out.println("\t-t specifies the xsl file");
     System.out.println("\t-m specifies the mapping file (for MARCXMLPlugout.pm only)");
@@ -541,4 +596,67 @@
     System.exit(-1);
   }
+
+
+    // StreamGobblers used in reading/writing to Process' input and outputstreams can be re-used more generally.
+    // Here in ApplyXSTL.java we use it to read from a pipe line (stdin piped into this ApplyXSLT.java)
+    // Code based on http://www.javaworld.com/article/2071275/core-java/when-runtime-exec---won-t.html?page=2
+    class ReadStreamGobbler extends Thread
+    {
+	InputStream is = null;
+	StringBuffer outputstr = new StringBuffer();
+	boolean split_newlines = false;
+	
+	
+	public ReadStreamGobbler(InputStream is)
+	{
+	    this.is = is;
+	    split_newlines = false;
+	}
+
+	public ReadStreamGobbler(InputStream is, boolean split_newlines)
+	{
+	    this.is = is;
+	    this.split_newlines = split_newlines;
+	}
+	
+	public void run()
+	{
+	    BufferedReader br = null;
+	    try	{
+		br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+		String line=null;
+		while ( (line = br.readLine()) != null) {
+		    //System.out.println("@@@ GOT LINE: " + line);
+		    outputstr.append(line);
+		    if(split_newlines) {
+			outputstr.append("\n");
+		    }
+		}
+	    } catch (IOException ioe) {
+		ioe.printStackTrace();  
+	    } finally {
+		closeResource(br);
+	    }
+	}
+	
+	public String getOutput() { 
+	    return outputstr.toString(); 
+	}
+
+	// http://docs.oracle.com/javase/tutorial/essential/exceptions/finally.html
+	// http://stackoverflow.com/questions/481446/throws-exception-in-finally-blocks
+	public void closeResource(Closeable resourceHandle) {
+	    try {
+		if(resourceHandle != null) {
+		    resourceHandle.close();
+		    resourceHandle = null;
+		}
+	    } catch(Exception e) {
+		System.err.println("Exception closing resource: " + e.getMessage());
+		e.printStackTrace();
+	    }
+	}
+    }
+
 }
 
Index: /main/trunk/greenstone2/build-src/src/java/org/nzdl/gsdl/Makefile.in
===================================================================
--- /main/trunk/greenstone2/build-src/src/java/org/nzdl/gsdl/Makefile.in	(revision 28972)
+++ /main/trunk/greenstone2/build-src/src/java/org/nzdl/gsdl/Makefile.in	(revision 28973)
@@ -15,5 +15,6 @@
 ApplyXSLT.jar: $(CLASSES)
 	$(JAR) cvf ApplyXSLT.jar -C ../../..  org/nzdl/gsdl/ApplyXSLT.class \
-	  -C ../../.. org/nzdl/gsdl/ApplyXSLTUtil.class
+	  -C ../../.. org/nzdl/gsdl/ApplyXSLTUtil.class \
+	  -C ../../.. org/nzdl/gsdl/ApplyXSLT\$$ReadStreamGobbler.class
 
 
Index: /main/trunk/greenstone2/runtime-src/src/recpt/cgiwrapper.cpp
===================================================================
--- /main/trunk/greenstone2/runtime-src/src/recpt/cgiwrapper.cpp	(revision 28972)
+++ /main/trunk/greenstone2/runtime-src/src/recpt/cgiwrapper.cpp	(revision 28973)
@@ -72,4 +72,8 @@
 #endif
 
+#if defined(GSDL_USE_GTI_ACTION)
+#include "gtiaction.h"
+#endif
+
 #if defined(USE_RSS)
 #include "rssaction.h"
Index: /main/trunk/greenstone2/runtime-src/src/recpt/gtiaction.cpp
===================================================================
--- /main/trunk/greenstone2/runtime-src/src/recpt/gtiaction.cpp	(revision 28972)
+++ /main/trunk/greenstone2/runtime-src/src/recpt/gtiaction.cpp	(revision 28973)
@@ -31,4 +31,5 @@
 #include <expat.h>
 #include <stdio.h>
+#include <cstring>
 #include <sys/utsname.h>
 #include "gtiaction.h"
@@ -36,4 +37,5 @@
 #include "fileutil.h"
 #include "gsdlunicode.h"
+#include "gsdltools.h"
 
 
@@ -85,7 +87,19 @@
   text_t set_gsdlos = "GSDLOS=";
 
+  // path to java executable.
+
+  if(java.empty()) {
+    //java = "$JAVA_HOME/bin/java"; // doesn't work
+    //java = "/research/root/jdk1.6.0_27/bin/java"; // can hardcode it, which may be necessary on nzdl or if default java is no longer version 6
+    java = "java";
+  }
+
 #if defined (__WIN32__)
+  path_separator = ";"; // windows (class)PATH separator
+
   set_gsdlos += "windows";
 #else
+  path_separator = ":"; // linux (class)PATH separator
+
   struct utsname *buf = new struct utsname();
   if (uname(buf) == -1) {
@@ -638,7 +652,21 @@
   text_t gti_arguments = "";
   if (target_chunk_type == "work") {
-    gti_arguments = "get-first-n-chunks-requiring-work " + target_language_code + " " + translation_file_key + " " + "10000" + " | /opt/jdk1.6.0/bin/java -cp /home/nzdl/gti:/home/nzdl/gti/xalan.jar ApplyXSLT /home/nzdl/gti/gti-generate-excel-xml.xsl -";
+
+    //gti_arguments = "get-first-n-chunks-requiring-work " + target_language_code + " " + translation_file_key + " " + "10000" + " | /opt/jdk1.6.0/bin/java -cp /home/nzdl/gti:/home/nzdl/gti/xalan.jar ApplyXSLT /home/nzdl/gti/gti-generate-excel-xml.xsl -";
+
+    //gti_arguments = "get-first-n-chunks-requiring-work " + target_language_code + " " + translation_file_key + " " + "10000" + " | /research/root/jdk1.6.0_27/bin/java -cp /research/ak19/gs2-svn-gti:/research/ak19/gs2-svn-gti/bin/java/ApplyXSLT.jar org.nzdl.gsdl.ApplyXSLT -c -t /research/ak19/gs2-svn-gti/bin/script/gti-generate-excel-xml.xsl";
+
+    // don't need to add toplevel gsdlhome to classpath actually, as the following will work from the commandline:
+    // gti.pl get-all-chunks nl coredm | java -cp /research/ak19/gs2-svn-gti/bin/java/ApplyXSLT.jar org.nzdl.gsdl.ApplyXSLT -t /research/ak19/gs2-svn-gti/bin/script/gti-generate-excel-xml.xsl
+    gti_arguments = "get-first-n-chunks-requiring-work " + target_language_code + " " + translation_file_key + " " + "10000" + " | " + java + " -cp " + gsdlhome + path_separator + gsdlhome + "/bin/java/ApplyXSLT.jar org.nzdl.gsdl.ApplyXSLT -c -t " + gsdlhome + "/bin/script/gti-generate-excel-xml.xsl";
+
   } else {
-    gti_arguments = "get-all-chunks " + target_language_code + " " + translation_file_key + " | /opt/jdk1.6.0/bin/java -cp /home/nzdl/gti:/home/nzdl/gti/xalan.jar ApplyXSLT /home/nzdl/gti/gti-generate-excel-xml.xsl -";
+    //gti_arguments = "get-all-chunks " + target_language_code + " " + translation_file_key + " | /opt/jdk1.6.0/bin/java -cp /home/nzdl/gti:/home/nzdl/gti/xalan.jar ApplyXSLT /home/nzdl/gti/gti-generate-excel-xml.xsl -";
+
+    //gti_arguments = "get-all-chunks " + target_language_code + " " + translation_file_key + " | /research/root/jdk1.6.0_27/bin/java -cp /research/ak19/gs2-svn-gti/bin/java/ApplyXSLT.jar org.nzdl.gsdl.ApplyXSLT -c -t /research/ak19/gs2-svn-gti/bin/script/gti-generate-excel-xml.xsl";
+
+    // don't need to add toplevel gsdlhome to classpath actually, as the following will work from the commandline:
+    // gti.pl get-all-chunks nl coredm | java -cp /research/ak19/gs2-svn-gti/bin/java/ApplyXSLT.jar org.nzdl.gsdl.ApplyXSLT -t /research/ak19/gs2-svn-gti/bin/script/gti-generate-excel-xml.xsl
+    gti_arguments = "get-all-chunks " + target_language_code + " " + translation_file_key + " | " + java +  " -cp " + gsdlhome + path_separator + gsdlhome + "/bin/java/ApplyXSLT.jar org.nzdl.gsdl.ApplyXSLT -c -t " + gsdlhome + "/bin/script/gti-generate-excel-xml.xsl";
   }
   
Index: /main/trunk/greenstone2/runtime-src/src/recpt/gtiaction.h
===================================================================
--- /main/trunk/greenstone2/runtime-src/src/recpt/gtiaction.h	(revision 28972)
+++ /main/trunk/greenstone2/runtime-src/src/recpt/gtiaction.h	(revision 28973)
@@ -68,4 +68,7 @@
   char* set_gsdlos_cstr;
 
+  text_t path_separator;
+  text_t java; // java bin path to preferrably 1.6. Set this here or in init() if the path to java is very specific (such as on nzdl)
+
 public:
   gtiaction ();
