Index: greenstone3/trunk/src/java/org/greenstone/gsdl3/util/XMLTransformer.java
===================================================================
--- greenstone3/trunk/src/java/org/greenstone/gsdl3/util/XMLTransformer.java	(revision 17023)
+++ greenstone3/trunk/src/java/org/greenstone/gsdl3/util/XMLTransformer.java	(revision 17024)
@@ -30,5 +30,9 @@
 import javax.xml.transform.dom.DOMResult;
 
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.DocumentBuilder;
+import org.w3c.dom.Element;
 import org.w3c.dom.Document;
+
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
@@ -42,4 +46,6 @@
 import java.util.Map;
 import java.util.Iterator;
+
+import org.apache.xml.utils.DefaultErrorHandler;
 
 import org.apache.log4j.*;
@@ -152,4 +158,5 @@
 	    // Use the TransformerFactory to process the stylesheet Source and generate a Transformer.
 	    Transformer transformer = this.t_factory.newTransformer(new DOMSource(stylesheet));
+	    
 	    if (parameters != null) {
 		Set params = parameters.entrySet();
@@ -165,15 +172,21 @@
 	    return result.getNode().getFirstChild();
 	} catch (TransformerConfigurationException e) {
-	    logger.error("couldn't create transformer object: "+e.getMessageAndLocation());
-	    logger.error(e.getLocationAsString());  
-	    return null;
-	} catch (TransformerException e) {
-	    logger.error("couldn't transform the source: " + e.getMessage());
-	    return null;
-	}	
-	
-
-    }
-
+		String message = "TransformerConfigurationException: "+e.getMessageAndLocation();
+		//System.err.println(message);
+		logger.error("couldn't create transformer object: "+e.getMessageAndLocation());
+	    logger.error(e.getLocationAsString());  
+	    return constructErrorXHTMLPage(message);
+	} catch (TransformerException e) {
+		String message = "TransformerException: " + e.getMessageAndLocation();
+		//System.err.println(message);
+		logger.error("couldn't transform the source: " + e.getMessage());
+	    return constructErrorXHTMLPage(message);
+	}	
+	
+
+    }
+
+
+    
     public Node transform(File stylesheet, File source) {
 
@@ -187,10 +200,53 @@
 	    logger.error("couldn't create transformer object: "+e.getMessageAndLocation());
 	    logger.error(e.getLocationAsString());  
-	    return null;
+	    String message = "TransformerConfigurationException: "+e.getMessageAndLocation();
+	    return constructErrorXHTMLPage(message);
 	} catch (TransformerException e) {
 	    logger.error("couldn't transform the source: " + e.getMessage());
-	    return null;
-	}	
-    }
+	    String message = "TransformerException: " + e.getMessageAndLocation();
+	    return constructErrorXHTMLPage(message);
+	}	
+    }
+    
+    
+    protected Element constructErrorXHTMLPage(String message) {
+    	try{
+    		Document xhtmlDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+    		// <html></html>
+    		Node htmlNode = xhtmlDoc.createElement("html");
+    		xhtmlDoc.appendChild(htmlNode);
+    		// <head></head>
+    		Node headNode = xhtmlDoc.createElement("head");
+    		htmlNode.appendChild(headNode);
+    		// <title></title>
+    		Node titleNode = xhtmlDoc.createElement("title");
+    		headNode.appendChild(titleNode);
+    		Node titleString = xhtmlDoc.createTextNode("Error occurred");
+    		titleNode.appendChild(titleString);
+    		
+    		// <body></body>
+    		Node bodyNode = xhtmlDoc.createElement("body");
+    		htmlNode.appendChild(bodyNode);
+    		
+    		// finally put the message in the body
+    		Node h1Node = xhtmlDoc.createElement("h1");
+    		bodyNode.appendChild(h1Node);
+    		Node headingString = xhtmlDoc.createTextNode("The following error occurred:");
+    		h1Node.appendChild(headingString);
+    		
+    		Node textNode = xhtmlDoc.createTextNode(message);
+    		bodyNode.appendChild(textNode);
+    		
+    		return xhtmlDoc.getDocumentElement();
+    		
+    	}catch(Exception e) {
+    		String errmsg = "Exception trying to construct error xhtml page from message: " + message
+    			+ "\n" + e.getMessage();
+    		System.err.println(errmsg);
+    		logger.error(errmsg);
+    		return null;
+    	}
+    }
+    
 }
 
