trim excessive trailing whitespace from subfield contents
authorGalen Charlton <gmc@esilibrary.com>
Thu, 2 Aug 2012 15:28:42 +0000 (11:28 -0400)
committerGalen Charlton <gmc@esilibrary.com>
Thu, 2 Aug 2012 15:28:42 +0000 (11:28 -0400)
If a subfield has too much (arbitrarily defined as at least 10)
of trailing whitespace, trim the whitespace.  This works around
a problem applying certain stylesheets (like the MARCXML-to-MODS
stylesheet) that use a recursive XSLT function to trim whitespace.

Note that only "excessive" whitespace is trimmed; some systems
emit subfields that contain semantically significant trailing
whitespace in certain fields.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>

marc_cleanup

index c26525c..e0c20a7 100755 (executable)
@@ -193,6 +193,12 @@ sub do_automated_cleanups {
             message("Dollar sign corrected");
         }
 
+        # excessive trailing whitespace in subfield contents
+        if ($record[$ptr] =~ m|\s{10,}</subfield>|) {
+            $record[$ptr] =~ s|\s{10,}</subfield>|</subfield>|;
+            message("Trailing whitespace trimmed from subfield contents");
+        }
+
         # automatable subfield maladies
         $record[$ptr] =~ s/code=" ">c/code="c">/;
         $record[$ptr] =~ s/code=" ">\$/code="c">\$/;