Index: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXSLT.java
===================================================================
--- main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXSLT.java	(revision 25913)
+++ main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXSLT.java	(revision 25914)
@@ -19,7 +19,5 @@
 package org.greenstone.gsdl3.util;
 
-import java.io.BufferedWriter;
 import java.io.File;
-import java.io.FileWriter;
 import java.util.ArrayList;
 import java.util.Vector;
@@ -28,5 +26,4 @@
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
@@ -84,5 +81,4 @@
 				//main.insertBefore(main_xsl.importNode(node, true), main.getFirstChild());
 				main.insertBefore(main_xsl.importNode(node, true), insertion_point);
-
 			}
 		}
@@ -111,20 +107,14 @@
 		} // for each include
 
-		// do we have a new insertion point??
-		Element last_output = GSXML.getLastElementByTagNameNS(main, "http://www.w3.org/1999/XSL/Transform", "output");
-		if (last_output != null)
-		{
-			insertion_point = last_output.getNextSibling();
-		}
-
-		// outputs
-		children = extra_xsl.getElementsByTagNameNS("http://www.w3.org/1999/XSL/Transform", "output");
-		for (int i = 0; i < children.getLength(); i++)
-		{
-			Element node = (Element) children.item(i);
-			// If the new xsl:output element is identical (in terms of the value for the method attr) 
-			// to any in the merged document, don't copy it over
-			if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "output", "method", node.getAttribute("method")) == null)
-			{
+		if (main.getElementsByTagNameNS("http://www.w3.org/1999/XSL/Transform", "output").getLength() == 0)
+		{
+			// outputs
+			children = extra_xsl.getElementsByTagNameNS("http://www.w3.org/1999/XSL/Transform", "output");
+			for (int i = 0; i < children.getLength(); i++)
+			{
+				Element node = (Element) children.item(i);
+				// If the new xsl:output element is identical (in terms of the value for the method attr) 
+				// to any in the merged document, don't copy it over
+
 				main.insertBefore(main_xsl.importNode(node, true), insertion_point);
 			}
@@ -140,4 +130,18 @@
 			// to any in the merged document, don't copy it over
 			if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "variable", "name", node.getAttribute("name")) == null)
+			{
+				main.appendChild(main_xsl.importNode(node, true));
+			}
+		}
+
+		// params - only top level ones!!
+		// append to end of document
+		children = GSXML.getChildrenByTagNameNS(extra_xsl, "http://www.w3.org/1999/XSL/Transform", "param");
+		for (int i = 0; i < children.getLength(); i++)
+		{
+			Element node = (Element) children.item(i);
+			// If the new xsl:import element is identical (in terms of href attr value) 
+			// to any in the merged document, don't copy it over
+			if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "param", "name", node.getAttribute("name")) == null)
 			{
 				main.appendChild(main_xsl.importNode(node, true));
@@ -180,4 +184,9 @@
 					main.appendChild(main_xsl.importNode(node, true));
 				}
+
+				if (GSXML.getNamedElementNS(main, "http://www.w3.org/1999/XSL/Transform", "template", "name", template_name) == null)
+				{
+					main.appendChild(main_xsl.importNode(node, true));
+				}
 			}
 		}
@@ -217,41 +226,28 @@
 	}
 
-	public static void inlineImportAndIncludeFiles(Document doc, String pathExtra, int depth)
-	{
-		inlineImportAndIncludeFilesDebug(doc, pathExtra, depth, false, null);
-	}
-
-	public static void inlineImportAndIncludeFilesDebug(Document doc, String pathExtra, int depth, boolean debug, String docFileName)
+	public static void inlineImportAndIncludeFiles(Document doc, String pathExtra)
+	{
+		inlineImportAndIncludeFilesDebug(doc, pathExtra, false, null);
+	}
+
+	public static void inlineImportAndIncludeFilesDebug(Document doc, String pathExtra, boolean debug, String docFileName)
 	{
 		XMLConverter converter = new XMLConverter();
 
-		String path = pathExtra;
-		if (path == null)
-		{
-			path = "";
-		}
+		String path = (pathExtra == null) ? "" : pathExtra;
 
 		NodeList importList = doc.getElementsByTagNameNS("http://www.w3.org/1999/XSL/Transform", "import");
 		NodeList includeList = doc.getElementsByTagNameNS("http://www.w3.org/1999/XSL/Transform", "include");
 
-		if (importList.getLength() == 0)
-		{
-			importList = doc.getElementsByTagName("xsl:import");
-		}
-		if (includeList.getLength() == 0)
-		{
-			includeList = doc.getElementsByTagName("xsl:include");
-		}
-
 		for (int i = 0; i < importList.getLength() + includeList.getLength(); i++)
 		{
 			Element current = (Element) ((i < importList.getLength()) ? importList.item(i) : includeList.item(i - importList.getLength()));
 			String href = current.getAttribute("href");
-
-			String filePath = GSFile.interfaceHome(GlobalProperties.getGSDL3Home(), "oran") + File.separator + "transform" + File.separator + path.replace("/", File.separator) + href.replace("/", File.separator);
+			String filePath = GSFile.interfaceHome(GlobalProperties.getGSDL3Home(), "default") + File.separator + "transform" + File.separator + path.replace("/", File.separator) + href.replace("/", File.separator);
+			System.err.println("ADDING IN " + filePath);
 
 			try
 			{
-				Document inlineDoc = converter.getDOM(new File(filePath));
+				Document inlineDoc = converter.getDOM(new File(filePath), "UTF-8");
 
 				String newPath = path;
@@ -263,5 +259,6 @@
 
 				//Do this recursively
-				inlineImportAndIncludeFilesDebug(inlineDoc, newPath, depth + 1, debug, filePath);
+				inlineImportAndIncludeFilesDebug(inlineDoc, newPath, debug, filePath);
+
 				GSXSLT.mergeStylesheetsDebug(doc, inlineDoc.getDocumentElement(), false, debug, docFileName, filePath);
 			}
