Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/TransformingReceptionist.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/TransformingReceptionist.java	(revision 33649)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/TransformingReceptionist.java	(revision 33650)
@@ -49,14 +49,14 @@
 public class TransformingReceptionist extends Receptionist
 {
-  protected static final String CONFIG_FORMAT_FILE = "config_format.xsl"; //int CONFIG_PASS = 1;
-  protected static final String TEXT_FORMAT_FILE = "text_fragment_format.xsl"; //int TEXT_PASS = 2;
-
-	static Logger logger = Logger.getLogger(org.greenstone.gsdl3.core.TransformingReceptionist.class.getName());
-
-	/** The preprocess.xsl file is in a fixed location */
-	static final String preprocess_xsl_filename = GlobalProperties.getGSDL3Home() + File.separatorChar + "interfaces" + File.separatorChar + "core" + File.separatorChar + "transform" + File.separatorChar + "preProcess.xsl";
-
-  static final String gslib_filename = "gslib.xsl";
+  protected static final String EXPAND_GSF_FILE = "expand-gsf.xsl"; 
+  protected static final String EXPAND_GSF_PASS1_FILE = "expand-gsf-pass1.xsl"; 
+  protected static final String EXPAND_GSLIB_FILE = "expand-gslib.xsl";
+  protected static final String GSLIB_FILE = "gslib.xsl";
   
+  static Logger logger = Logger.getLogger(org.greenstone.gsdl3.core.TransformingReceptionist.class.getName());
+
+	/** The expand-gslib.xsl file is in a fixed location */
+	static final String expand_gslib_filepath = GlobalProperties.getGSDL3Home() + File.separatorChar + "interfaces" + File.separatorChar + "core" + File.separatorChar + "transform" + File.separatorChar + EXPAND_GSLIB_FILE;
+
 	/** the list of xslt to use for actions */
 	protected HashMap<String, String> xslt_map = null;
@@ -756,28 +756,23 @@
 		  
 		  // need to transform the format info
-		  // run config_format.xsl over the format_elem. We need to do this now to turn
+		  // run expand-gsf.xsl over the format_elem. We need to do this now to turn
 		  // eg gsf:template into xsl:template so that the merging works properly.
 		  // xsl:templates will get merged
 		  // into the main stylesheet, but gsf:templates won't.
+
+		  Document format_doc = XMLConverter.newDOM();
+		  format_doc.appendChild(format_doc.importNode(format_elem, true));
 		  
-			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_FILE);
-			Document configStylesheet_doc = this.converter.getDOM(new File(configStylesheet_file));
-
-			if (configStylesheet_doc != null)
-			{
-				Document format_doc = XMLConverter.newDOM();
-				format_doc.appendChild(format_doc.importNode(format_elem, true));
-
-				if (_debug)
-				{
-					String siteHome = GSFile.siteHome(GlobalProperties.getGSDL3Home(), (String) this.config_params.get(GSConstants.SITE_NAME));
-					GSXSLT.insertDebugElements(format_doc, GSFile.collectionConfigFile(siteHome, collection));
-				}
-
-				Node result = this.transformer.transform(configStylesheet_doc, format_doc, config_params); // Needs addressing <-
-
-				// Since we started creating documents with DocTypes, we can end up with 
-				// Document objects here. But we will be working with an Element instead, 
-				// so we grab the DocumentElement() of the Document object in such a case.
+		  if (_debug) {
+		    
+		    String siteHome = GSFile.siteHome(GlobalProperties.getGSDL3Home(), (String) this.config_params.get(GSConstants.SITE_NAME));
+		    GSXSLT.insertDebugElements(format_doc, GSFile.collectionConfigFile(siteHome, collection));
+		  }
+		  
+		  // should we be doing the double pass here too?
+		  Node result = transformGSFElements(collection, format_doc, EXPAND_GSF_FILE);
+		  // Since we started creating documents with DocTypes, we can end up with 
+		  // Document objects here. But we will be working with an Element instead, 
+		  // so we grab the DocumentElement() of the Document object in such a case.
 				Element new_format;
 				if (result.getNodeType() == Node.DOCUMENT_NODE)
@@ -806,12 +801,5 @@
 				}
 
-			}
-			else
-			{
-			  // Is this a fatal error, or are there situations where we could carry on here...
-			  logger.error(" Couldn't parse the "+CONFIG_FORMAT_FILE+" stylesheet");
-			  return XMLTransformer.constructErrorXHTMLPage("Couldn't find and/or load the stylesheet \""+CONFIG_FORMAT_FILE);
-			  //GSXSLT.mergeStylesheets(page_xsl, format_elem, true);
-			}
+		
 		}
 
@@ -868,18 +856,18 @@
 		  return converter.getDOM(getStringFromDocument(page_xsl));
 		}
-  
-  // The next steg is to process the page_xsl +  gslib.xsl by preProcess.xsl to expand all the
-  // gslib elements
-
-                Document preprocessingXsl;
+		
+		// The next step is to process the page_xsl +  gslib_xsl by
+		// expand-gslib.xsl to expand all the gslib elements
+
+                Document expand_gslib_xsl_doc;
 		try
 		{
-		  // interfaces/core/transform/preProcess.xsl
+		  // interfaces/core/transform/expand-gslib.xsl
 		  // this takes skinandLibraryXsl, copies skinXSL, merges elements of libraryXsl into it, and replaces gslib elements
-			preprocessingXsl = getDoc(preprocess_xsl_filename);
+			expand_gslib_xsl_doc = getDoc(expand_gslib_filepath);
 			String errMsg = ((XMLConverter.ParseErrorHandler) parser.getErrorHandler()).getErrorMessage();
 			if (errMsg != null)
 			{
-				return XMLTransformer.constructErrorXHTMLPage("error loading core/transform/preProcess xslt file: " + preprocess_xsl_filename + "\n" + errMsg);
+				return XMLTransformer.constructErrorXHTMLPage("error loading file: " + expand_gslib_filepath + "\n" + errMsg);
 			}
 		}
@@ -891,13 +879,13 @@
 		{
 			e.printStackTrace();
-			System.out.println("error loading preprocess xslt");
-			return XMLTransformer.constructErrorXHTMLPage("Error loading interfaces/core/transform/preProcess xslt\n" + e.getMessage());
+			System.out.println("error loading "+expand_gslib_filepath);
+			return XMLTransformer.constructErrorXHTMLPage("Error loading file: "+ expand_gslib_filepath+"\n" + e.getMessage());
 		}
 
 		// gslib.xsl
-		Document libraryXsl = null;
+		Document gslib_xsl_doc = null;
 		try
 		{
-			libraryXsl = GSXSLT.mergedXSLTDocumentCascade(gslib_filename, (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces, _debug);
+			gslib_xsl_doc = GSXSLT.mergedXSLTDocumentCascade(GSLIB_FILE, (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces, _debug);
 		}
 		catch (Exception e)
@@ -908,9 +896,9 @@
 		}
 
-  if (output.equals("preprocess")) {
-    return converter.getDOM(getStringFromDocument(preprocessingXsl));
+  if (output.equals("gslib-expander")) {
+    return converter.getDOM(getStringFromDocument(expand_gslib_xsl_doc));
   }
   if (output.equals("gslib1")) {
-    return converter.getDOM(getStringFromDocument(libraryXsl));
+    return converter.getDOM(getStringFromDocument(gslib_xsl_doc));
   }
 		//   Combine the skin file and library variables/templates into one document. 
@@ -918,53 +906,59 @@
 		//   needs to know what's available in the library.
 
-		Document skinAndLibraryXsl = null;
-		Document skinAndLibraryDoc = converter.newDOM();
 
                 // add in all gslib.xsl's include and import files
 		// debug?? use debug method?? or does it not make sense here??
-		GSXSLT.inlineImportAndIncludeFiles(libraryXsl, null, (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces);
+		GSXSLT.inlineImportAndIncludeFiles(gslib_xsl_doc, null, (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces);
   if (output.equals("gslib")) {
-    return converter.getDOM(getStringFromDocument(libraryXsl));
+    return converter.getDOM(getStringFromDocument(gslib_xsl_doc));
   }
 
-		// now, we transform all the gslib elements
+
+  		Document pageAndGslibXsl = null;
+		Document pageAndGslibDoc = converter.newDOM();
+
+  // now, we transform all the gslib elements
 		{
 		  
 
-		  skinAndLibraryXsl = converter.newDOM();
-		  Element root = skinAndLibraryXsl.createElement("skinAndLibraryXsl");
-		  skinAndLibraryXsl.appendChild(root);
+		  pageAndGslibXsl = converter.newDOM();
+		  Element root = pageAndGslibXsl.createElement("pageAndGslibXsl");
+		  pageAndGslibXsl.appendChild(root);
 		  
-		  Element s = skinAndLibraryXsl.createElement("skinXsl");
-		  s.appendChild(skinAndLibraryXsl.importNode(page_xsl.getDocumentElement(), true));
+		  Element s = pageAndGslibXsl.createElement("pageXsl");
+		  s.appendChild(pageAndGslibXsl.importNode(page_xsl.getDocumentElement(), true));
 		  root.appendChild(s);
 		  
-		  Element l = skinAndLibraryXsl.createElement("libraryXsl");
-		  if (libraryXsl != null)
+		  Element l = pageAndGslibXsl.createElement("gslibXsl");
+		  if (gslib_xsl_doc != null)
 		    {
-		      Element libraryXsl_el = libraryXsl.getDocumentElement();
-		      l.appendChild(skinAndLibraryXsl.importNode(libraryXsl_el, true));
+		      Element gslib_xsl_el = gslib_xsl_doc.getDocumentElement();
+		      l.appendChild(pageAndGslibXsl.importNode(gslib_xsl_el, true));
 		    }
 		  root.appendChild(l);
 
+		  if (output.equals("xsl5")) {
+		    return converter.getDOM(getStringFromDocument(pageAndGslibXsl));
+		  }
 		  // actually merge the gslib file with the page
 		  XMLTransformer preProcessor = new XMLTransformer();
-		  preProcessor.transform_withResultNode(preprocessingXsl, skinAndLibraryXsl, skinAndLibraryDoc);
-
-		}
-		if (output.equals("xsl5")) {
-		  return converter.getDOM(getStringFromDocument(skinAndLibraryDoc));
-		}
-
-		// now we need to transform all the gsf elements
-		skinAndLibraryDoc = (Document) transformGSFElements(collection, skinAndLibraryDoc, TEXT_FORMAT_FILE); 
+		  preProcessor.transform_withResultNode(expand_gslib_xsl_doc, pageAndGslibXsl, pageAndGslibDoc);
+
+		}
+		if (output.equals("xsl6")) {
+		  return converter.getDOM(getStringFromDocument(pageAndGslibDoc));
+		}
 		  
-		skinAndLibraryDoc = (Document) transformGSFElements(collection, skinAndLibraryDoc, CONFIG_FORMAT_FILE); 
-	
-		
-
+		pageAndGslibDoc = (Document) transformGSFElements(collection, pageAndGslibDoc, EXPAND_GSF_PASS1_FILE);
+
+		if (output.equals("xsl7")) {
+		  return converter.getDOM(getStringFromDocument(pageAndGslibDoc));
+		}
+		
+		pageAndGslibDoc = (Document) transformGSFElements(collection, pageAndGslibDoc, EXPAND_GSF_FILE);
+		
 		if (output.equals("xsl") || output.equals("skinandlibdocfinal"))
 		{
-		  return converter.getDOM(getStringFromDocument(skinAndLibraryDoc));
+		  return converter.getDOM(getStringFromDocument(pageAndGslibDoc));
 		}
 		
@@ -972,13 +966,13 @@
 		{
 			        
-		  // Go through and 'fix up' any 'util:...' or 'java:...' attributes the skinAndLibraryDoc has
+		  // Go through and 'fix up' any 'util:...' or 'java:...' attributes the pageAndGslibDoc has
 		  String lang = (String)config_params.get("lang");
-		  resolveExtendedNamespaceAttributesXSLT(skinAndLibraryDoc,currentInterface,lang); // test= and select= attributes
-		  resolveExtendedNamespaceAttributesXML(skinAndLibraryDoc,currentInterface,lang);  // href= and src= attributes
-		  Node skinAndLibFinal = converter.getDOM(getStringFromDocument(skinAndLibraryDoc));
+		  resolveExtendedNamespaceAttributesXSLT(pageAndGslibDoc,currentInterface,lang); // test= and select= attributes
+		  resolveExtendedNamespaceAttributesXML(pageAndGslibDoc,currentInterface,lang);  // href= and src= attributes
+		  Node skinAndLibFinal = converter.getDOM(getStringFromDocument(pageAndGslibDoc));
 		  
 		  // Send XML and skinandlibdoc down the line together
 		  Document finalDoc = converter.newDOM();
-		  Node finalDocSkin = finalDoc.importNode(skinAndLibraryDoc.getDocumentElement(), true);
+		  Node finalDocSkin = finalDoc.importNode(pageAndGslibDoc.getDocumentElement(), true);
 		  Node finalDocXML = finalDoc.importNode(page_with_xslt_params_doc.getDocumentElement(), true);
 		  Element root = finalDoc.createElement("skinlibfinalPlusXML");
@@ -993,5 +987,5 @@
 
 		///logger.debug("final xsl is");
-		///logger.debug(XMLConverter.getPrettyString(skinAndLibraryDoc));
+		///logger.debug(XMLConverter.getPrettyString(pageAndGslibDoc));
 		
 		// The transformer will now work out the resulting doctype from any set in the (merged) stylesheets and
@@ -999,5 +993,5 @@
 
   // Here, we finally transform the page xml source with the complete xsl file
-  Node finalResult = this.transformer.transform(skinAndLibraryDoc, page_xml_doc, config_params);
+  Node finalResult = this.transformer.transform(pageAndGslibDoc, page_xml_doc, config_params);
 
 		if (_debug)
@@ -1093,14 +1087,14 @@
   // transform the xsl with xsl to replace all gsf elements. We do this in 2 stages -
   // first do just a text pass, that way we can have gsf elements in the text content 
-  protected Node transformGSFElements(String collection, Document skinAndLibraryDoc, String formatFile) {
-
-    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, formatFile);
-    Document configStylesheet_doc = this.converter.getDOM(new File(configStylesheet_file));
+  protected Node transformGSFElements(String collection, Document source_xsl, String expand_gsf_filename) {
+
+    String expand_gsf_file = GSFile.stylesheetFile(GlobalProperties.getGSDL3Home(), (String) this.config_params.get(GSConstants.SITE_NAME), collection, (String) this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces, expand_gsf_filename);
+    Document expand_gsf_doc = this.converter.getDOM(new File(expand_gsf_file));
     
-    if (configStylesheet_doc != null)
+    if (expand_gsf_doc != null)
       {
-	return this.transformer.transform(configStylesheet_doc, skinAndLibraryDoc, config_params);
+	return this.transformer.transform(expand_gsf_doc, source_xsl, config_params);
       }
-    return skinAndLibraryDoc;
+    return source_xsl;
     
   }    
