Index: /greenstone3/trunk/src/java/org/greenstone/gsdl3/LibraryServlet.java
===================================================================
--- /greenstone3/trunk/src/java/org/greenstone/gsdl3/LibraryServlet.java	(revision 16373)
+++ /greenstone3/trunk/src/java/org/greenstone/gsdl3/LibraryServlet.java	(revision 16374)
@@ -7,4 +7,5 @@
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
+import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 import java.io.*;
@@ -497,6 +498,6 @@
     //GSXML.printXMLNode(xml_message);
     
-    Element xml_result = this.recept.process (xml_message);
-    encodeURLs (xml_result, response);
+    Node xml_result = this.recept.processToPage (xml_message);
+    // encodeURLs (xml_result, response);
     out.println (this.converter.getPrettyString (xml_result));
     
Index: /greenstone3/trunk/src/java/org/greenstone/gsdl3/core/Receptionist.java
===================================================================
--- /greenstone3/trunk/src/java/org/greenstone/gsdl3/core/Receptionist.java	(revision 16373)
+++ /greenstone3/trunk/src/java/org/greenstone/gsdl3/core/Receptionist.java	(revision 16374)
@@ -129,16 +129,42 @@
 	return true;
     }
+
+    public String process(String xml_in) {
+
+	Element message = this.converter.getDOM(xml_in).getDocumentElement();
+	Node page = process(message);
+	return this.converter.getString(page);
+    }
+
+    public Element process(Element message) {
+	Node node = processToPage(message);
+
+	short nodeType = node.getNodeType();
+
+	if (nodeType == Node.DOCUMENT_NODE) {
+		Document docNode = (Document)node;
+		return docNode.getDocumentElement() ;
+	}
+	else {
+	    return null;
+	}
+    }
+
+
+
+
     /** process using strings - just calls process using Elements */
-    public String process(String xml_in) {
+    public String processToPage(String xml_in) {
 
 	Element message = this.converter.getDOM(xml_in).getDocumentElement();
-	Element page = process(message);
+	Node page = processToPage(message);
 	return this.converter.getString(page);
     }
+
 
     /** process - produce a page of data in response to a request 
      * if something goes wrong, it returns null - 
      * TODO:  return a suitable message to the user */
-    public Element process(Element message) {
+    public Node processToPage(Element message) {
 
 	// get the request out of the message - assume that there is only one
@@ -221,7 +247,10 @@
 	//logger.info(" raw page="+this.converter.getString(page));
 	// transform the result in some way
-	Element resulting_page = postProcessPage(page);
-    logger.debug("receptionist returned response");
-    logger.debug(this.converter.getString(resulting_page));
+	//Element resulting_page = postProcessPage(page);
+
+	Node resulting_page = postProcessPage(page);
+
+	logger.debug("receptionist returned response");
+	logger.debug(this.converter.getString(resulting_page));
 //    logger.info("receptionist returned response");
 //    logger.info(this.converter.getString(resulting_page));
@@ -285,5 +314,5 @@
     }
 
-    protected Element postProcessPage(Element page) {
+    protected Node postProcessPage(Element page) {
 	return page;
     }
Index: /greenstone3/trunk/src/java/org/greenstone/gsdl3/core/Skin.java
===================================================================
--- /greenstone3/trunk/src/java/org/greenstone/gsdl3/core/Skin.java	(revision 16373)
+++ /greenstone3/trunk/src/java/org/greenstone/gsdl3/core/Skin.java	(revision 16374)
@@ -175,5 +175,5 @@
 	
 	
-	public Element transformPage(Page page) throws Exception{
+	public Node transformPage(Page page) throws Exception{
 		
 		Element p = page.getPage() ;
@@ -209,5 +209,5 @@
 		} catch (Exception e) {
 			System.out.println("error loading preprocessing xslt") ;
-			e.printStackTrace() ;
+		e.printStackTrace() ;
 			return constructErrorPage(e) ;
 		}
@@ -259,59 +259,38 @@
 		//return sourceXml.getDocumentElement() ;
 		
-		Document finalPage = receptionist.converter.newDOM();
+		// Document finalPage = receptionist.converter.newDOM(); // ****
+		Document finalPageParsed = null;
+
 		//transform source doc
 		try {
 		
-		//Tranform XSL DOM to String	
+		    /*
+		    //Tranform XSL DOM to String	
 			TransformerFactory tf = TransformerFactory.newInstance();
 			Transformer trans = tf.newTransformer();
 			StringWriter sw = new StringWriter();
 			trans.transform(new DOMSource(processedXsl), new StreamResult(sw));
-			String theXSLAnswer = sw.toString();
-			
-			//writefile("c:\\mr49\\stylesheet.xsl", theXSLAnswer);
-			
-			
-		//Tranform XML DOM to String	
+			// String theXSLAnswer = sw.toString(); // ****
+			
+			
+			//Tranform XML DOM to String	
 			TransformerFactory tf2 = TransformerFactory.newInstance();
 			Transformer trans2 = tf2.newTransformer();
 			StringWriter sw2 = new StringWriter();
 			trans2.transform(new DOMSource(sourceXml), new StreamResult(sw2));
-			String theXMLAnswer = sw2.toString();
-			
-			//writefile("c:\\mr49\\xml.xml", theXMLAnswer);
-
-			
+			//String theXMLAnswer = sw2.toString();
+			*/
+
 			Transformer transformer = transformerFactory.newTransformer(new DOMSource(processedXsl));
-			//Transformer transformer = transformerFactory.newTransformer(new StreamSource("c:\\mr49\\stylesheet.xsl"));
-			transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd");
-			DOMResult result = new DOMResult();
-			result.setNode(finalPage);
+			// transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd");
+			//DOMResult result = new DOMResult();
+			//result.setNode(finalPage);
 			
 			//transformer.transform(new DOMSource(sourceXml), result2);
 			StringWriter result2 = new StringWriter();
-			transformer.transform(new DOMSource(sourceXml), result);
-			
-			//transformer.transform(new DOMSource(sourceXml), new StreamResult(result2));
-			//writefile("c:\\mr49\\result.html", result2.toString());
-			//System.err.println("outputting result:");
-			//System.err.println(this.converter.getPrettyString(finalPage));
-			/*
-			//Testing stuff
-			
-				TransformerFactory tFactory = TransformerFactory.newInstance();
-				Transformer with identity transformation
-				Transformer transformer2 =  tFactory.newTransformer(new DOMSource(processedXsl));
-            
-				String xml="<root><a><b><c>aaa</c></b></a></root>";
-				StringWriter result2 = new StringWriter();
-            //Transfrom xml (in String) to formatted xml (in String)                        
-				transformer2.transform(new StreamSource(new StringReader(theXMLAnswer)), new StreamResult(result2));
-            //Output result            
-				writefile("c:\\mr49\\testHTML.txt", result2.toString());
-		*/
-			
-			
-			
+			transformer.transform(new DOMSource(sourceXml), new StreamResult(result2));
+
+			XMLConverter converter = new XMLConverter();
+			finalPageParsed = converter.getDOM(result2.toString());		      			
 			
 		} catch (TransformerException e) {
@@ -326,5 +305,5 @@
 		}
 			
-		return finalPage.getDocumentElement() ;
+		return finalPageParsed;
 	}
 	
@@ -438,26 +417,4 @@
 	}
 	
-	private void writefile(String filename, String contents){
-	
-        File testFile = new File(filename);
-		
-
-    //use buffering
-    
-	
-    try {
-	Writer output = new BufferedWriter(new FileWriter(testFile));
-      //FileWriter always assumes default encoding is OK!
-      output.write( contents );
-	   output.close();
-    }
-	
-	catch (Exception e) {
-	e.printStackTrace();
-	}
-	
-	
-   
-  }
 
 }	
Index: /greenstone3/trunk/src/java/org/greenstone/gsdl3/core/SkinnedReceptionist.java
===================================================================
--- /greenstone3/trunk/src/java/org/greenstone/gsdl3/core/SkinnedReceptionist.java	(revision 16373)
+++ /greenstone3/trunk/src/java/org/greenstone/gsdl3/core/SkinnedReceptionist.java	(revision 16374)
@@ -7,4 +7,5 @@
 import org.w3c.dom.Document; 
 import org.w3c.dom.Element; 
+import org.w3c.dom.Node; 
 
 import org.greenstone.gsdl3.util.*;
@@ -24,5 +25,5 @@
 	}
 	
-	protected Element postProcessPage(Element p) {
+	protected Node postProcessPage(Element p) {
 		try {
 			//Avoid the duplicate attribute in the namespaces declaration of the generated html file
@@ -76,12 +77,12 @@
 			
 			
+			Node np = null;
 			try {
 				if (skin != null && !output.equals("xml")) {
-					//System.out.println("Skin exists") ;
-					p = skin.transformPage(page);
-					//System.out.println("done skinning") ;
-					
-					//System.out.println("SkinnedPage = " + this.converter.getPrettyString(p)) ;
+					np = skin.transformPage(page);
 				} 
+				else {
+				    np = p;
+				}
 			} catch (Exception e) {
 				e.printStackTrace() ;
@@ -90,5 +91,5 @@
 			
 			
-			return p ;
+			return np ;
 		} catch (Exception e) {
 			e.printStackTrace() ;
@@ -340,5 +341,5 @@
 	}
 	
-	protected Element transformPage(Element page) {
+	protected Node transformPage(Element page) {
 		return super.transformPage(page) ;
 	}
Index: /greenstone3/trunk/src/java/org/greenstone/gsdl3/core/TransformingReceptionist.java
===================================================================
--- /greenstone3/trunk/src/java/org/greenstone/gsdl3/core/TransformingReceptionist.java	(revision 16373)
+++ /greenstone3/trunk/src/java/org/greenstone/gsdl3/core/TransformingReceptionist.java	(revision 16374)
@@ -116,10 +116,10 @@
 
 
-    protected Element postProcessPage(Element page) {
+    protected Node postProcessPage(Element page) {
 	
 	// might need to add some data to the page
 	addExtraInfo(page);
 	// transform the page using xslt
-	Element transformed_page = transformPage(page);
+	Node transformed_page = transformPage(page);
 	
 	return transformed_page;
@@ -132,5 +132,5 @@
      * we need to get any format element out of the page and add it to the xslt
      * before transforming */
-    protected Element transformPage(Element page) {
+    protected Node transformPage(Element page) {
 
 	logger.debug("page before transfomring:");
@@ -184,7 +184,7 @@
 		format_doc.appendChild(format_doc.importNode(format_elem, true));
 		Element new_format = (Element)this.transformer.transform(stylesheet_doc, format_doc);
-	    logger.debug("new format elem="+this.converter.getPrettyString(new_format));
+		logger.debug("new format elem="+this.converter.getPrettyString(new_format));
 	    
-	    // add it in to the main stylesheet
+		// add it in to the main stylesheet
 		GSXSLT.mergeStylesheets(style_doc, new_format);
 	    } else {
@@ -196,7 +196,17 @@
 	}
 	
-	// there is a thing called a URIResolver which you can set for a transformer or transformer factory. may be able to use this instead of this absoluteIncludepaths hack
-	GSXSLT.absoluteIncludePaths(style_doc, GlobalProperties.getGSDL3Home(), (String)this.config_params.get(GSConstants.SITE_NAME), collection, (String)this.config_params.get(GSConstants.INTERFACE_NAME), base_interfaces);
-	// put the page into a document - this is necessary for xslt to get the paths right if you have paths relative to the document root eg /page.
+	// there is a thing called a URIResolver which you can set for a
+	// transformer or transformer factory. may be able to use this
+	// instead of this absoluteIncludepaths hack
+
+	GSXSLT.absoluteIncludePaths(style_doc, GlobalProperties.getGSDL3Home(), 
+				    (String)this.config_params.get(GSConstants.SITE_NAME), 
+				    collection, (String)this.config_params.get(GSConstants.INTERFACE_NAME), 
+				    base_interfaces);
+
+	// put the page into a document - this is necessary for xslt to get
+	// the paths right if you have paths relative to the document root
+	// eg /page.
+
 	Document doc = this.converter.newDOM();
 	doc.appendChild(doc.importNode(page, true));
Index: /greenstone3/trunk/src/java/org/greenstone/gsdl3/util/XMLConverter.java
===================================================================
--- /greenstone3/trunk/src/java/org/greenstone/gsdl3/util/XMLConverter.java	(revision 16373)
+++ /greenstone3/trunk/src/java/org/greenstone/gsdl3/util/XMLConverter.java	(revision 16374)
@@ -21,4 +21,5 @@
 // XML classes
 import org.w3c.dom.Document; 
+import org.w3c.dom.DocumentType; 
 import org.w3c.dom.Node; 
 import org.w3c.dom.NodeList;
@@ -173,5 +174,22 @@
 
 	if (nodeType == Node.DOCUMENT_NODE) {
-	    getString(((Document)xmlNode).getDocumentElement(), xmlRepresentation, depth, pretty);
+	    Document xmlDocNode = (Document)xmlNode;
+	    
+	    if (xmlDocNode.getDoctype() == null) {
+		System.err.println("Doctype is null.");
+	    }
+	    else {
+		
+		DocumentType dt = xmlDocNode.getDoctype();
+		
+		String name = dt.getName();
+		String pid  = dt.getPublicId();
+		String sid  = dt.getSystemId();
+		
+		String doctype_str = "<!DOCTYPE " + dt.getName() + " PUBLIC \"" + pid + "\"" + sid + "\">\n";
+		
+		xmlRepresentation.append(doctype_str);
+	    }
+	    getString(xmlDocNode.getDocumentElement(), xmlRepresentation, depth, pretty);
 	    return;
 	}
