3 INSERT INTO config.upgrade_log (version) VALUES ('0514'); -- miker
5 CREATE OR REPLACE FUNCTION unapi.bre ( obj_id BIGINT, format TEXT, ename TEXT, includes TEXT[], org TEXT, depth INT DEFAULT NULL, slimit INT DEFAULT NULL, soffset INT DEFAULT NULL, include_xmlns BOOL DEFAULT TRUE ) RETURNS XML AS $F$
7 me biblio.record_entry%ROWTYPE;
8 layout unapi.bre_output_layout%ROWTYPE;
9 xfrm config.xml_transform%ROWTYPE;
18 SELECT id INTO ouid FROM actor.org_unit WHERE shortname = org;
24 IF format = 'holdings_xml' THEN -- the special case
25 output := unapi.holdings_xml( obj_id, ouid, org, depth, includes, slimit, soffset, include_xmlns);
29 SELECT * INTO layout FROM unapi.bre_output_layout WHERE name = format;
31 IF layout.name IS NULL THEN
35 SELECT * INTO xfrm FROM config.xml_transform WHERE name = layout.transform;
37 SELECT * INTO me FROM biblio.record_entry WHERE id = obj_id;
39 -- grab SVF if we need them
40 IF ('mra' = ANY (includes)) THEN
41 axml := unapi.mra(obj_id,NULL,NULL,NULL,NULL);
46 -- grab hodlings if we need them
47 IF ('holdings_xml' = ANY (includes)) THEN
48 hxml := unapi.holdings_xml(obj_id, ouid, org, depth, evergreen.array_remove_item_by_value(includes,'holdings_xml'), slimit, soffset, include_xmlns);
54 -- generate our item node
57 IF format = 'marcxml' THEN
59 IF tmp_xml !~ E'<marc:' THEN -- If we're not using the prefixed namespace in this record, then remove all declarations of it
60 tmp_xml := REGEXP_REPLACE(tmp_xml, ' xmlns:marc="http://www.loc.gov/MARC21/slim"', '', 'g');
63 tmp_xml := oils_xslt_process(me.marc, xfrm.xslt)::XML;
66 top_el := REGEXP_REPLACE(tmp_xml, E'^.*?<((?:\\S+:)?' || layout.holdings_element || ').*$', E'\\1');
68 IF axml IS NOT NULL THEN
69 tmp_xml := REGEXP_REPLACE(tmp_xml, '</' || top_el || '>(.*?)$', axml || '</' || top_el || E'>\\1');
72 IF hxml IS NOT NULL THEN -- XXX how do we configure the holdings position?
73 tmp_xml := REGEXP_REPLACE(tmp_xml, '</' || top_el || '>(.*?)$', hxml || '</' || top_el || E'>\\1');
76 IF ('bre.unapi' = ANY (includes)) THEN
77 output := REGEXP_REPLACE(
79 '</' || top_el || '>(.*?)',
83 'http://www.w3.org/1999/xhtml' AS xmlns,
85 'tag:open-ils.org:U2@bre/' || obj_id || '/' || org AS title
87 )::TEXT || '</' || top_el || E'>\\1'
93 output := REGEXP_REPLACE(output::TEXT,E'>\\s+<','><','gs')::XML;