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("e w 0 4 5 6 7 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(" ");
83 ctx.media_prefix _ '/images/format_icons/' _ ccvm.ctype _ '/' _ ccvm.code _ '.png';
86 # Extract MARC fields from XML
87 # get_marc_attrs( { marc_xml => doc } )
91 # Map item types to schema.org types; impedance mismatch :(
92 args.schema.itemtype = {};
95 schema_typemap.bluray = 'Movie'; # Movie could also be TVSeries
96 schema_typemap.book = 'Book';
97 schema_typemap.braille = 'Book';
98 schema_typemap.casaudiobook = 'Book AudioObject';
99 schema_typemap.casmusic = 'MusicAlbum';
100 schema_typemap.cdaudiobook = 'Book AudioObject';
101 schema_typemap.cdmusic = 'MusicAlbum';
102 schema_typemap.dvd = 'Movie';
103 schema_typemap.eaudio = 'AudioObject';
104 schema_typemap.ebook = 'Book';
105 # schema_typemap.equip = '';
106 schema_typemap.evideo = 'Movie';
107 # schema_typemap.kit = '';
108 schema_typemap.lpbook = 'Book';
109 schema_typemap.map = 'Map';
110 # schema_typemap.microform = '';
111 schema_typemap.music = 'MusicAlbum';
112 schema_typemap.phonomusic = 'MusicAlbum';
113 # schema_typemap.phonospoken = '';
114 # schema_typemap.picture = ''; Painting or Photograph?
115 schema_typemap.score = 'Book'; # schema.org has no generic Music type
116 schema_typemap.serial = 'Periodical';
117 schema_typemap.software = 'SoftwareApplication';
118 schema_typemap.vhs = 'Movie';
120 schema_typemap.a = 'Book';
121 schema_typemap.e = 'Map';
122 schema_typemap.j = 'MusicAlbum';
124 # Hard-coded to match defaults in config.copy_status for all OPAC-visible statuses
125 schema_copy_status = {};
126 schema_copy_status.0 = '<link property="availability" href="http://schema.org/InStock" />'; # Available
127 schema_copy_status.1 = '<link property="availability" href="http://schema.org/OutOfStock" />'; # Checked out
128 schema_copy_status.5 = '<link property="availability" href="http://schema.org/PreOrder" />'; # In process
129 schema_copy_status.6 = '<link property="availability" href="http://schema.org/PreOrder" />'; # In transit
130 schema_copy_status.7 = '<link property="availability" href="http://schema.org/InStock" />'; # Reshelving
131 schema_copy_status.8 = '<link property="availability" href="http://schema.org/OutOfStock" />'; # On holds shelf
132 schema_copy_status.9 = '<link property="availability" href="http://schema.org/PreOrder" />'; # On order
133 schema_copy_status.12 = '<link property="availability" href="http://schema.org/InStoreOnly" />'; # Reserves
136 FOR isbn IN xml.findnodes('//*[@tag="020"]/*[@code="a"]');
137 args.isbns.push(isbn.textContent);
140 # UPCs can be identified either by ind1="1" or subfield 2 of "upc"
142 FOR upc IN xml.findnodes('//*[@tag="024" and @ind="1"]/*[@code="a"]');
143 args.upcs.push(upc.textContent);
145 FOR upcfield IN xml.findnodes('//*[@tag="024"]/*[@code="2" and text()="upc"]');
146 my_parent = upcfield.parentNode();
147 FOR upc IN my_parent.findnodes('./*[@code="a"]');
148 args.upcs.push(upc.textContent);
151 args.upc = args.upcs.0; # use first UPC as the default
153 # These are URIs that link out to related works for linked data purposes,
154 # such as OCLC Work Entities like http://worldcat.org/entity/work/id/415491
156 # We differentiate between http://schema.org/sameAs relations, which
157 # are roughly the same as the work we're describing here, and
158 # http://schema.org/exampleOfWork which point to a broader work, of which
159 # this is a more specific edition or manifestation.
160 args.links.sameAs = [];
161 args.links.exampleOfWork = [];
162 FOR link_node IN xml.findnodes('//*[@tag="024"]/*[@code="2" and text()="uri"]');
163 my_parent = link_node.parentNode();
164 FOR link IN my_parent.findnodes('./*[@code="a"]');
165 link_uri = link.textContent | trim;
166 IF link_uri.search('worldcat.org/entity/work');
167 args.links.exampleOfWork.push(link_uri);
169 args.links.sameAs.push(link_uri);
173 FOR lccn IN xml.findnodes('//*[@tag="010"]/*[@code="a"]');
174 lccn_num = lccn.textContent | trim;
175 args.links.sameAs.push('http://lccn.loc.gov/' _ lccn_num);
177 FOR oclcnum IN xml.findnodes('//*[@tag="035"]/*[@code="a"]');
178 oclcnum = oclcnum.textContent | trim;
179 NEXT UNLESS oclcnum.search('^\(OCoLC\)');
180 oclcnum = oclcnum | remove('\(OCoLC\)');
181 # These prefixes are often included in the 035, even though they should not be
182 oclcnum = oclcnum | remove('ocm');
183 oclcnum = oclcnum | remove('ocn');
184 oclcnum = oclcnum | remove('on') | trim;
185 args.links.sameAs.push('http://www.worldcat.org/oclc/' _ oclcnum);
187 args.links.sameAs = args.links.sameAs.unique;
190 FOR sub IN xml.findnodes('//*[@tag="022"]/*[@code="a"]');
191 args.issns.push(sub.textContent);
193 args.issn = (args.issns.size) ? args.issn.0 : '';
196 get_graphic_880s(target_field='100');
197 get_graphic_880s(target_field='110');
198 get_graphic_880s(target_field='111');
199 args.graphic_authors = graphic_880s;
201 FOR author IN args.graphic_authors;
202 args.authors.push(author.primary.value);
204 args.author = (args.authors.size) ? args.authors.0 : '';
206 # Include subfields 'abnp' to generate a more comprehensive title display in search results
207 titresults = xml.findnodes('//*[@tag="245"]/*[@code="a" or @code="b" or @code="n" or @code="p"]');
208 titresults_content = [];
209 FOR sub IN titresults; titresults_content.push(sub.textContent); END;
211 args.title = titresults_content.join(" ");
212 # Avoid ugly trailing syntax on brief titles
213 args.title = args.title | replace('[:;/]$', '');
216 get_graphic_880s(target_field='245');
217 args.graphic_titles = graphic_880s;
219 FOR title IN args.graphic_titles;
220 args.titles.push(title.primary.value);
222 args.title_extended = (args.titles.size) ? args.titles.0 : '';
224 # Create a version of the title designed for sorted displays.
225 args.sort_title = args.title | upper;
227 # If the title has a "non-filing chaaracters"
228 # (to logically remove leading "The " for example)
229 # chop the title. Otherwise, chop until the first alphanumeric.
230 # BTW: Template Toolkit folds 1-element arrays to scalars!
231 title_node = xml.findnodes('//*[@tag="245"]');
233 args.nonfiling_characters = title_node.findvalue('@ind2');
235 IF (args.nonfiling_characters > 0);
236 args.sort_title = args.sort_title.substr(args.nonfiling_characters);
238 args.sort_title = args.sort_title.replace('^[^A-Z0-9]*','');
242 pubplace_hunt = xml.findnodes('//*[@tag="260"]/*[@code="a"]') ||
243 xml.findnodes('//*[@tag="264" and @ind2="1"]/*[@code="a"]');
244 FOR sub IN pubplace_hunt;
245 args.pubplaces.push(sub.textContent);
247 args.pubplace = (args.pubplaces.size) ? args.pubplaces.0 : '';
249 args.publishers = [];
250 publishers_hunt = xml.findnodes('//*[@tag="260"]/*[@code="b"]') ||
251 xml.findnodes('//*[@tag="264" and @ind2="1"]/*[@code="b"]');
252 FOR sub IN publishers_hunt;
253 args.publishers.push(sub.textContent);
255 args.publisher = (args.publishers.size) ? args.publishers.0 : '';
258 pubdates_hunt = xml.findnodes('//*[@tag="260"]/*[@code="c"]') ||
259 xml.findnodes('//*[@tag="264" and @ind2="1"]/*[@code="c"]');
260 FOR sub IN pubdates_hunt;
261 args.pubdates.push(sub.textContent);
263 args.pubdate = (args.pubdates.size) ? args.pubdates.0 : '';
265 # Get RDA Copyright Info.
266 args.copyrights = [];
267 FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="4"]/*[@code="c"]');
268 args.copyrights.push(sub.textContent);
270 args.copyright = (args.copyrights.size) ? args.copyrights.0 : '';
272 IF args.copyright.length >= 4;
273 args.copyrightYear = args.copyright.match('(\d{4})');
274 IF args.copyrightYear;
275 args.copyrightYear = args.copyrightYear.0;
279 # Get the RDA Production info.
281 FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="0"]/*[@code="b"]');
282 args.producers.push(sub.textContent);
284 args.producer = (args.producers.size) ? args.producers.0 : '';
286 args.prodplaces = [];
287 FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="0"]/*[@code="a"]');
288 args.prodplaces.push(sub.textContent);
290 args.prodplace = (args.prodplaces.size) ? args.prodplaces.0 : '';
293 FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="0"]/*[@code="c"]');
294 args.proddates.push(sub.textContent);
296 args.proddate = (args.proddates.size) ? args.proddates.0 : '';
298 # Get the RDA Distribution args.
299 args.distributors = [];
300 FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="2"]/*[@code="b"]');
301 args.distributors.push(sub.textContent);
303 args.distributor = (args.distributors.size) ? args.distributors.0 : '';
305 args.distplaces = [];
306 FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="2"]/*[@code="a"]');
307 args.distplaces.push(sub.textContent);
309 args.distplace = (args.distplaces.size) ? args.distplaces.0 : '';
312 FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="2"]/*[@code="c"]');
313 args.distdates.push(sub.textContent);
315 args.distdate = (args.distdates.size) ? args.distdates.0 : '';
317 # Get the RDA Manufacture args.
318 args.manufacturers = [];
319 FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="3"]/*[@code="b"]');
320 args.manufacturers.push(sub.textContent);
322 args.manufacturer = (args.manufacturers.size) ? args.manufacturers.0 : '';
325 FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="3"]/*[@code="a"]');
326 args.manplaces.push(sub.textContent);
328 args.manplace = (args.manplaces.size) ? args.manplaces.0 : '';
331 FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="3"]/*[@code="c"]');
332 args.mandates.push(sub.textContent);
334 args.mandate = (args.mandates.size) ? args.mandates.0 : '';
336 # RDA adds 264 to the pubinfo 880 consideration mix
338 get_graphic_880s(target_field='260');
339 get_graphic_880s(target_field='264');
340 args.graphic_pubinfos = graphic_880s;
342 FOR pubinfo IN args.graphic_pubinfos;
343 args.pubinfos.push(pubinfo.primary.value);
345 args.pubinfo = (args.pubinfos.size) ? args.pubinfos.0 : '';
348 FOR sub IN xml.findnodes('//*[@tag="520"]/*[@code="a"]');
349 args.summaries.push(sub.textContent);
351 args.summary = (args.summaries.size) ? args.summaries.0 : '';
353 # 250 gets pride of place for edition statement, and is the
354 # only logical choice for 880 graphic fields
356 get_graphic_880s(target_field='250');
357 args.graphic_editions = graphic_880s;
359 FOR edition IN args.graphic_editions;
360 args.editions.push(edition.primary.value);
363 ed_hunt = xml.findnodes('//*[@tag="250"]/*[@code="a"]');
365 args.editions.push(sub.textContent);
367 args.edition = (args.editions.size) ? args.editions.0 : '';
370 FOR sub IN xml.findnodes(
371 '//*[@tag="300"]/*[@code="a" or @code="b" or @code="c" or @code="e"]'
373 phys_content.push(sub.textContent);
375 args.phys_desc = phys_content.join(" ");
378 get_graphic_880s(target_field='505');
379 args.graphic_contents = graphic_880s;
380 FOR content IN args.graphic_contents;
381 args.contents.push(content.primary.value);
383 args.content = (args.contents.size) ? args.contents.0 : '';
385 # Maintain contents_list in case any custom use was made of it
386 args.contents_list = [];
387 FOR sub IN xml.findnodes('//*[@tag="505"]');
388 args.contents_list.push(sub.textContent);
393 FOR sub IN xml.findnodes('//*[@tag="092" or @tag="099"]/*');
394 args.marc_cns.push(sub.textContent);
396 args.marc_cn = (args.marc_cns.size ) ? args.marc_cns.0 : '';
400 args.isbn_clean = args.isbns.0.replace('\ .*', '');
401 FOR isbn IN args.isbns;
402 clean_isbn = isbn.replace('\ .*', '');
403 clean_isbn = clean_isbn.replace('-', '');
404 IF clean_isbn.length == 13;
405 args.gtin13 = clean_isbn;
410 IF ebook_api.overdrive.enabled == 'true';
411 FOR marc037 IN xml.findnodes('//*[@tag="037"]');
412 marc037_id = marc037.findnodes('./*[@code="a"]').textContent;
413 marc037_source = marc037.findnodes('./*[@code="b"]').textContent;
414 IF marc037_source.match('OverDrive') AND marc037_id;
415 args.overdrive_id = marc037_id;
421 # Extract the 856 URLs that are not otherwise represented by asset.uri's
422 args.online_res = [];
423 FOR node IN xml.findnodes('//*[@tag="856" and @ind1="4" and (@ind2="0" or @ind2="1")]');
424 IF node.findnodes('./*[@code="9" or @code="w" or @code="n"]'); NEXT; END; # asset.uri's
425 label = node.findnodes('./*[@code="y"]');
426 notes = node.findnodes('./*[@code="z" or @code="3"]');
427 FOR href IN node.findnodes('./*[@code="u"]');
429 # it's possible for multiple $u's to exist within 1 856 tag.
430 # in that case, honor the label/notes data for the first $u, but
431 # leave any subsequent $u's as unadorned href's.
432 # use href/link/note keys to be consistent with args.uri's
433 args.online_res.push({
434 href => href.textContent,
435 link => (loop.first AND label) ? label.textContent : href.textContent,
436 note => (loop.first) ? notes.textContent : ''
444 args.resolver_isbns = [];
445 args.resolver_issns = [];
447 # we use $9 of ISBN and ISSN as a flag for e-version
448 FOR resolver_isbn IN xml.findnodes('//*[@tag="020"]/*[@code="9"]');
449 IF resolver_isbn.textContent == "SFX" || resolver_isbn.textContent == "CUFTS";
450 my_parent = resolver_isbn.parentNode();
451 FOR resolver_isbn_val IN my_parent.findnodes('./*[@code="a"]');
452 args.resolver_isbns.push(
453 resolver_isbn_val.textContent.replace('-', '').replace('\ .*', '')
459 FOR resolver_issn IN xml.findnodes('//*[@tag="022"]/*[@code="9"]');
460 IF resolver_issn.textContent == "SFX" || resolver_issn.textContent == "CUFTS";
461 my_parent = resolver_issn.parentNode();
462 FOR resolver_issn_val IN my_parent.findnodes('./*[@code="a"]');
463 args.resolver_issns.push(
464 resolver_issn_val.textContent.replace('[^\d\-X]', '')
471 FOR rawissn IN xml.findnodes('//*[@tag="022"]/*[@code="a"]');
473 rawissn.textContent.replace('[^\d\-X]', '')
477 ou_hiding_disabled = ctx.org_hiding_disabled();
479 # explicitly grabbing the first bib_source node, though there should be only one anyway
480 bib_source = xml.findnodes('//*[local-name()="bib_source"][1]');
481 args.bib_source.id = bib_source.getAttribute('ident');
482 args.bib_source.source = bib_source.textContent;
484 FOR volume IN xml.findnodes('//*[local-name()="volumes"]/*[local-name()="volume"]');
486 # Check volume visibility - could push this into XPath
487 vol.label = volume.getAttribute('label');
489 # Prepend prefix, if any
490 prefix = volume.findnodes('./*[local-name()="call_number_prefix"][@ident!="-1"]');
491 IF prefix.getAttribute('label') != '';
492 vol.label = prefix.getAttribute('label') _ " " _ vol.label;
495 # Append prefix, if any
496 suffix = volume.findnodes('./*[local-name()="call_number_suffix"][@ident!="-1"]');
497 IF suffix.getAttribute('label') != '';
498 vol.label = vol.label _ " " _ suffix.getAttribute('label');
501 vol.id = volume.getAttribute('id');
502 NEXT IF volume.getAttribute('opac_visible') == 'false';
503 NEXT IF volume.getAttribute('deleted') == 'true';
505 IF vol.label == '##URI##';
506 FOR uri IN volume.findnodes('./*[local-name()="uris"]/*[local-name()="uri"]');
508 res.href = uri.getAttribute('href');
509 res.link = uri.getAttribute('label');
510 res.note = uri.getAttribute('use_restriction');
511 # Avoid displaying the href as the link text if we can display the note instead
512 IF res.link == res.href AND res.note;
518 IF ebook_api.ebook_test.enabled == 'true';
519 IF !args.ebook_test_id;
520 FOR base_uri IN ebook_api.ebook_test.base_uris;
521 IF res.href.match(base_uri);
522 args.ebook_test_id = res.href.remove(base_uri);
529 IF ebook_api.oneclickdigital.enabled == 'true';
530 # A record might conceivably have multiple OneClickdigital URIs,
531 # but we use (the same) ISBN as the ebook ID in each case.
532 IF !args.oneclickdigital_id;
533 FOR base_uri IN ebook_api.oneclickdigital.base_uris;
534 IF res.href.match(base_uri);
535 # found a OneClickdigital URI, let's grab our ID and move on
536 args.oneclickdigital_id = clean_isbn;
543 IF ebook_api.overdrive.enabled == 'true';
544 # Ideally we already have an OverDrive record ID from MARC 037 (see above).
545 # But for older records, it will be embedded in the URI in MARC 856.
546 IF !args.overdrive_id;
547 FOR base_uri IN ebook_api.overdrive.base_uris;
548 IF res.href.match(base_uri);
549 args.overdrive_id = res.href.remove('^.*/ContentDetails.htm\?ID=');
559 copies = volume.findnodes('./*[local-name()="copies"]/*[local-name()="copy"]');
561 parts = copy.findnodes('./*[local-name()="monograph_parts"]/*[local-name()="monograph_part"]');
563 FOREACH part IN parts;
564 part_label = part.getAttribute('label');
565 LAST IF part_label != '';
567 # Check copy visibility
568 cp.deleted = copy.getAttribute('deleted');
569 cp.visible = copy.getAttribute('opac_visible');
570 NEXT IF (cp.deleted == 'true' OR cp.visible == 'false');
572 # Iterate through all of the children to determine visibility
573 FOR node IN cp.childNodes;
574 NEXT IF cp.visible == 'false';
575 vis = node.getAttribute('opac_visible');
576 del = node.getAttribute('deleted');
577 IF vis == 'false' or del == 'true';
578 cp.visible = 'false';
582 NEXT IF cp.visible == 'false';
584 loc = copy.findnodes('./*[local-name()="location"]');
585 NEXT IF loc.getAttribute('opac_visible') == 'false';
587 circlib = copy.findnodes('./*[local-name()="circlib"]');
588 NEXT IF circlib.getAttribute('opac_visible') == 'false';
590 status = copy.findnodes('./*[local-name()="status"]');
591 NEXT IF status.getAttribute('opac_visible') == 'false';
593 # extract the circ_lib id from the circ_lib node
594 circ_lib = copy.findnodes('./*[local-name()="circ_lib"]');
595 circ_lib_id = circ_lib.getAttribute('id').replace('.*/', '');
597 UNLESS ou_hiding_disabled;
598 NEXT UNLESS ctx.org_within_hiding_scope(circ_lib_id);
602 circ_lib => circ_lib_id,
604 part_label => part_label,
605 location => loc.textContent,
606 library => circlib.textContent,
607 status => status.textContent,
608 status_code => status.getAttribute('ident'),
609 barcode => copy.getAttribute('barcode'),
610 owner => volume.getAttribute('lib')
612 args.holdings.push(holding);
618 # Extract the copy count summary
619 count_type = (ctx.is_staff) ? 'staff' : 'public';
621 # Consortial copy count summary first
622 xpath = '//*[local-name()="counts"]/*[local-name()="count"][@type="' _ count_type _ '"]';
623 args.copy_counts = {};
624 FOR node IN xml.findnodes(xpath);
625 FOR attr IN ['count', 'available', 'unshadow', 'transcendant', 'org_unit'];
626 depth = node.getAttribute('depth');
627 count_org_unit = node.getAttribute('org_unit');
628 args.copy_counts.$depth.$attr = node.getAttribute(attr);
629 args.org_copy_counts.$count_org_unit.$attr = node.getAttribute(attr);
633 # Get preferred library copy count
634 args.plib_copy_counts = {};
635 count_type = 'pref_lib';
636 xpath = '//*[local-name()="counts"]/*[local-name()="count"][@type="' _ count_type _ '"]';
637 FOR node IN xml.findnodes(xpath);
638 FOR attr IN ['count', 'available', 'unshadow', 'transcendant', 'org_unit'];
639 depth = node.getAttribute('depth');
640 args.plib_copy_counts.$depth.$attr = node.getAttribute(attr);
645 # "mattype" == "custom marc format specifier"
646 icon_style = ctx.get_cgf('opac.icon_attr').value || 'item_type';
647 formats_xpath = '//*[local-name()="attributes"]/*[local-name()="field"][@name="' _ icon_style _ '"]';
649 args.all_formats = [];
650 FOR node IN xml.findnodes(formats_xpath);
651 IF node AND node.textContent;
652 ccvm = ctx.get_ccvm(node.getAttribute('cvmid'));
653 NEXT IF ccvm.opac_visible == 'f';
656 this_icon_source = node.getAttribute('source_list');
658 # Just display everything if we don't have the data
659 IF NOT args.mr_constituent_ids OR NOT this_icon_source;
661 # We have an array of search-included bib IDs and we have the bib ID that this icon belongs to
663 FOR mr_constituent_id IN args.mr_constituent_ids;
664 IF this_icon_source.split(',').grep('^' _ mr_constituent_id _ '$' ).size;
665 # This bib appears to be in the array of filtered bibs
671 type = ccvm.code.remove('-'); # blu-ray to bluray
672 format.label = ccvm.search_label || ccvm.value;
673 format.icon = PROCESS get_ccvm_icon ccvm=ccvm;
674 format.itemtype = schema_typemap.$type || 'CreativeWork';
675 format.search_format = ccvm.code;
676 format.source_bibs = this_icon_source.split(',');
677 FOR bib_source IN format.source_bibs;
678 IF NOT mmr_unique_bib.grep(bib_source).size; mmr_unique_bib.push(bib_source); END;
680 args.all_formats.push(format); # metarecords want all formats
682 IF !args.format_label;
683 # use the first format as the default
684 args.format_label = format.label;
685 args.schema.itemtype = format.itemtype;
686 args.format_icon = format.icon;
692 formats_xpath = '//*[local-name()="attributes"]/*[local-name()="field"][@name="item_lang"]';
694 FOR node IN xml.findnodes(formats_xpath);
695 IF node AND node.textContent;
696 ccvm = ctx.get_ccvm(node.getAttribute('cvmid'));
697 NEXT IF ccvm.opac_visible == 'f';
700 this_source = node.getAttribute('source_list');
702 # Just display everything if we don't have the data
703 IF NOT args.mr_constituent_ids OR NOT this_source;
705 # We have an array of search-included bib IDs and we have the bib ID that this lang belongs to
707 FOR mr_constituent_id IN args.mr_constituent_ids;
708 IF this_source.split(',').grep('^' _ mr_constituent_id _ '$' ).size;
709 # This bib appears to be in the array of filtered bibs
715 lang.label = ccvm.search_label || ccvm.value;
716 lang.itemtype = schema_typemap.$type || 'CreativeWork';
717 lang.search_format = node.textContent;
718 lang.source_bibs = this_source.split(',');
719 FOR bib_source IN lang.source_bibs;
720 IF NOT mmr_unique_bib.grep(bib_source).size; mmr_unique_bib.push(bib_source); END;
723 args.all_lang.push(lang); # metarecords want all
727 args.mmr_unique_bib = mmr_unique_bib;
730 FOR bibid IN xml.findnodes('//*[@tag="901"]/*[@code="c"]');
731 args.bibid.push(bibid.textContent);
733 args.bibid = args.bibid.0;
737 # Get the library or location group
739 # magically upgrades any use of 'loc' to 'locg',
740 # which is a superset of 'loc'.
744 # Location groups don't have shortnames, so they'll take priority
745 # (_org doesn't contain the group and breaks the selector).
746 loc_value = ctx.copy_location_group ? CGI.param(loc_name)
747 : ctx.copy_location_group_org # resolved locg
748 || CGI.param(loc_name) || CGI.param('loc') || ctx.search_ou;