Index: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/TransformingReceptionist.java
===================================================================
--- main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/TransformingReceptionist.java	(revision 26324)
+++ main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/TransformingReceptionist.java	(revision 26325)
@@ -21,5 +21,4 @@
 import org.greenstone.gsdl3.util.GSFile;
 import org.greenstone.gsdl3.util.GSParams;
-import org.greenstone.gsdl3.util.GSPath;
 import org.greenstone.gsdl3.util.GSXML;
 import org.greenstone.gsdl3.util.GSXSLT;
@@ -181,10 +180,10 @@
 		}
 
-		GetRequiredMetadataNamesFromXSLFiles();
+		getRequiredMetadataNamesFromXSLFiles();
 
 		return true;
 	}
 
-	protected void GetRequiredMetadataNamesFromXSLFiles()
+	protected void getRequiredMetadataNamesFromXSLFiles()
 	{
 		ArrayList<File> xslFiles = GSFile.getAllXSLFiles((String) this.config_params.get(GSConstants.INTERFACE_NAME), (String) this.config_params.get(GSConstants.SITE_NAME));
@@ -345,19 +344,20 @@
 		ArrayList<String> requiredMetadata = _metadataRequiredMap.get(stylesheetFile);
 
-		if(requiredMetadata !=null){
-		    Element extraMetadataList = this.doc.createElement(GSXML.EXTRA_METADATA + GSXML.LIST_MODIFIER);
-
-		    for (String metadataString : requiredMetadata)
-			{
-			    Element metadataElem = this.doc.createElement(GSXML.EXTRA_METADATA);
-			    metadataElem.setAttribute(GSXML.NAME_ATT, metadataString);
-			    extraMetadataList.appendChild(metadataElem);
-			}
-		    request.appendChild(request.getOwnerDocument().importNode(extraMetadataList, true));
-		}
-	}
-    
-    protected Node postProcessPage(Element page)
-    {
+		if (requiredMetadata != null)
+		{
+			Element extraMetadataList = this.doc.createElement(GSXML.EXTRA_METADATA + GSXML.LIST_MODIFIER);
+
+			for (String metadataString : requiredMetadata)
+			{
+				Element metadataElem = this.doc.createElement(GSXML.EXTRA_METADATA);
+				metadataElem.setAttribute(GSXML.NAME_ATT, metadataString);
+				extraMetadataList.appendChild(metadataElem);
+			}
+			request.appendChild(request.getOwnerDocument().importNode(extraMetadataList, true));
+		}
+	}
+
+	protected Node postProcessPage(Element page)
+	{
 		// might need to add some data to the page
 		addExtraInfo(page);
@@ -633,4 +633,6 @@
 		}
 
+		config_params.put("collName", collection);
+
 		Document style_doc = getXSLTDocument(action, subaction, collection);
 		if (style_doc == null)
@@ -909,5 +911,6 @@
 
 		GSXSLT.inlineImportAndIncludeFiles(skinAndLibraryDoc, null, (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces);
-		skinAndLibraryDoc = (Document) secondConfigFormatPass(collection, skinAndLibraryDoc, doc, new UserContext(request));
+		skinAndLibraryDoc = (Document) performTextFormatPass(collection, skinAndLibraryDoc, doc, new UserContext(request));
+		skinAndLibraryDoc = (Document) performConfigFormatPass(collection, skinAndLibraryDoc, doc, new UserContext(request));
 
 		if (_debug)
@@ -935,7 +938,19 @@
 	}
 
-	protected Node secondConfigFormatPass(String collection, Document skinAndLibraryDoc, Document doc, UserContext userContext)
+	protected Node performConfigFormatPass(String collection, Document skinAndLibraryDoc, Document doc, UserContext userContext)
 	{
 		String configStylesheet_file = GSFile.stylesheetFile(GlobalProperties.getGSDL3Home(), (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces, "config_format.xsl");
+		Document configStylesheet_doc = this.converter.getDOM(new File(configStylesheet_file));
+
+		if (configStylesheet_doc != null)
+		{
+			return this.transformer.transform(configStylesheet_doc, skinAndLibraryDoc, config_params);
+		}
+		return skinAndLibraryDoc;
+	}
+
+	protected Node performTextFormatPass(String collection, Document skinAndLibraryDoc, Document doc, UserContext userContext)
+	{
+		String configStylesheet_file = GSFile.stylesheetFile(GlobalProperties.getGSDL3Home(), (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces, "text_fragment_format.xsl");
 		Document configStylesheet_doc = this.converter.getDOM(new File(configStylesheet_file));
 
@@ -997,11 +1012,13 @@
 			name = this.xslt_map.get(action);
 		}
-		if (name== null) {
-		  // so we can reandomly create any named page
-		  if (action.equals("p") && !subaction.equals("")) {
-		    // TODO: pages/ won't work for interface other than default!!
-		    name="pages/"+subaction+".xsl";
-		  }
-		  
+		if (name == null)
+		{
+			// so we can reandomly create any named page
+			if (action.equals("p") && !subaction.equals(""))
+			{
+				// TODO: pages/ won't work for interface other than default!!
+				name = "pages/" + subaction + ".xsl";
+			}
+
 		}
 		Document finalDoc = GSXSLT.mergedXSLTDocumentCascade(name, (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces, _debug);
Index: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/XSLTUtil.java
===================================================================
--- main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/XSLTUtil.java	(revision 26324)
+++ main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/XSLTUtil.java	(revision 26325)
@@ -19,4 +19,5 @@
 package org.greenstone.gsdl3.util;
 
+import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.text.SimpleDateFormat;
@@ -26,4 +27,7 @@
 import java.util.HashMap;
 import java.util.Locale;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
 
 import net.tanesha.recaptcha.ReCaptcha;
@@ -50,10 +54,10 @@
 		_stringVariables.put(name, value);
 	}
-	
+
 	public static String getString(String name)
 	{
 		return _stringVariables.get(name);
 	}
-	
+
 	/* some tests */
 	public static boolean equals(String s1, String s2)
@@ -292,43 +296,43 @@
 	}
 
-	public static String getCollectionText(String collection, String site_name, String lang, String key)
-	{
-	  return getCollectionTextWithArgs(collection, site_name, lang, key, null);
-	}
-
-  public static String getCollectionText(String collection, String site_name, String lang, String key, String args_str)
-  {
-
-    String[] args = null;
-    if (args_str != null && !args_str.equals(""))
-      {
-	args = StringUtils.split(args_str, ";");
-      }
-
-    return getCollectionTextWithArgs(collection, site_name, lang, key, args);
-  }
+	public static Node getCollectionText(String collection, String site_name, String lang, String key)
+	{
+		return getCollectionTextWithArgs(collection, site_name, lang, key, null);
+	}
+
+	public static Node getCollectionText(String collection, String site_name, String lang, String key, String args_str)
+	{
+
+		String[] args = null;
+		if (args_str != null && !args_str.equals(""))
+		{
+			args = StringUtils.split(args_str, ";");
+		}
+
+		return getCollectionTextWithArgs(collection, site_name, lang, key, args);
+	}
 
 	// xslt didn't like calling the function with Node varargs, so have this hack for now
-	public static String getCollectionTextWithDOM(String collection, String site_name, String lang, String key, Node n1)
+	public static Node getCollectionTextWithDOM(String collection, String site_name, String lang, String key, Node n1)
 	{
 		return getCollectionTextWithDOMMulti(collection, site_name, lang, key, n1);
 	}
 
-	public static String getCollectionTextWithDOM(String collection, String site_name, String lang, String key, Node n1, Node n2)
+	public static Node getCollectionTextWithDOM(String collection, String site_name, String lang, String key, Node n1, Node n2)
 	{
 		return getCollectionTextWithDOMMulti(collection, site_name, lang, key, n1, n2);
 	}
 
-	public static String getCollectionTextWithDOM(String collection, String site_name, String lang, String key, Node n1, Node n2, Node n3)
+	public static Node getCollectionTextWithDOM(String collection, String site_name, String lang, String key, Node n1, Node n2, Node n3)
 	{
 		return getCollectionTextWithDOMMulti(collection, site_name, lang, key, n1, n2, n3);
 	}
 
-	public static String getCollectionTextWithDOM(String collection, String site_name, String lang, String key, Node n1, Node n2, Node n3, Node n4)
+	public static Node getCollectionTextWithDOM(String collection, String site_name, String lang, String key, Node n1, Node n2, Node n3, Node n4)
 	{
 		return getCollectionTextWithDOMMulti(collection, site_name, lang, key, n1, n2, n3, n4);
 	}
 
-	public static String getCollectionTextWithDOMMulti(String collection, String site_name, String lang, String key, Node... nodes)
+	public static Node getCollectionTextWithDOMMulti(String collection, String site_name, String lang, String key, Node... nodes)
 	{
 		int num_nodes = nodes.length;
@@ -340,5 +344,4 @@
 			for (int i = 0; i < num_nodes; i++)
 			{
-
 				String node_str = XMLConverter.getString(nodes[i]);
 				args[i] = node_str;
@@ -348,15 +351,23 @@
 	}
 
-  public static String getCollectionTextWithArgs(String collection, String site_name, String lang, String key, String [] args) {
-
-		CollectionClassLoader class_loader = new CollectionClassLoader(XSLTUtil.class.getClassLoader(), GSFile.siteHome(GlobalProperties.getGSDL3Home(), site_name), collection);
-		Dictionary dict = new Dictionary(collection, lang, class_loader);
-		String result = dict.get(key, args);
-		if (result != null)
-		{
-			return result;
-		}
-		return "text:" + collection + ":" + key;
-
+	public static Node getCollectionTextWithArgs(String collection, String site_name, String lang, String key, String[] args)
+	{
+		try
+		{
+			DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+
+			CollectionClassLoader class_loader = new CollectionClassLoader(XSLTUtil.class.getClassLoader(), GSFile.siteHome(GlobalProperties.getGSDL3Home(), site_name), collection);
+			Dictionary dict = new Dictionary(collection, lang, class_loader);
+			String result = dict.get(key, args);
+			if (result != null)
+			{
+				return docBuilder.parse(new ByteArrayInputStream(("<fragment>" + result + "</fragment>").getBytes())).getDocumentElement();
+			}
+			return docBuilder.parse(new ByteArrayInputStream(("<fragment>" + "text:" + collection + ":" + key + "</fragment>").getBytes())).getDocumentElement();
+		}
+		catch (Exception ex)
+		{
+			return null;
+		}
 	}
 
