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
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');
output := xml_buf;
END IF;
+ -- remove ignorable whitesace
output := REGEXP_REPLACE(output::TEXT,E'>\\s+<','><','gs')::XML;
RETURN output;
END;