Index: gsdl/trunk/src/recpt/dynamicclassifieraction.cpp
===================================================================
--- gsdl/trunk/src/recpt/dynamicclassifieraction.cpp	(revision 16060)
+++ gsdl/trunk/src/recpt/dynamicclassifieraction.cpp	(revision 16061)
@@ -164,14 +164,12 @@
     selected_grouping_node_OID = output_grouping_nodes (classifier_options, args, collectproto, browsers, disp, outconvert, textout, logout);
   }
-
-  // Prepare to output the classifier (and maybe document) nodes
-  text_t classifier_node_OID = args["dcn"];
+  text_t classifier_node_OID = args["dcn"];  // args["dcn"] may have been modified by output_grouping_nodes()
   int classifier_node_indent = 0;
 
   // Simple case at the top level: just output the child classifier nodes
-  if (args["dcn"] == selected_grouping_node_OID)
-  {
-    text_t metadata_value_filter = args["dcn"] + "*";
-    output_child_classifier_nodes (classifier_node_OID, metadata_value_filter, classifier_node_indent, classifier_options, args, collectproto, browsers, disp, outconvert, textout, logout);
+  if (classifier_node_OID == selected_grouping_node_OID)
+  {
+    text_t metadata_value_filter = selected_grouping_node_OID + "*";
+    output_child_classifier_nodes (classifier_node_OID, "", metadata_value_filter, classifier_node_indent, classifier_options, args, collectproto, browsers, disp, outconvert, textout, logout);
   }
 
@@ -179,22 +177,25 @@
   else
   {
-    // Output the parent classifier nodes
-    output_parent_classifier_nodes (classifier_node_OID, classifier_node_indent, classifier_options, args, collectproto, browsers, disp, outconvert, textout, logout);
-
-    // Display the selected classifier node
-    text_tarray classifier_node_labels;
-    splitchar(classifier_node_OID.begin(), classifier_node_OID.end(), '|', classifier_node_labels);
-    text_t classifier_node_label = classifier_node_labels.back();
-    text_t classifier_node_numleafdocs = "?";
-    display_classifier_node (classifier_node_OID, classifier_node_label, classifier_node_numleafdocs, classifier_node_indent, args, collectproto, browsers, disp, outconvert, textout, logout);
-    classifier_node_indent++;
+    // This is the classifier node OID without any grouping information
+    text_t classifier_node_OID_sans_grouping = classifier_node_OID;
+    if (starts_with (classifier_node_OID, selected_grouping_node_OID + "|"))
+    {
+      classifier_node_OID_sans_grouping = substr (classifier_node_OID.begin() + (selected_grouping_node_OID + "|").size(), classifier_node_OID.end());
+    }
+
+    // Determine the parent classifier node labels
+    text_tlist parent_classifier_node_labels;
+    splitchar(classifier_node_OID_sans_grouping.begin(), classifier_node_OID_sans_grouping.end(), '|', parent_classifier_node_labels);
+
+    // Output the parent classifier nodes and the current classifier node
+    output_upper_classifier_nodes (selected_grouping_node_OID, parent_classifier_node_labels, classifier_node_indent, classifier_options, args, collectproto, browsers, disp, outconvert, textout, logout);
 
     // Output the child classifier nodes
-    text_t metadata_value_filter = args["dcn"] + "|*";
-    output_child_classifier_nodes (classifier_node_OID, metadata_value_filter, classifier_node_indent, classifier_options, args, collectproto, browsers, disp, outconvert, textout, logout);
+    text_t classifier_node_metadata_value = classifier_node_OID_sans_grouping;
+    text_t metadata_value_filter = classifier_node_OID_sans_grouping + "|*";
+    output_child_classifier_nodes (classifier_node_OID, classifier_node_metadata_value, metadata_value_filter, classifier_node_indent, classifier_options, args, collectproto, browsers, disp, outconvert, textout, logout);
 
     // Get the document nodes at this level
     text_t metadata_element_name = classifier_options["metadata_element_name"];
-    text_t classifier_node_metadata_value = args["dcn"];
     text_t sort_documents_by = classifier_options["-sort_documents_by"];
     FilterResponse_t documents_response;
@@ -285,5 +286,5 @@
   {
     // Is this the grouping node that is currently selected?
-    if ((*grouping_node_iterator).OID == args["dcn"])
+    if (starts_with (args["dcn"], (*grouping_node_iterator).OID))
     {
       selected_grouping_node_OID = (*grouping_node_iterator).OID;
@@ -320,19 +321,15 @@
 
 
-void dynamicclassifieraction::output_parent_classifier_nodes (text_t classifier_node_OID,
-	      						      int& classifier_node_indent,
-							      text_tmap classifier_options, cgiargsclass &args,
-							      recptproto *collectproto, browsermapclass *browsers,
-							      displayclass &disp, outconvertclass &outconvert,
-							      ostream &textout, ostream &logout)
-{
-  // Determine the parent classifier nodes
-  text_tarray parent_classifier_node_labels;
-  splitchar(classifier_node_OID.begin(), classifier_node_OID.end(), '|', parent_classifier_node_labels);
-  parent_classifier_node_labels.pop_back();
-
+void dynamicclassifieraction::output_upper_classifier_nodes (text_t root_classifier_node_OID,
+							     text_tlist parent_classifier_node_labels,
+							     int& classifier_node_indent,
+							     text_tmap classifier_options, cgiargsclass &args,
+							     recptproto *collectproto, browsermapclass *browsers,
+							     displayclass &disp, outconvertclass &outconvert,
+							     ostream &textout, ostream &logout)
+{
   // Display the parent classifier nodes
-  text_t parent_classifier_node_OID = "";
-  text_tarray::iterator parent_classifier_node_labels_iterator = parent_classifier_node_labels.begin();
+  text_t parent_classifier_node_OID = root_classifier_node_OID;
+  text_tlist::iterator parent_classifier_node_labels_iterator = parent_classifier_node_labels.begin();
   while (parent_classifier_node_labels_iterator != parent_classifier_node_labels.end())
   {
@@ -350,4 +347,5 @@
 
 void dynamicclassifieraction::output_child_classifier_nodes (text_t classifier_node_OID,
+							     text_t classifier_node_metadata_value,
 							     text_t metadata_value_filter,
 							     int& classifier_node_indent,
@@ -371,14 +369,14 @@
   // After processing any hierarchical metadata values we're left with the child classifer nodes
   map<text_t, int, lttext_t> child_classifier_nodes;
-  text_t current_position = args["dcn"];
   ResultDocInfo_tarray::iterator metadata_value_iterator = metadata_values_response.docInfo.begin();
   while (metadata_value_iterator != metadata_values_response.docInfo.end())
   {
     text_t metadata_value = (*metadata_value_iterator).OID;
+    // logout << "Metadata value: " << metadata_value << ", current position: " << current_position << endl;
 
     // If we're not at the top-level we need to remove the current position from the metadata values
-    if (current_position != "" && starts_with(metadata_value, current_position + "|"))
-    {
-      metadata_value = substr(metadata_value.begin() + (current_position + "|").size(), metadata_value.end());
+    if (starts_with(metadata_value, classifier_node_metadata_value + "|"))
+    {
+      metadata_value = substr(metadata_value.begin() + (classifier_node_metadata_value + "|").size(), metadata_value.end());
     }
 
Index: gsdl/trunk/src/recpt/dynamicclassifieraction.h
===================================================================
--- gsdl/trunk/src/recpt/dynamicclassifieraction.h	(revision 16060)
+++ gsdl/trunk/src/recpt/dynamicclassifieraction.h	(revision 16061)
@@ -70,12 +70,14 @@
 				ostream &textout, ostream &logout);
 
-  void output_parent_classifier_nodes (text_t classifier_node_OID,
-				       int& classifier_node_indent,
-				       text_tmap classifier_options, cgiargsclass &args,
-				       recptproto *collectproto, browsermapclass *browsers,
-				       displayclass &disp, outconvertclass &outconvert,
-				       ostream &textout, ostream &logout);
+  void output_upper_classifier_nodes (text_t root_classifier_node_OID,
+				      text_tlist parent_classifier_node_labels,
+				      int& classifier_node_indent,
+				      text_tmap classifier_options, cgiargsclass &args,
+				      recptproto *collectproto, browsermapclass *browsers,
+				      displayclass &disp, outconvertclass &outconvert,
+				      ostream &textout, ostream &logout);
 
   void output_child_classifier_nodes (text_t classifier_node_OID,
+				      text_t classifier_node_metadata_value,
 				      text_t metadata_value_filter,
 				      int& classifier_node_indent,
