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 28382)
+++ main/trunk/greenstone2/build-src/src/java/org/nzdl/gsdl/ApplyXSLT.java	(revision 28384)
@@ -29,4 +29,8 @@
 
 import java.io.*;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
 
 import javax.xml.transform.Transformer;
@@ -66,22 +70,23 @@
     private String sourcelang;
     private String targetlang;
-
-    public ApplyXSLT(String sourcelang, String targetlang){
-	initLanguages(sourcelang, targetlang);
+    private HashMap paramMap;
+
+    public ApplyXSLT(String sourcelang, String targetlang, HashMap param_map){
+	initParams(sourcelang, targetlang, param_map);
     }
    
-    public ApplyXSLT(String xsl_file, String sourcelang, String targetlang)
+    public ApplyXSLT(String xsl_file, String sourcelang, String targetlang, HashMap param_map)
   {
     this.xsl_file = xsl_file; 
-    initLanguages(sourcelang, targetlang);
-  }
-
-    public ApplyXSLT(String xsl_file, String sourcelang, String targetlang, String mapping_file) {
+    initParams(sourcelang, targetlang, param_map);
+  }
+
+    public ApplyXSLT(String xsl_file, String mapping_file, String sourcelang, String targetlang, HashMap param_map) {
     this.xsl_file = xsl_file; 
     this.mapping_file = mapping_file;
-    initLanguages(sourcelang, targetlang);
-  }
-
-    private void initLanguages(String sourcelang, String targetlang)
+    initParams(sourcelang, targetlang, param_map);
+  }
+
+    private void initParams(String sourcelang, String targetlang, HashMap param_map)
     {
 	this.sourcelang = sourcelang;
@@ -91,4 +96,7 @@
 	    this.sourcelang = "en";
 	}
+
+	// any custom parameters to be passed into the XSLT would be in the map by now
+	paramMap = param_map;
     }
 
@@ -170,5 +178,5 @@
     Transformer transformer = tFactory.newTransformer(new StreamSource(xsl_file));
 
-    setTransformerLanguageParams(transformer); // sourcelang and targetlang
+    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)));
@@ -189,5 +197,5 @@
 	    
       transformer.setParameter("mapping",mapping);
-      setTransformerLanguageParams(transformer); // sourcelang and targetlang
+      setTransformerParams(transformer); // sourcelang and targetlang and any further custom parameters to be passed into the XSLT
 	    
       Document output_doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
@@ -305,10 +313,21 @@
   } 
 
-    private void  setTransformerLanguageParams(Transformer transformer) 
+    private void  setTransformerParams(Transformer transformer) 
     {
 	if(targetlang != "") {
 	    transformer.setParameter("sourcelang",sourcelang);
 	    transformer.setParameter("targetlang",targetlang);
-	}  
+	}
+
+	// handle any custom parameters that are also to be passed into the XSLT
+	Iterator i = paramMap.entrySet().iterator(); 
+	while(i.hasNext()) {
+	    Map.Entry entry = (Map.Entry)i.next();
+	    String paramName = (String)entry.getKey();
+	    String paramValue = (String)entry.getValue();
+
+	    transformer.setParameter(paramName, paramValue);
+	}
+	
     }
 
@@ -326,5 +345,5 @@
     }
 
-    setTransformerLanguageParams(transformer); // sourcelang and targetlang
+    setTransformerParams(transformer); // sourcelang and targetlang and any further custom parameters to be passed into the XSLT
     transformer.transform(new StreamSource(new File(xml_file)),new StreamResult(output));
         
@@ -393,4 +412,7 @@
     String targetlang="";
 
+    HashMap paramMap = new HashMap();
+    int index = -1; // index of the '=' sign in cmdline argument specifying custom parameters to be passed into the XSLT
+
     // Checking Arguments
     if(args.length < 1)
@@ -427,8 +449,15 @@
 	printUsage();
       }
+      else if ((index = args[i].indexOf("=")) != -1) { // custom parameters provided on the cmdline in the form paramName1=paramValue1 paramName2=paramValue2 etc 
+	  // that are to be passed into the XSLT
+	  String paramName = args[i].substring(0, index);
+	  String paramValue = args[i].substring(index+1); // skip the = sign
+	  paramMap.put(paramName, paramValue);
+	  index = -1;
+      }
       else{
 	printUsage();
       }
-		  
+      
     }
 
@@ -438,8 +467,8 @@
     if (xml_file.equals("") && !xsl_file.equals("")){//read from pipe line
       if (mapping_file.equals("")){ 
-	  core = new ApplyXSLT(xsl_file, sourcelang, targetlang);
+	  core = new ApplyXSLT(xsl_file, sourcelang, targetlang, paramMap);
       }
       else{
-	  core = new ApplyXSLT(xsl_file,mapping_file, sourcelang, targetlang);  
+	  core = new ApplyXSLT(xsl_file, mapping_file, sourcelang, targetlang, paramMap);  
       }
             
@@ -452,5 +481,5 @@
     }
     else if(!xml_file.equals("") && !xsl_file.equals("")){
-	core = new ApplyXSLT(sourcelang, targetlang);
+	core = new ApplyXSLT(sourcelang, targetlang, paramMap);
       try {
 	core.translate(xml_file,xsl_file,output_file); 
@@ -473,5 +502,5 @@
   
   private  static void printUsage(){
-    System.out.println("Usage: ApplyXSLT -x File -t File [-m File] [-o File] [-s sourcelang] [-l targetlang]");
+    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-t specifies the xsl file");
@@ -480,4 +509,5 @@
     System.out.println("\t-s specifies the input language code for generating TMX file. Defaults to 'en' if none is provided");
     System.out.println("\t-l specifies the output language code. Required if generating a TMX file.");
+    System.out.println("\tFor general transformations of an XML by an XSLT, you can pass in parameter name=value pairs if any need to passed on into the XSLT as xsl params.");
     System.exit(-1);
   }
