LP#1053397 unapi.mmr() repairs
authorBill Erickson <berick@esilibrary.com>
Fri, 17 Jan 2014 19:55:14 +0000 (14:55 -0500)
committerBill Erickson <berick@esilibrary.com>
Fri, 17 Jan 2014 19:55:14 +0000 (14:55 -0500)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.unapi-mmr.sql

index cdcef16..6fe1fde 100644 (file)
@@ -115,14 +115,11 @@ BEGIN
     END LOOP;
 
     -- append data from the subordinate records to the 
-    -- record document before applying the main XSLT
-
-    top_el := REGEXP_REPLACE(xml_buf, E'^.*?<((?:\\S+:)?' || 
-        layout.holdings_element || ').*$', E'\\1');
+    -- main record document before applying the XSLT
 
     IF subxml IS NOT NULL THEN 
         xml_buf := REGEXP_REPLACE(xml_buf, 
-            '</' || top_el || '>(.*?)$', subxml || '</' || top_el || E'>\\1');
+            '</record>(.*?)$', subxml || '</record>' || E'\\1');
     END IF;
 
     IF format = 'marcxml' THEN
@@ -136,6 +133,11 @@ BEGIN
         xml_buf := oils_xslt_process(xml_buf, xfrm.xslt)::XML;
     END IF;
 
+    -- update top_el to reflect the change in xml_buf, which may
+    -- now be a wholly different type of document (e.g. record -> mods)
+    top_el := REGEXP_REPLACE(xml_buf, E'^.*?<((?:\\S+:)?' || 
+        layout.holdings_element || ').*$', E'\\1');
+
     IF axml IS NOT NULL THEN 
         xml_buf := REGEXP_REPLACE(xml_buf, 
             '</' || top_el || '>(.*?)$', axml || '</' || top_el || E'>\\1');
@@ -163,6 +165,7 @@ BEGIN
         output := xml_buf;
     END IF;
 
+    -- remove ignorable whitesace
     output := REGEXP_REPLACE(output::TEXT,E'>\\s+<','><','gs')::XML;
     RETURN output;
 END;