Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/FormatAction.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/FormatAction.java	(revision 23550)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/FormatAction.java	(revision 23551)
@@ -85,4 +85,6 @@
 
     String format_string = (String)params.get("data");
+    //logger.error("Original format string");
+    //logger.error(format_string);
     
     Element page_response = this.doc.createElement(GSXML.RESPONSE_ELEM);
@@ -115,7 +117,7 @@
 
             // not sure what to do here - some code from Transforming Receptionist
-            //String transformed = transformer.transformToString(style_doc, d);
+            String transformed = transformer.transformToString(style_doc, d);
             logger.error("About to transform");
-            Node transformed = (Node) transformer.transform(style_doc, d);  // Failing org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not permitted. ; SystemID: file:///home/sam/greenstone3/packages/tomcat/bin/dummy.xsl
+            //Node transformed = (Node) transformer.transform(style_doc, d);  // Failing org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not permitted. ; SystemID: file:///home/sam/greenstone3/packages/tomcat/bin/dummy.xsl
 
             logger.error("Transform successful?");
@@ -124,14 +126,14 @@
                 logger.error("TRANSFORMED IS NULL");
 
-            logger.error("begin import"); 
-            Node imported = this.doc.importNode(transformed, true); // There was an exception org.w3c.dom.DOMException: NOT_SUPPORTED_ERR: The implementation does not support the requested type of object or operation.
-            logger.error("finished import"); 
+            //logger.error("begin import"); 
+            //Node imported = this.doc.importNode(transformed, true); // There was an exception org.w3c.dom.DOMException: NOT_SUPPORTED_ERR: The implementation does not support the requested type of object or operation.
+            //logger.error("finished import"); 
 
-            String format_string2 = GSXML.xmlNodeToString(imported); // null pointer exception occuring here
-            logger.error("format string="+format_string2);
+            //String format_string2 = GSXML.xmlNodeToString(imported); // null pointer exception occuring here
+            //logger.error("format string="+format_string2);
  
             Element format = this.doc.createElement(GSXML.FORMAT_STRING_ELEM);
-            //GSXML.setNodeText(format, transformed);
-            format.appendChild(transformed);
+            GSXML.setNodeText(format, transformed);
+            //format.appendChild(transformed);
             //format.setNodeValue(transformed);
             mr_request.appendChild(format); 
Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/collection/Collection.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/collection/Collection.java	(revision 23550)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/collection/Collection.java	(revision 23551)
@@ -33,4 +33,12 @@
 import java.io.File;
 import java.util.HashMap;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.xml.sax.*;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
 
 import org.apache.log4j.*;
@@ -330,6 +338,6 @@
 
         Element format_element = (Element) GSXML.getChildByTagName(request, GSXML.FORMAT_STRING_ELEM);
-        //String format_string = GSXML.getNodeText(format_element);
-        Element format_statement = (Element) format_element.getFirstChild();
+        String format_string = GSXML.getNodeText(format_element);
+        //Element format_statement = (Element) format_element.getFirstChild();
 
         //logger.error("Format string: " + format_string);
@@ -386,5 +394,5 @@
 
                 // Write format statement
-                String format_string = GSXML.xmlNodeToString(format_statement);
+                //String format_string = GSXML.xmlNodeToString(format_statement);
                 writer = new BufferedWriter(new FileWriter(format_statement_filename));
                 writer.write(format_string);
@@ -405,89 +413,112 @@
             logger.error("SAVE format statement");
 
-            // open collectionConfig.xml and read in to w3 Document
-            String collection_config = directory + "collectionConfig.xml";
-            Document config = this.converter.getDOM(new File(collection_config), "UTF-8");
+            try{
+
+                // Convert format string to a document
+                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+                DocumentBuilder builder = factory.newDocumentBuilder();
+                //String input = "<html><head><title></title></head><body>" + format_string + "</body></html>";
+                String input = format_string.substring(0,format_string.length()-1)+"</xml>";
+                logger.error(input);
+                InputSource is = new InputSource( new StringReader( input ) );
+                logger.error("About to parse format string");
+                Document format_statement = (Document) builder.parse( is );
+                logger.error("Done parsing format string");
+
+                // open collectionConfig.xml and read in to w3 Document
+                String collection_config = directory + "collectionConfig.xml";
+                Document config = this.converter.getDOM(new File(collection_config), "UTF-8");
            
-            //String tag_name = "";
-            int k;
-            int index;
-            Element elem;
-            Node current_node = GSXML.getChildByTagName(config, "CollectionConfig");
-            NodeList current_node_list;
-
-            if(service.equals("ClassifierBrowse"))
-            {
-                //tag_name = "browse";
-                // if CLX then need to look in <classifier> X then <format>
-                // default is <browse><format>
-
-                current_node = GSXML.getChildByTagName(current_node, "browse");
-
-                // find CLX
-                if(classifier != null)
+                //String tag_name = "";
+                int k;
+                int index;
+                Element elem;
+                Node current_node = GSXML.getChildByTagName(config, "CollectionConfig");
+                NodeList current_node_list;
+    
+                if(service.equals("ClassifierBrowse"))
                 {
-                    current_node_list = GSXML.getChildrenByTagName(current_node, "classifier");
-                    index = Integer.parseInt(classifier.substring(2)) - 1;
-                    // index should be given by X-1
-                    current_node = current_node_list.item(index);
-                    current_node = GSXML.getChildByTagName(current_node, "format");
+                    //tag_name = "browse";
+                    // if CLX then need to look in <classifier> X then <format>
+                    // default is <browse><format>
+
+                    current_node = GSXML.getChildByTagName(current_node, "browse");
+
+                    // find CLX
+                    if(classifier != null)
+                    {
+                        current_node_list = GSXML.getChildrenByTagName(current_node, "classifier");
+                        index = Integer.parseInt(classifier.substring(2)) - 1;
+                        // index should be given by X-1
+                        current_node = current_node_list.item(index);
+                        current_node = GSXML.getChildByTagName(current_node, "format");
+                    }
+                    else{
+                        current_node = GSXML.getChildByTagName(current_node, "format");
+                    }
                 }
-                else{
-                    current_node = GSXML.getChildByTagName(current_node, "format");
+                else
+                {
+                    // look in <format> with no attributes
+            
+                    current_node_list = GSXML.getChildrenByTagName(current_node, "search");
+                    for(k=0; k<current_node_list.getLength(); k++) 
+                    {
+                        current_node = current_node_list.item(k);
+                        // if current_node has no attributes then break
+                        elem = (Element) current_node;
+                        if(elem.hasAttribute("name")==false)
+                            break;
+                    }
                 }
-            }
-            else
-            {
-                // look in <format> with no attributes
-            
-                current_node_list = GSXML.getChildrenByTagName(current_node, "search");
-                for(k=0; k<current_node_list.getLength(); k++) 
+
+                // Current_node should be a format tag
+                elem = (Element) current_node;
+    
+                logger.error("Current_node = " + elem.getNodeName());
+
+                // seems we want to remove current child/ren and replace with format_statement's child/ren?
+
+                // remove existing
+                current_node_list = elem.getChildNodes();
+                for(k=0; k<current_node_list.getLength(); k++)
                 {
-                    current_node = current_node_list.item(k);
-                    // if current_node has no attributes then break
-                    elem = (Element) current_node;
-                    if(elem.hasAttribute("name")==false)
-                        break;
+                    current_node = elem.removeChild(current_node_list.item(k));
                 }
-            }
-
-            // Current_node should be a format tag
-            elem = (Element) current_node;
-
-            logger.error("Current_node = " + elem.getNodeName());
-
-            // seems we want to remove current child/ren and replace with format_statement's child/ren?
-
-            // remove existing
-            current_node_list = elem.getChildNodes();
-            for(k=0; k<current_node_list.getLength(); k++)
-            {
-                current_node = elem.removeChild(current_node_list.item(k));
-            }
-
-            // append new
-            current_node_list = format_statement.getChildNodes();
-            for(k=0; k<current_node_list.getLength(); k++)
-            {
-                current_node = elem.appendChild(current_node_list.item(k));
-            }
-
-            //String text = GSXML.getNodeText(elem);
-            //logger.error(text);
-            //text = text.replaceAll("_httpsite_", http_site);
-            //text = text.replaceAll("_httpcollection_", http_collection);
-            //GSXML.setNodeText(d, text);
-
-            // Now convert config document to string for writing to file
-            String new_config = GSXML.xmlNodeToString(config);
-
-            // Write to file (not original! for now)
-            try{
+
+                // append new but we have a string!
+                GSXML.setNodeText(elem, format_string);
+
+                //current_node_list = format_statement.getChildNodes();
+                //for(k=0; k<current_node_list.getLength(); k++)
+                //{
+                //    current_node = elem.appendChild(current_node_list.item(k));
+                //}
+
+                //String text = GSXML.getNodeText(elem);
+                //logger.error(text);
+                //text = text.replaceAll("_httpsite_", http_site);
+                //text = text.replaceAll("_httpcollection_", http_collection);
+                //GSXML.setNodeText(d, text);
+
+                // Now convert config document to string for writing to file
+                String new_config = GSXML.xmlNodeToString(config);
+    
+                // Write to file (not original! for now)
                 BufferedWriter writer = new BufferedWriter(new FileWriter(collection_config+".new"));
                 writer.write(new_config);
                 writer.close();
-            } catch (IOException e) {
-                logger.error("IO Exception "+e);
+
+             } catch( Exception ex ) {
+                logger.error("There was an exception "+ex);
+
+                StringWriter sw = new StringWriter();
+                PrintWriter pw = new PrintWriter(sw, true);
+                ex.printStackTrace(pw);
+                pw.flush();
+                sw.flush();
+                logger.error(sw.toString());
             }
+
         }
     }
Index: /main/trunk/greenstone3/web/interfaces/oran/js/gui_div.js
===================================================================
--- /main/trunk/greenstone3/web/interfaces/oran/js/gui_div.js	(revision 23550)
+++ /main/trunk/greenstone3/web/interfaces/oran/js/gui_div.js	(revision 23551)
@@ -3,4 +3,10 @@
 
 var initialised_iframe = "false";
+
+function onTextChange(item, text)
+{
+    item.setAttribute("value",text);
+}
+
 
 //function createFormatStatement()
Index: /main/trunk/greenstone3/web/interfaces/oran/transform/layouts/xml-to-gui.xsl
===================================================================
--- /main/trunk/greenstone3/web/interfaces/oran/transform/layouts/xml-to-gui.xsl	(revision 23550)
+++ /main/trunk/greenstone3/web/interfaces/oran/transform/layouts/xml-to-gui.xsl	(revision 23551)
@@ -236,10 +236,10 @@
             <xsl:variable name="mode">
                 <xsl:choose>
-                    <xsl:when test="not(@mode)">MODE=<input class="mode" type="text" name="rawtextinput" size="10" value="vertical"><xsl:text></xsl:text></input></xsl:when>
-                    <xsl:otherwise>MODE=<input class="mode" type="text" name="rawtextinput" size="10" value="{@mode}"/></xsl:otherwise>
+                    <xsl:when test="not(@mode)">MODE=<input class="mode" type="text" name="rawtextinput" size="10" value="vertical" onChange="onTextChange(this, this.value)"><xsl:text></xsl:text></input></xsl:when>
+                    <xsl:otherwise>MODE=<input class="mode" type="text" name="rawtextinput" size="10" value="{@mode}" onChange="onTextChange(this, this.value)"/></xsl:otherwise>
                 </xsl:choose>
             </xsl:variable>
     
-            <table class="header"><tbody><tr><td class="header">MATCH=<input class="match" type="text" name="rawtextinput" size="10" value="{@match}"/></td><td class="header"><xsl:copy-of select="$mode"/></td><td class="header"><a href="#" class="minmax ui-icon ui-icon-plusthick" title="Click me to expand">[+]</a></td><td class="header"><a href="#" class="remove ui-icon ui-icon-closethick" title="Click me to remove"/></td></tr></tbody></table>
+            <table class="header"><tbody><tr><td class="header">MATCH=<input class="match" type="text" name="rawtextinput" size="10" value="{@match}" onChange="onTextChange(this, this.value)"/></td><td class="header"><xsl:copy-of select="$mode"/></td><td class="header"><a href="#" class="minmax ui-icon ui-icon-plusthick" title="Click me to expand">[+]</a></td><td class="header"><a href="#" class="remove ui-icon ui-icon-closethick" title="Click me to remove"/></td></tr></tbody></table>
 
                 <table class="table" border="1">
@@ -356,5 +356,5 @@
         <div class="block leaf gsf_text" title="gsf:text">
                 <xsl:variable name="rawtext"><xsl:value-of select="."/></xsl:variable>
-                <table class="header"><tbody><tr><td class="header"><input class="text" type="text" name="rawtextinput" size="10" value="{$rawtext}"></input></td><td class="header"><a href="[myhref]" class="ui-icon ui-icon-closethick"/></td></tr></tbody></table>
+                <table class="header"><tbody><tr><td class="header"><input class="text" type="text" name="rawtextinput" size="10" value="{$rawtext}" onChange="onTextChange(this, this.value)"></input></td><td class="header"><a href="[myhref]" class="ui-icon ui-icon-closethick"/></td></tr></tbody></table>
         </div>
     </xsl:template>
