4 CREATE OR REPLACE FUNCTION unapi.bre (
10 depth INT DEFAULT NULL,
11 slimit HSTORE DEFAULT NULL,
12 soffset HSTORE DEFAULT NULL,
13 include_xmlns BOOL DEFAULT TRUE,
14 pref_lib INT DEFAULT NULL
18 me biblio.record_entry%ROWTYPE;
19 layout unapi.bre_output_layout%ROWTYPE;
20 xfrm config.xml_transform%ROWTYPE;
30 IF org = '-' OR org IS NULL THEN
31 SELECT shortname INTO org FROM evergreen.org_top();
34 SELECT id INTO ouid FROM actor.org_unit WHERE shortname = org;
40 IF format = 'holdings_xml' THEN -- the special case
41 output := unapi.holdings_xml( obj_id, ouid, org, depth, includes, slimit, soffset, include_xmlns);
45 SELECT * INTO layout FROM unapi.bre_output_layout WHERE name = format;
47 IF layout.name IS NULL THEN
51 SELECT * INTO xfrm FROM config.xml_transform WHERE name = layout.transform;
53 SELECT * INTO me FROM biblio.record_entry WHERE id = obj_id;
55 -- grab bib_source, if any
56 IF ('cbs' = ANY (includes) AND me.source IS NOT NULL) THEN
57 source := unapi.cbs(me.source,NULL,NULL,NULL,NULL);
62 -- grab SVF if we need them
63 IF ('mra' = ANY (includes)) THEN
64 axml := unapi.mra(obj_id,NULL,NULL,NULL,NULL);
69 -- grab holdings if we need them
70 IF ('holdings_xml' = ANY (includes)) THEN
71 hxml := unapi.holdings_xml(obj_id, ouid, org, depth, evergreen.array_remove_item_by_value(includes,'holdings_xml'), slimit, soffset, include_xmlns, pref_lib);
77 -- generate our item node
80 IF format = 'marcxml' THEN
82 IF tmp_xml !~ E'<marc:' THEN -- If we're not using the prefixed namespace in this record, then remove all declarations of it
83 tmp_xml := REGEXP_REPLACE(tmp_xml, ' xmlns:marc="http://www.loc.gov/MARC21/slim"', '', 'g');
86 tmp_xml := oils_xslt_process(me.marc, xfrm.xslt)::XML;
89 top_el := REGEXP_REPLACE(tmp_xml, E'^.*?<((?:\\S+:)?' || layout.holdings_element || ').*$', E'\\1');
91 IF source IS NOT NULL THEN
92 tmp_xml := REGEXP_REPLACE(tmp_xml, '</' || top_el || '>(.*?)$', source || '</' || top_el || E'>\\1');
95 IF axml IS NOT NULL THEN
96 tmp_xml := REGEXP_REPLACE(tmp_xml, '</' || top_el || '>(.*?)$', axml || '</' || top_el || E'>\\1');
99 IF hxml IS NOT NULL THEN -- XXX how do we configure the holdings position?
100 tmp_xml := REGEXP_REPLACE(tmp_xml, '</' || top_el || '>(.*?)$', hxml || '</' || top_el || E'>\\1');
103 IF ('bre.unapi' = ANY (includes)) THEN
104 output := REGEXP_REPLACE(
106 '</' || top_el || '>(.*?)',
110 'http://www.w3.org/1999/xhtml' AS xmlns,
112 'tag:open-ils.org:U2@bre/' || obj_id || '/' || org AS title
114 )::TEXT || '</' || top_el || E'>\\1'
120 IF ('bre.extern' = ANY (includes)) THEN
121 output := REGEXP_REPLACE(
123 '</' || top_el || '>(.*?)',
127 'http://open-ils.org/spec/biblio/v1' AS xmlns,
128 me.creator AS creator,
130 me.create_date AS create_date,
131 me.edit_date AS edit_date,
132 me.quality AS quality,
133 me.fingerprint AS fingerprint,
134 me.tcn_source AS tcn_source,
135 me.tcn_value AS tcn_value,
137 me.share_depth AS share_depth,
139 me.deleted AS deleted
141 )::TEXT || '</' || top_el || E'>\\1'
147 output := REGEXP_REPLACE(output::TEXT,E'>\\s+<','><','gs')::XML;
150 $F$ LANGUAGE PLPGSQL STABLE;