CREATE OR REPLACE FUNCTION marc_cleanup_james (TEXT) RETURNS TEXT AS $$ $_ = $_[0]; s/\n\s*//g; # linebreaks and whitespace # add indicators to tags without them s/datafield tag="(...)">/datafield tag="$1" ind1=" " ind2=" ">/g; # make blank indicators from null ones s/ind1=""/ind1=" "/g; s/ind2=""/ind2=" "/g; # remove namespace stuff s/ xmlns.marc.\"http...www.loc.gov.MARC21.slim.\" //g; s/ xmlns\:marc\=\"http\:\/\/www\.loc\.gov\/MARC21\/slim\"//g; s/marc\:record/record/g; #delete datafields without a tag value s///g; # seen a few examples of this s/tag="undefined"/tag="020"/g; # make subfields a 999 if they only have 1 character tags s/tag="."/tag="999"/g; # if they have 2 character tags, add a 0 to the field s/tag="(..)"/tag="0$1"/g; # remove empty elements s///g; return $_; $$ LANGUAGE plperlu;