Index: /main/trunk/greenstone2/perllib/classify/List.pm
===================================================================
--- /main/trunk/greenstone2/perllib/classify/List.pm	(revision 29093)
+++ /main/trunk/greenstone2/perllib/classify/List.pm	(revision 29094)
@@ -44,4 +44,15 @@
 }
 
+my $meta_select_type_list =
+    [ 
+      { 'name' => "firstvalue",
+	'desc' => "{List.metadata_selection.firstvalue}"},
+      { 'name' => "firstvalidmetadata",
+	'desc' => "{List.metadata_selection.firstvalidmetadata}"},
+      { 'name' => "allvalues",
+	'desc' => "{List.metadata_selection.allvalues}"} ];
+my $valid_meta_select_types = { 'firstvalue' => 1,
+				'firstvalidmetadata' => 1,
+				'allvalues' => 1 };
 my $partition_type_list = 
     [ { 'name' => "per_letter",
@@ -74,5 +85,9 @@
 	'type' => "metadata",
 	'reqd' => "yes" },
-
+      { 'name' => "metadata_selection_mode",
+	'desc' => "{List.metadata_selection_mode}",
+	'type' => "enumstring", # Must be enumstring because multiple values can be specified (separated by '/')
+	'list' => $meta_select_type_list,
+	'deft' => "firstvalidmetadata" },
       # The interesting options
       { 'name' => "bookshelf_type", 
@@ -162,4 +177,20 @@
     }
 
+    # meta selection mode for each level
+    if (!$self->{'metadata_selection_mode'}) {
+	foreach my $metadata_group (@metadata_groups) {
+	    $self->{$metadata_group . ".metadata_selection_mode"} = "firstvalidmetadata";
+	}
+    } else {
+	my @metadata_selection_mode_list = split(/\//, $self->{'metadata_selection_mode'});
+	foreach my $metadata_group (@metadata_groups) {
+	    my $meta_select_mode = shift(@metadata_selection_mode_list);
+	    if (defined($meta_select_mode) && defined $valid_meta_select_types->{$meta_select_mode}) {
+		$self->{$metadata_group . ".metadata_selection_mode"} = $meta_select_mode;
+	    } else {
+		$self->{$metadata_group . ".metadata_selection_mode"} = "firstvalidmetadata";	
+	    }
+	}
+    }	
     # Whether to group items into a bookshelf, (must be 'always' for all metadata fields except the last)
     foreach my $metadata_group (@metadata_groups) {
@@ -276,5 +307,10 @@
     }
     $self->{'sort_leaf_nodes_using_metadata_groups'} = \@sort_leaf_nodes_using_metadata_groups;
-
+    foreach my $sort_group (@sort_leaf_nodes_using_metadata_groups) {
+	# set metadata_select_type, if not already set - might be already set if the same group was used in -metadata
+	if (!defined $self->{$sort_group . ".metadata_selection_mode"}) {
+	    $self->{$sort_group . ".metadata_selection_mode"} = "firstvalue";
+	}
+    }
     # Create an instance of the Unicode::Collate object if better Unicode sorting is desired
     if ($self->{'sort_using_unicode_collation'}) {
@@ -413,5 +449,10 @@
 
 		    # Add the metadata value into the list for this combination of metadata group and section
-		    push(@{$self->{$metadata_group . ".list"}->{$section_OID}}, $lc_metadata_value);
+		    # text that we have some non-whitespace chars
+		    if ($lc_metadata_value =~ /\S/) {
+			
+			push(@{$self->{$metadata_group . ".list"}->{$section_OID}}, $lc_metadata_value);
+			
+		    
 		    # add the actual value into the stored values so we can remember the case
 		    if (!$self->{'standardize_capitalization'}) {
@@ -421,8 +462,10 @@
 			    $self->{$metadata_group . ".actualvalues"}->{$lc_metadata_value}->{$metadata_value} = 1;
 			}
-		    }	    
-		}
-		last if (@metadata_values > 0);
-	    }
+		    }
+			last if ($self->{$metadata_group . ".metadata_selection_mode"} eq "firstvalue");
+		    }
+		} # foreach metadatavalue
+		last if ((@metadata_values > 0) &&  $self->{$metadata_group . ".metadata_selection_mode"} =~ /^(firstvalue|firstvalidmetadata)$/ );
+	    } # foreach metadata element
 
 	    $metadata_groups_done{$metadata_group} = 1;
Index: /main/trunk/greenstone2/perllib/strings.properties
===================================================================
--- /main/trunk/greenstone2/perllib/strings.properties	(revision 29093)
+++ /main/trunk/greenstone2/perllib/strings.properties	(revision 29094)
@@ -649,6 +649,10 @@
 List.level_partition.approximate_size:Create a partition per letter, then group or split the letters to get approximately the same sized partitions. 
 
-List.metadata:Metadata fields used for classification. Use '/' to separate the levels in the hierarchy and ';' to separate metadata fields within each level.
-
+List.metadata:Metadata fields used for classification. Use '/' to separate the levels in the hierarchy and ';' or ',' to separate metadata fields within each level.
+
+List.metadata_selection_mode:Determines how many metadata values the document is classified by, within each level. Use '/' to separate the levels.
+List.metadata_selection.firstvalue:Only classify by a single metadata value, the first one encountered.
+List.metadata_selection.firstvalidmetadata:Classify by all the metadata values of the first element in the list that has values.
+List.metadata_selection.allvalues:Classify by all metadata values found, from all elements in the list.
 List.partition_name_length:The length of the partition name; defaults to a variable length from 1 up to 3 characters, depending on how many are required to distinguish the partition start from its end. This option only applies when partition_type_within_level is set to 'constant_size'.
 
