hxml := NULL::XML;
subxml := NULL::XML;
- FOR subrec IN SELECT * FROM biblio.record_entry bre
- JOIN metabib.metarecord_source_map mmsm ON (mmsm.metarecord = mmr_id)
- WHERE mmsm.source = bre.id LOOP
-
- -- collect holdings for all records
- -- XXX: holdings limits and offsets are applied individually to each
- -- subordinate record. This could lead to large XML blobs for
- -- large metarecords. Does this need to change?
+ FOR subrec IN SELECT bre.* FROM biblio.record_entry bre
+ JOIN metabib.metarecord_source_map mmsm ON (mmsm.source = bre.id)
+ JOIN metabib.metarecord mmr ON (mmr.id = mmsm.metarecord)
+ WHERE mmr.id = mmr_id
+ ORDER BY CASE WHEN bre.id = mmr.master_record THEN 0 ELSE bre.id END
+ LIMIT COALESCE((slimit->'bre')::INT, 5) LOOP
+
+ -- collect holdings for all added records
IF ('holdings_xml' = ANY (includes)) THEN
hxml := XMLCONCAT(hxml, unapi.holdings_xml(
subrec.id, ouid, org, depth,
END IF;
IF subrec.id = leadrec.id THEN CONTINUE; END IF;
- -- Append choice data from the XML of the non-lead records to the
- -- XML of the lead record
+ -- Append choice data from the the non-lead records to the
+ -- the lead record document
FOREACH xml_frag IN ARRAY
(SELECT * FROM xpath(sub_xpath, subrec.marc::XML)) LOOP
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)
+ -- now be a different type of document (e.g. record -> mods)
top_el := REGEXP_REPLACE(xml_buf, E'^.*?<((?:\\S+:)?' ||
layout.holdings_element || ').*$', E'\\1');
'</' || top_el || '>(.*?)$', axml || '</' || top_el || E'>\\1');
END IF;
- IF hxml IS NOT NULL THEN -- XXX how do we configure the holdings position?
+ IF hxml IS NOT NULL THEN
xml_buf := REGEXP_REPLACE(xml_buf,
'</' || top_el || '>(.*?)$', hxml || '</' || top_el || E'>\\1');
END IF;