2 # Support multiscript records via alternate graphic 880 fields
3 # get_graphic_880s(target_field='100')
4 # See "Model A" in http://www.loc.gov/marc/bibliographic/ecbdmulti.html
5 # and $6 description in http://www.loc.gov/marc/bibliographic/ecbdcntf.html
6 MACRO get_graphic_880s BLOCK;
7 FOR node IN xml.findnodes('//*[@tag="' _ target_field _ '"]');
10 FOR subnode IN node.findnodes('./*[not(contains("w 0 5 6 8 9", @code))]');
11 raw_vals.push(subnode.textContent());
13 core_val = raw_vals.join(" ");
17 FOR sub IN node.findnodes('./*[@code="6"]');
18 linked_fields.push(sub.textContent);
23 primary => {"occur" => occurrence, "value" => core_val},
29 MACRO get_linked_880s BLOCK;
30 FOR link_field IN linked_fields;
31 target = target_field _ link_field.substr(3);
32 # Get the linked 880 value
37 FOR node IN xml.findnodes('//*[@tag="880"]');
38 # Operate only on the target linked fields
39 FOR linknode IN node.findnodes('./*[@code="6"]');
40 lf = linknode.textContent();
41 IF lf.substr(0, target.length) == target;
42 occurrence = lf.substr(4, 2);
43 rawscript = lf.substr(7, 2);
59 rawdir = lf.substr(9, 1);
66 FOR subnode IN node.findnodes('./*[not(contains("w 0 5 6 8 9", @code))]');
67 raw_vals.push(subnode.textContent());
69 raw_val = raw_vals.join(" ");
82 # Extract MARC fields from XML
83 # get_marc_attrs( { marc_xml => doc } )
87 # Map item types to schema.org types; impedance mismatch :(
88 args.schema.itemtype = {};
90 schema_typemap.a = 'http://schema.org/Book';
91 schema_typemap.e = 'http://schema.org/Map';
92 schema_typemap.j = 'http://schema.org/MusicAlbum';
95 FOR isbn IN xml.findnodes('//*[@tag="020"]/*[@code="a"]');
96 args.isbns.push(isbn.textContent);
100 FOR upc IN xml.findnodes('//*[@tag="024"]/*[@code="a"]');
101 args.upcs.push(upc.textContent);
103 args.upc = args.upcs.0; # use first UPC as the default
106 FOR sub IN xml.findnodes('//*[@tag="022"]/*[@code="a"]');
107 args.issns.push(sub.textContent);
109 args.issn = (args.issns.size) ? args.issn.0 : '';
112 get_graphic_880s(target_field='100');
113 args.graphic_authors = graphic_880s;
115 FOR author IN args.graphic_authors;
116 args.authors.push(author.primary.value);
118 args.author = (args.authors.size) ? args.authors.0 : '';
120 # Include subfields 'abnp' to generate a more comprehensive title display in search results
121 titresults = xml.findnodes('//*[@tag="245"]/*[@code="a" or @code="b" or @code="n" or @code="p"]');
122 titresults_content = [];
123 FOR sub IN titresults; titresults_content.push(sub.textContent); END;
124 args.title = titresults_content.join(" ");
125 # Avoid ugly trailing syntax on brief titles
126 args.title = args.title | replace('[:;/]$', '');
129 get_graphic_880s(target_field='245');
130 args.graphic_titles = graphic_880s;
132 FOR title IN args.graphic_titles;
133 args.titles.push(title.primary.value);
135 args.title_extended = (args.titles.size) ? args.titles.0 : '';
138 pubplace_hunt = xml.findnodes('//*[@tag="260"]/*[@code="a"]') ||
139 xml.findnodes('//*[@tag="264" and @ind2="1"]/*[@code="a"]');
140 FOR sub IN pubplace_hunt;
141 args.pubplaces.push(sub.textContent);
143 args.pubplace = (args.pubplaces.size) ? args.pubplaces.0 : '';
145 args.publishers = [];
146 publishers_hunt = xml.findnodes('//*[@tag="260"]/*[@code="b"]') ||
147 xml.findnodes('//*[@tag="264" and @ind2="1"]/*[@code="b"]');
148 FOR sub IN publishers_hunt;
149 args.publishers.push(sub.textContent);
151 args.publisher = (args.publishers.size) ? args.publishers.0 : '';
154 pubdates_hunt = xml.findnodes('//*[@tag="260"]/*[@code="c"]') ||
155 xml.findnodes('//*[@tag="264" and @ind2="1"]/*[@code="c"]');
156 FOR sub IN pubdates_hunt;
157 args.pubdates.push(sub.textContent);
159 args.pubdate = (args.pubdates.size) ? args.pubdates.0 : '';
161 # Full publisher info
162 args.pubinfo = "$args.pubplace $args.publisher $args.pubdate";
165 get_graphic_880s(target_field='260');
166 args.graphic_pubinfos = graphic_880s;
168 FOR pubinfo IN args.graphic_pubinfos;
169 args.pubinfos.push(pubinfo.primary.value);
171 args.pubinfo = (args.pubinfos.size) ? args.pubinfos.0 : '';
174 FOR sub IN xml.findnodes('//*[@tag="520"]/*[@code="a"]');
175 args.summaries.push(sub.textContent);
177 args.summary = (args.summaries.size) ? args.summaries.0 : '';
179 # 250 gets pride of place for edition statement, and is the
180 # only logical choice for 880 graphic fields
182 get_graphic_880s(target_field='250');
183 args.graphic_editions = graphic_880s;
185 FOR edition IN args.graphic_editions;
186 args.editions.push(edition.primary.value);
189 ed_hunt = xml.findnodes('//*[@tag="250"]/*[@code="a"]') ||
190 xml.findnodes('//*[@tag="534"]/*[@code="b"]') ||
191 xml.findnodes('//*[@tag="775"]/*[@code="b"]');
193 args.editions.push(sub.textContent);
195 args.edition = (args.editions.size) ? args.editions.0 : '';
198 FOR sub IN xml.findnodes(
199 '//*[@tag="300"]/*[@code="a" or @code="b" or @code="c" or @code="e"]'
201 phys_content.push(sub.textContent);
203 args.phys_desc = phys_content.join(" ");
206 get_graphic_880s(target_field='505');
207 args.graphic_contents = graphic_880s;
208 FOR content IN args.graphic_contents;
209 args.contents.push(content.primary.value);
211 args.content = (args.contents.size) ? args.contents.0 : '';
213 # Maintain contents_list in case any custom use was made of it
214 args.contents_list = [];
215 FOR sub IN xml.findnodes('//*[@tag="505"]');
216 args.contents_list.push(sub.textContent);
221 FOR sub IN xml.findnodes('//*[@tag="092" or @tag="099"]/*');
222 args.marc_cns.push(sub.textContent);
224 args.marc_cn = (args.marc_cns.size ) ? args.marc_cns.0 : '';
228 args.isbn_clean = args.isbns.0.replace('\ .*', '');
230 # Extract the 856 URLs that are not otherwise represented by asset.uri's
231 args.online_res = [];
232 FOR node IN xml.findnodes('//*[@tag="856" and @ind1="4" and (@ind2="0" or @ind2="1")]');
233 IF node.findnodes('./*[@code="9" or @code="w" or @code="n"]'); NEXT; END; # asset.uri's
234 label = node.findnodes('./*[@code="y"]');
235 notes = node.findnodes('./*[@code="z" or @code="3"]');
236 FOR href IN node.findnodes('./*[@code="u"]');
238 # it's possible for multiple $u's to exist within 1 856 tag.
239 # in that case, honor the label/notes data for the first $u, but
240 # leave any subsequent $u's as unadorned href's.
241 # use href/link/note keys to be consistent with args.uri's
242 args.online_res.push({
243 href => href.textContent,
244 link => (loop.first AND label) ? label.textContent : href.textContent,
245 note => (loop.first) ? notes.textContent : ''
253 args.resolver_isbns = [];
254 args.resolver_issns = [];
256 # we use $9 of ISBN and ISSN as a flag for e-version
257 FOR resolver_isbn IN xml.findnodes('//*[@tag="020"]/*[@code="9"]');
258 IF resolver_isbn.textContent == "SFX" || resolver_isbn.textContent == "CUFTS";
259 my_parent = resolver_isbn.parentNode();
260 FOR resolver_isbn_val IN my_parent.findnodes('./*[@code="a"]');
261 args.resolver_isbns.push(
262 resolver_isbn_val.textContent.replace('-', '').replace('\ .*', '')
268 FOR resolver_issn IN xml.findnodes('//*[@tag="022"]/*[@code="9"]');
269 IF resolver_issn.textContent == "SFX" || resolver_issn.textContent == "CUFTS";
270 my_parent = resolver_issn.parentNode();
271 FOR resolver_issn_val IN my_parent.findnodes('./*[@code="a"]');
272 args.resolver_issns.push(
273 resolver_issn_val.textContent.replace('[^\d\-X]', '')
280 FOR rawissn IN xml.findnodes('//*[@tag="022"]/*[@code="a"]');
282 rawissn.textContent.replace('[^\d\-X]', '')
286 ou_hiding_disabled = ctx.org_hiding_disabled();
288 FOR volume IN xml.findnodes('//*[local-name()="volumes"]/*[local-name()="volume"]');
290 # Check volume visibility - could push this into XPath
291 vol.label = volume.getAttribute('label');
293 # Prepend prefix, if any
294 prefix = volume.findnodes('./*[local-name()="call_number_prefix"][@ident!="-1"]');
295 IF prefix.getAttribute('label') != '';
296 vol.label = prefix.getAttribute('label') _ " " _ vol.label;
299 # Append prefix, if any
300 suffix = volume.findnodes('./*[local-name()="call_number_suffix"][@ident!="-1"]');
301 IF suffix.getAttribute('label') != '';
302 vol.label = vol.label _ " " _ suffix.getAttribute('label');
305 vol.id = volume.getAttribute('id');
306 NEXT IF volume.getAttribute('opac_visible') == 'false';
307 NEXT IF volume.getAttribute('deleted') == 'true';
309 IF vol.label == '##URI##';
310 FOR uri IN volume.findnodes('./*[local-name()="uris"]/*[local-name()="uri"]');
312 res.href = uri.getAttribute('href');
313 res.link = uri.getAttribute('label');
314 res.note = uri.getAttribute('use_restriction');
319 copies = volume.findnodes('./*[local-name()="copies"]/*[local-name()="copy"]');
321 parts = copy.findnodes('./*[local-name()="monograph_parts"]/*[local-name()="monograph_part"]');
322 FOREACH part IN parts;
323 part_label = part.getAttribute('label');
324 LAST IF part_label != '';
326 # Check copy visibility
327 cp.deleted = copy.getAttribute('deleted');
328 cp.visible = copy.getAttribute('opac_visible');
329 NEXT IF (cp.deleted == 'true' OR cp.visible == 'false');
331 # Iterate through all of the children to determine visibility
332 FOR node IN cp.childNodes;
333 NEXT IF cp.visible == 'false';
334 vis = node.getAttribute('opac_visible');
335 del = node.getAttribute('deleted');
336 IF vis == 'false' or del == 'true';
337 cp.visible = 'false';
341 NEXT IF cp.visible == 'false';
343 loc = copy.findnodes('./*[local-name()="location"]');
344 NEXT IF loc.getAttribute('opac_visible') == 'false';
346 circlib = copy.findnodes('./*[local-name()="circlib"]');
347 NEXT IF circlib.getAttribute('opac_visible') == 'false';
349 status = copy.findnodes('./*[local-name()="status"]');
350 NEXT IF status.getAttribute('opac_visible') == 'false';
352 UNLESS ou_hiding_disabled;
353 # extract the circ_lib id from the circ_lib node
354 circ_lib = copy.findnodes('./*[local-name()="circ_lib"]');
355 circ_lib_id = circ_lib.getAttribute('id').replace('.*/', '');
356 NEXT UNLESS ctx.org_within_hiding_scope(circ_lib_id);
361 part_label => part_label,
362 location => loc.textContent,
363 library => circlib.textContent,
364 status => status.textContent,
365 barcode => copy.getAttribute('barcode'),
366 owner => volume.getAttribute('lib')
368 args.holdings.push(holding);
374 # Extract the copy count summary
375 count_type = (ctx.is_staff) ? 'staff' : 'public';
377 # Consortial copy count summary first
378 xpath = '//*[local-name()="counts"]/*[local-name()="count"][@type="' _ count_type _ '"]';
379 args.copy_counts = {};
380 FOR node IN xml.findnodes(xpath);
381 FOR attr IN ['count', 'available', 'unshadow', 'transcendant', 'org_unit'];
382 depth = node.getAttribute('depth');
383 count_org_unit = node.getAttribute('org_unit');
384 args.copy_counts.$depth.$attr = node.getAttribute(attr);
385 args.org_copy_counts.$count_org_unit.$attr = node.getAttribute(attr);
389 # Get preferred library copy count
390 args.plib_copy_counts = {};
391 count_type = 'pref_lib';
392 xpath = '//*[local-name()="counts"]/*[local-name()="count"][@type="' _ count_type _ '"]';
393 FOR node IN xml.findnodes(xpath);
394 FOR attr IN ['count', 'available', 'unshadow', 'transcendant', 'org_unit'];
395 depth = node.getAttribute('depth');
396 args.plib_copy_counts.$depth.$attr = node.getAttribute(attr);
400 # "mattype" == "custom marc format specifier"
401 FOR icon_style IN ['mattype', 'item_type'];
402 node = xml.findnodes(
403 '//*[local-name()="attributes"]/*[local-name()="field"][@name="' _ icon_style _ '"]');
404 IF node AND node.textContent;
405 type = node.textContent;
406 args.format_label = node.getAttribute('coded-value')
407 args.schema.itemtype = schema_typemap.$type;
408 args.format_icon = ctx.media_prefix _ '/images/format_icons/' _ icon_style _ '/' _ type _ '.png';
415 # Get the library or location group
417 # magically upgrades any use of 'loc' to 'locg',
418 # which is a superset of 'loc'.
421 loc_value = CGI.param(loc_name) || CGI.param('loc') || ctx.search_ou;