Index: /trunk/gsdl3/src/java/org/greenstone/gsdl3/action/BrowseAction.java
===================================================================
--- /trunk/gsdl3/src/java/org/greenstone/gsdl3/action/BrowseAction.java	(revision 4079)
+++ /trunk/gsdl3/src/java/org/greenstone/gsdl3/action/BrowseAction.java	(revision 4080)
@@ -10,4 +10,5 @@
 
 import java.util.HashMap;
+import java.util.Vector;
 import java.io.File;
 
@@ -115,5 +116,4 @@
 	}
 	
-	
 	// create a classifier elem to return in the page
 	Element page_classifier = doc_.createElement(GSXML.CLASSIFIER_ELEM);
@@ -123,5 +123,16 @@
 	String top_id = OID.getTop(classifier_node);
 	page_classifier.setAttribute(GSXML.NAME_ATT, top_id);
-	    
+
+	// add in the format info into the stylesheet
+	System.out.println("transforming format:"+converter_.getString(format_response));
+	Element format_elem = getAndTransformFormat(format_response);
+	System.out.println("transformed format:"+converter_.getString(format_elem));
+	if (format_elem != null) {
+	    Element this_format = GSXML.getNamedElement(format_elem, GSXML.CLASSIFIER_ELEM, GSXML.NAME_ATT, top_id);
+	    if (this_format != null) {
+		GSXSLT.mergeStylesheets(style_doc, this_format);
+	    }
+	}
+		    
 	// get the browse structure for the selected node
 	Element classify_message = doc_.createElement(GSXML.MESSAGE_ELEM);
@@ -183,6 +194,8 @@
 	}
 
+	
 	// get the metadata for each classifier node, 
 	// then for each document node
+
 	Element metadata_message = doc_.createElement(GSXML.MESSAGE_ELEM);
 
@@ -190,25 +203,10 @@
 	boolean did_documents = false;
 	
-	// Create a parameter list to specify the required metadata information
-	// for now get Title
-	Element meta_param_list = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
-	Element meta_param = doc_.createElement(GSXML.PARAM_ELEM);
-	meta_param_list.appendChild(meta_param);
-	meta_param.setAttribute(GSXML.NAME_ATT, "metadata");
-	meta_param.setAttribute(GSXML.VALUE_ATT, "Source");
-	meta_param = doc_.createElement(GSXML.PARAM_ELEM);
-	meta_param_list.appendChild(meta_param);
-	meta_param.setAttribute(GSXML.NAME_ATT, "metadata");
-	meta_param.setAttribute(GSXML.VALUE_ATT, "Keyword");
-	meta_param = doc_.createElement(GSXML.PARAM_ELEM);
-	meta_param_list.appendChild(meta_param);
-	meta_param.setAttribute(GSXML.NAME_ATT, "metadata");
-	meta_param.setAttribute(GSXML.VALUE_ATT, "Title");
-	    
-	// if there are classifier nodes (I think there always will be) 
+    
+	// if there are classifier nodes 
 	// create a metadata request for the classifier, and add it to 
 	// the the message
 	cl_nodes = page_classifier.getElementsByTagName(GSXML.CLASS_NODE_ELEM);
-	    
+	
 	if (cl_nodes.getLength() > 0) {
 	    did_classifier = true;
@@ -219,6 +217,4 @@
 	    cl_meta_request.setAttribute(GSXML.LANG_ATT, lang);
 	    
-	    cl_meta_request.appendChild(meta_param_list);
-	    
 	    Element new_cl_nodes_list = doc_.createElement(GSXML.CLASS_NODE_ELEM+GSXML.LIST_MODIFIER);
 	    cl_meta_request.appendChild(new_cl_nodes_list);
@@ -230,6 +226,18 @@
 		new_cl_nodes_list.appendChild(cl);
 	    }
-	}
-	
+
+	    // create and add in the param list
+	    Vector classifier_metadata = GSXSLT.extractWantedMetadata(style_doc, GSXML.CLASS_NODE_ELEM);
+	    if (classifier_metadata.isEmpty()) {
+		System.err.println("BrowseAction: no classifier metadata specified!!");
+		did_classifier = false;
+		metadata_message.removeChild(cl_meta_request);
+	    } else {
+		Element meta_param_list = GSXML.createMetadataParamList(doc_, classifier_metadata);
+		cl_meta_request.appendChild(meta_param_list);
+	    }
+
+	}
+
 	// if there are document nodes in the classification (happens 
 	// sometimes), create a second request for document metadata and 
@@ -244,7 +252,4 @@
 	    doc_meta_request.setAttribute(GSXML.LANG_ATT, lang);
 	    
-	    // for now, use the same metadata list - this will probably change once we look at format statements
-	    doc_meta_request.appendChild(meta_param_list.cloneNode(true));
-	    
 	    Element doc_list = doc_.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
 	    doc_meta_request.appendChild(doc_list);
@@ -257,6 +262,18 @@
 	    }
 
-	}
-
+	    // create and add in the param list
+	    Vector doc_metadata = GSXSLT.extractWantedMetadata(style_doc, GSXML.DOC_NODE_ELEM);
+	    if (doc_metadata.isEmpty()) {
+		System.err.println("BrowseAction: no document metadata specified!!");
+		did_documents = false;
+		metadata_message.removeChild(doc_meta_request);
+	    } else {
+		Element meta_param_list = GSXML.createMetadataParamList(doc_, doc_metadata);
+		doc_meta_request.appendChild(meta_param_list);
+	    }
+
+
+	}
+	
 	// process the metadata requests
 	Element metadata_response = (Element)mr_.process(metadata_message);
@@ -288,14 +305,6 @@
 	}
 	    
-	// add in the format info
-	Element format_elem = getAndTransformFormat(format_response);
-	if (format_elem != null) {
-	    Element this_format = GSXML.getNamedElement(format_elem, GSXML.CLASSIFIER_ELEM, GSXML.NAME_ATT, top_id);
-	    if (this_format != null) {
-		GSXSLT.mergeStylesheets(style_doc, this_format);
-	    }
-	}
-	
-	System.out.println("(BrowseAction) Page:\n" + converter_.getPrettyString(page));
+
+	//System.out.println("(BrowseAction) Page:\n" + converter_.getPrettyString(page));
 
 	// transform the page
Index: /trunk/gsdl3/src/java/org/greenstone/gsdl3/action/QueryAction.java
===================================================================
--- /trunk/gsdl3/src/java/org/greenstone/gsdl3/action/QueryAction.java	(revision 4079)
+++ /trunk/gsdl3/src/java/org/greenstone/gsdl3/action/QueryAction.java	(revision 4080)
@@ -11,4 +11,5 @@
 
 import java.util.HashMap;
+import java.util.Vector;
 import java.util.Map;
 import java.util.Iterator;
@@ -155,4 +156,11 @@
 	}
 	
+	// add in the format info to the stylesheet if there is any
+	Element format_elem = getAndTransformFormat(format_response);
+	if (format_elem != null) {
+	    GSXSLT.mergeStylesheets(style_doc, format_elem);
+	}
+
+
 	// do the query
 	Element mr_query_message = doc_.createElement(GSXML.MESSAGE_ELEM);
@@ -163,4 +171,6 @@
 	Element query_param_list = (Element)doc_.importNode(cgi_param_list, true);
 	mr_query_request.appendChild(query_param_list);
+
+	// do the query
        	Element mr_query_response = (Element)mr_.process(mr_query_message);
 
@@ -169,15 +179,16 @@
 	if (query_result_metadata_list == null) {
 	    System.err.println("QueryAction: Warning: No query result metadata.\n");
-	}
+	} else { // add it into the page response
+	    page_response.appendChild(doc_.importNode(query_result_metadata_list, true)); 
+	}
+	
 	path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.TERM_ELEM+GSXML.LIST_MODIFIER);
 	Element query_term_info_list = (Element) GSXML.getNodeByPath(mr_query_response, path);
 	if (query_term_info_list == null) {
 	    System.err.println("QueryAction: Warning: No query term information.\n");
-	}
-
-	// this result is the list of docs.
-	// now take that list, and get the Titles
-	// for now, just create a whole new request
-	
+	} else { // add it into the page response
+	    page_response.appendChild(doc_.importNode(query_term_info_list, true));
+	}
+
 	// check that there are some documents - for now check the list, but later should use a numdocs metadata elem
 	path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
@@ -187,8 +198,4 @@
 	// documentList not present if no docs found
 	if (document_list == null) {
-	    
-	    //Element result_response = (Element)GSXML.getChildByTagName(mr_query_response, GSXML.RESPONSE_ELEM);
-
-	    //page.appendChild(doc_.importNode(result_response, true));
 	    GSXSLT.absoluteIncludePaths(style_doc, config_);
 	    return (Element)transformer_.transform(style_doc, page);    
@@ -196,12 +203,18 @@
 	}
 	
-	// add in the format info
-	Element format_elem = getAndTransformFormat(format_response);
-	if (format_elem != null) {
-	    GSXSLT.mergeStylesheets(style_doc, format_elem);
-	}
-
-	// we have a doc list, so get the metadata - for now, get title.
-	// can we dynamically decide what metadata to get?
+	
+	// we have a doc list, so get the metadata - look through the stylesheet to determine what metadata to ask for
+
+	Vector document_metadata = GSXSLT.extractWantedMetadata(style_doc, GSXML.DOC_NODE_ELEM);
+	if (document_metadata.isEmpty()) {
+	    System.err.println("no document metadata specified!!");
+	    // we dont need to do the metadata request, just append the original doc list and return the page
+	    page_response.appendChild(doc_.importNode(document_list, true));
+	    GSXSLT.absoluteIncludePaths(style_doc, config_);
+	    return (Element)transformer_.transform(style_doc, page);
+
+	} 
+	// we have to do the metadata request
+
 	Element mr_metadata_message = doc_.createElement(GSXML.MESSAGE_ELEM);
 	Element mr_metadata_request = doc_.createElement(GSXML.REQUEST_ELEM);
@@ -213,12 +226,9 @@
 	mr_metadata_request.setAttribute(GSXML.TO_ATT, to);
 
-	// Create a parameter list to specify the required metadata information
-	Element dm_param_list = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
+	Element dm_param_list = GSXML.createMetadataParamList(doc_, document_metadata);
 	mr_metadata_request.appendChild(dm_param_list);
-	Element dm_param = doc_.createElement(GSXML.PARAM_ELEM);
-	dm_param_list.appendChild(dm_param);
-	dm_param.setAttribute(GSXML.NAME_ATT, "metadata");
-	dm_param.setAttribute(GSXML.VALUE_ATT, "Title");
-
+	
+	
+	// add in the doc node list too
 	mr_metadata_request.appendChild(doc_.importNode(document_list, true));
 	Element mr_metadata_response = (Element) mr_.process(mr_metadata_message);	
@@ -229,12 +239,4 @@
 	if (query_result_document_list != null) {
 	    page_response.appendChild(doc_.importNode(query_result_document_list, true));
-	}
-	// If there is some metadata about the query results, add it in
-	if (query_result_metadata_list != null) {
-	    page_response.appendChild(doc_.importNode(query_result_metadata_list, true));
-	}
-	// If there is some metadata about the query results, add it in
-	if (query_term_info_list != null) {
-	    page_response.appendChild(doc_.importNode(query_term_info_list, true));
 	}
 
