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' _ ctx.cache_key;
86 # Extract MARC fields from XML
87 # get_marc_attrs( args = { marc_xml => doc } )
93 FOR bibid IN xml.findnodes('//*[@tag="901"]/*[@code="c"]');
94 args.bibid.push(bibid.textContent);
97 args.df_bib_list = args.bibid;
98 args.bibid = args.bibid.0;
100 IF args.mr_constituent_ids.size && !args.df_bib_list.size;
101 args.df_bib_list = args.mr_constituent_ids;
105 # Gather display field data for this record and map it
106 # to a display field map. Hopefully, one day, this can
107 # replace the XPath below entirely.
109 args.display_fields = {};
111 IF !CGI.param('no_highlight') && !search.no_highlight;
113 junk = ctx.timelog('Fetching of highlighted display fields for bib(s) ' _ args.df_bib_list.list.join(', '));
114 args.display_field_list = ctx.fetch_display_fields(args.df_bib_list.list);
115 junk = ctx.timelog('Finished fetch of highlighted display fields for bib(s) ' _ args.df_bib_list.list.join(', '));
117 junk = ctx.timelog('Mapping highlighted display fields for bib(s) ' _ args.df_bib_list.list.join(', '));
118 FOR df IN args.display_field_list;
119 df_map = ctx.search_cdfm('field', df.field).0;
120 df_name = df_map.name();
121 IF df_map.multi() == 't';
122 IF NOT args.hl_display_fields.$df_name;
123 args.hl_display_fields.$df_name = [];
124 args.hl.$df_name = [];
126 args.hl_display_fields.$df_name.push(df);
127 args.hl.$df_name.push(df.highlight || df.value);
128 ELSIF !args.hl_display_fields.$df_name.defined;
129 args.hl_display_fields.$df_name = df;
130 args.hl.$df_name = df.highlight || df.value;
133 junk = ctx.timelog('Finished mapping highlighted display fields for bib(s) ' _ args.df_bib_list.list.join(', '));
136 # Map item types to schema.org types; impedance mismatch :(
137 args.schema.itemtype = {};
140 schema_typemap.bluray = 'Movie'; # Movie could also be TVSeries
141 schema_typemap.book = 'Book';
142 schema_typemap.braille = 'Book';
143 schema_typemap.casaudiobook = 'Book AudioObject';
144 schema_typemap.casmusic = 'MusicAlbum';
145 schema_typemap.cdaudiobook = 'Book AudioObject';
146 schema_typemap.cdmusic = 'MusicAlbum';
147 schema_typemap.dvd = 'Movie';
148 schema_typemap.eaudio = 'AudioObject';
149 schema_typemap.ebook = 'Book';
150 # schema_typemap.equip = '';
151 schema_typemap.evideo = 'Movie';
152 # schema_typemap.kit = '';
153 schema_typemap.lpbook = 'Book';
154 schema_typemap.map = 'Map';
155 # schema_typemap.microform = '';
156 schema_typemap.music = 'MusicAlbum';
157 schema_typemap.phonomusic = 'MusicAlbum';
158 # schema_typemap.phonospoken = '';
159 # schema_typemap.picture = ''; Painting or Photograph?
160 schema_typemap.score = 'Book'; # schema.org has no generic Music type
161 schema_typemap.serial = 'Periodical';
162 schema_typemap.software = 'SoftwareApplication';
163 schema_typemap.vhs = 'Movie';
165 schema_typemap.a = 'Book';
166 schema_typemap.e = 'Map';
167 schema_typemap.j = 'MusicAlbum';
169 # Hard-coded to match defaults in config.copy_status for all OPAC-visible statuses
170 schema_copy_status = {};
171 schema_copy_status.0 = '<link property="availability" href="http://schema.org/InStock" />'; # Available
172 schema_copy_status.1 = '<link property="availability" href="http://schema.org/OutOfStock" />'; # Checked out
173 schema_copy_status.5 = '<link property="availability" href="http://schema.org/PreOrder" />'; # In process
174 schema_copy_status.6 = '<link property="availability" href="http://schema.org/PreOrder" />'; # In transit
175 schema_copy_status.7 = '<link property="availability" href="http://schema.org/InStock" />'; # Reshelving
176 schema_copy_status.8 = '<link property="availability" href="http://schema.org/OutOfStock" />'; # On holds shelf
177 schema_copy_status.9 = '<link property="availability" href="http://schema.org/PreOrder" />'; # On order
178 schema_copy_status.12 = '<link property="availability" href="http://schema.org/InStoreOnly" />'; # Reserves
181 FOR isbn IN xml.findnodes('//*[@tag="020"]/*[@code="a"]');
182 args.isbns.push(isbn.textContent);
185 # UPCs can be identified either by ind1="1" or subfield 2 of "upc"
187 FOR upc IN xml.findnodes('//*[@tag="024" and @ind="1"]/*[@code="a"]');
188 args.upcs.push(upc.textContent);
190 FOR upcfield IN xml.findnodes('//*[@tag="024"]/*[@code="2" and text()="upc"]');
191 my_parent = upcfield.parentNode();
192 FOR upc IN my_parent.findnodes('./*[@code="a"]');
193 args.upcs.push(upc.textContent);
196 args.upc = args.upcs.0; # use first UPC as the default
198 # These are URIs that link out to related works for linked data purposes,
199 # such as OCLC Work Entities like http://worldcat.org/entity/work/id/415491
201 # We differentiate between http://schema.org/sameAs relations, which
202 # are roughly the same as the work we're describing here, and
203 # http://schema.org/exampleOfWork which point to a broader work, of which
204 # this is a more specific edition or manifestation.
205 args.links.sameAs = [];
206 args.links.exampleOfWork = [];
207 FOR link_node IN xml.findnodes('//*[@tag="024"]/*[@code="2" and text()="uri"]');
208 my_parent = link_node.parentNode();
209 FOR link IN my_parent.findnodes('./*[@code="a"]');
210 link_uri = link.textContent | trim;
211 IF link_uri.search('worldcat.org/entity/work');
212 args.links.exampleOfWork.push(link_uri);
214 args.links.sameAs.push(link_uri);
218 FOR lccn IN xml.findnodes('//*[@tag="010"]/*[@code="a"]');
219 lccn_num = lccn.textContent | trim;
220 args.links.sameAs.push('http://lccn.loc.gov/' _ lccn_num);
222 FOR oclcnum IN xml.findnodes('//*[@tag="035"]/*[@code="a"]');
223 oclcnum = oclcnum.textContent | trim;
224 NEXT UNLESS oclcnum.search('^\(OCoLC\)');
225 oclcnum = oclcnum | remove('\(OCoLC\)');
226 # These prefixes are often included in the 035, even though they should not be
227 oclcnum = oclcnum | remove('ocm');
228 oclcnum = oclcnum | remove('ocn');
229 oclcnum = oclcnum | remove('on') | trim;
230 args.links.sameAs.push('http://www.worldcat.org/oclc/' _ oclcnum);
232 args.links.sameAs = args.links.sameAs.unique;
235 FOR sub IN xml.findnodes('//*[@tag="022"]/*[@code="a"]');
236 args.issns.push(sub.textContent);
238 args.issn = (args.issns.size) ? args.issn.0 : '';
241 get_graphic_880s(target_field='100');
242 get_graphic_880s(target_field='110');
243 get_graphic_880s(target_field='111');
244 args.graphic_authors = graphic_880s;
246 FOR author IN args.graphic_authors;
247 args.authors.push(author.primary.value);
249 args.author = (args.authors.size) ? args.authors.0 : '';
251 # Include subfields 'abnp' to generate a more comprehensive title display in search results
252 titresults = xml.findnodes('//*[@tag="245"]/*[@code="a" or @code="b" or @code="n" or @code="p"]');
253 titresults_content = [];
254 FOR sub IN titresults; titresults_content.push(sub.textContent); END;
256 args.title = titresults_content.join(" ");
257 # Avoid ugly trailing syntax on brief titles
258 args.title = args.title | replace('[:;/]$', '');
261 get_graphic_880s(target_field='245');
262 args.graphic_titles = graphic_880s;
264 FOR title IN args.graphic_titles;
265 args.titles.push(title.primary.value);
267 args.title_extended = (args.titles.size) ? args.titles.0 : '';
269 # Create a version of the title designed for sorted displays.
270 args.sort_title = args.title | upper;
272 # If the title has a "non-filing chaaracters"
273 # (to logically remove leading "The " for example)
274 # chop the title. Otherwise, chop until the first alphanumeric.
275 # BTW: Template Toolkit folds 1-element arrays to scalars!
276 title_node = xml.findnodes('//*[@tag="245"]');
278 args.nonfiling_characters = title_node.findvalue('@ind2');
280 IF (args.nonfiling_characters > 0);
281 args.sort_title = args.sort_title.substr(args.nonfiling_characters);
283 args.sort_title = args.sort_title.replace('^[^A-Z0-9]*','');
287 pubplace_hunt = xml.findnodes('//*[@tag="260"]/*[@code="a"]') ||
288 xml.findnodes('//*[@tag="264" and @ind2="1"]/*[@code="a"]');
289 FOR sub IN pubplace_hunt;
290 args.pubplaces.push(sub.textContent);
292 args.pubplace = (args.pubplaces.size) ? args.pubplaces.0 : '';
294 args.publishers = [];
295 publishers_hunt = xml.findnodes('//*[@tag="260"]/*[@code="b"]') ||
296 xml.findnodes('//*[@tag="264" and @ind2="1"]/*[@code="b"]');
297 FOR sub IN publishers_hunt;
298 args.publishers.push(sub.textContent);
300 args.publisher = (args.publishers.size) ? args.publishers.0 : '';
303 pubdates_hunt = xml.findnodes('//*[@tag="260"]/*[@code="c"]') ||
304 xml.findnodes('//*[@tag="264" and @ind2="1"]/*[@code="c"]');
305 FOR sub IN pubdates_hunt;
306 args.pubdates.push(sub.textContent);
308 args.pubdate = (args.pubdates.size) ? args.pubdates.0 : '';
310 # Get RDA Copyright Info.
311 args.copyrights = [];
312 FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="4"]/*[@code="c"]');
313 args.copyrights.push(sub.textContent);
315 args.copyright = (args.copyrights.size) ? args.copyrights.0 : '';
317 IF args.copyright.length >= 4;
318 args.copyrightYear = args.copyright.match('(\d{4})');
319 IF args.copyrightYear;
320 args.copyrightYear = args.copyrightYear.0;
324 # Get the RDA Production info.
326 FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="0"]/*[@code="b"]');
327 args.producers.push(sub.textContent);
329 args.producer = (args.producers.size) ? args.producers.0 : '';
331 args.prodplaces = [];
332 FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="0"]/*[@code="a"]');
333 args.prodplaces.push(sub.textContent);
335 args.prodplace = (args.prodplaces.size) ? args.prodplaces.0 : '';
338 FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="0"]/*[@code="c"]');
339 args.proddates.push(sub.textContent);
341 args.proddate = (args.proddates.size) ? args.proddates.0 : '';
343 # Get the RDA Distribution args.
344 args.distributors = [];
345 FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="2"]/*[@code="b"]');
346 args.distributors.push(sub.textContent);
348 args.distributor = (args.distributors.size) ? args.distributors.0 : '';
350 args.distplaces = [];
351 FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="2"]/*[@code="a"]');
352 args.distplaces.push(sub.textContent);
354 args.distplace = (args.distplaces.size) ? args.distplaces.0 : '';
357 FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="2"]/*[@code="c"]');
358 args.distdates.push(sub.textContent);
360 args.distdate = (args.distdates.size) ? args.distdates.0 : '';
362 # Get the RDA Manufacture args.
363 args.manufacturers = [];
364 FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="3"]/*[@code="b"]');
365 args.manufacturers.push(sub.textContent);
367 args.manufacturer = (args.manufacturers.size) ? args.manufacturers.0 : '';
370 FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="3"]/*[@code="a"]');
371 args.manplaces.push(sub.textContent);
373 args.manplace = (args.manplaces.size) ? args.manplaces.0 : '';
376 FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="3"]/*[@code="c"]');
377 args.mandates.push(sub.textContent);
379 args.mandate = (args.mandates.size) ? args.mandates.0 : '';
381 # RDA adds 264 to the pubinfo 880 consideration mix
383 get_graphic_880s(target_field='260');
384 get_graphic_880s(target_field='264');
385 args.graphic_pubinfos = graphic_880s;
387 FOR pubinfo IN args.graphic_pubinfos;
388 args.pubinfos.push(pubinfo.primary.value);
390 args.pubinfo = (args.pubinfos.size) ? args.pubinfos.0 : '';
393 FOR sub IN xml.findnodes('//*[@tag="520"]/*[@code="a"]');
394 args.summaries.push(sub.textContent);
396 args.summary = (args.summaries.size) ? args.summaries.0 : '';
398 # 250 gets pride of place for edition statement, and is the
399 # only logical choice for 880 graphic fields
401 get_graphic_880s(target_field='250');
402 args.graphic_editions = graphic_880s;
404 FOR edition IN args.graphic_editions;
405 args.editions.push(edition.primary.value);
408 ed_hunt = xml.findnodes('//*[@tag="250"]/*[@code="a"]');
410 args.editions.push(sub.textContent);
412 args.edition = (args.editions.size) ? args.editions.0 : '';
415 FOR sub IN xml.findnodes(
416 '//*[@tag="300"]/*[@code="a" or @code="b" or @code="c" or @code="e"]'
418 phys_content.push(sub.textContent);
420 args.phys_desc = phys_content.join(" ");
423 get_graphic_880s(target_field='505');
424 args.graphic_contents = graphic_880s;
425 FOR content IN args.graphic_contents;
426 args.contents.push(content.primary.value);
428 args.content = (args.contents.size) ? args.contents.0 : '';
430 # Maintain contents_list in case any custom use was made of it
431 args.contents_list = [];
432 FOR sub IN xml.findnodes('//*[@tag="505"]');
433 args.contents_list.push(sub.textContent);
438 FOR sub IN xml.findnodes('//*[@tag="092" or @tag="099"]/*');
439 args.marc_cns.push(sub.textContent);
441 args.marc_cn = (args.marc_cns.size ) ? args.marc_cns.0 : '';
445 args.isbn_clean = args.isbns.0.replace('\ .*', '');
446 FOR isbn IN args.isbns;
447 clean_isbn = isbn.replace('\ .*', '');
448 clean_isbn = clean_isbn.replace('-', '');
449 IF clean_isbn.length == 13;
450 args.gtin13 = clean_isbn;
455 IF ebook_api.overdrive.enabled == 'true';
456 FOR marc037 IN xml.findnodes('//*[@tag="037"]');
457 marc037_id = marc037.findnodes('./*[@code="a"]').textContent;
458 marc037_source = marc037.findnodes('./*[@code="b"]').textContent;
459 IF marc037_source.match('OverDrive') AND marc037_id;
460 args.overdrive_id = marc037_id;
466 # Extract the 856 URLs that are not otherwise represented by asset.uri's
467 args.online_res = [];
468 FOR node IN xml.findnodes('//*[@tag="856" and @ind1="4" and (@ind2="0" or @ind2="1")]');
469 IF node.findnodes('./*[@code="9" or @code="w" or @code="n"]'); NEXT; END; # asset.uri's
470 label = node.findnodes('./*[@code="y"]');
471 notes = node.findnodes('./*[@code="z" or @code="3"]');
472 FOR href IN node.findnodes('./*[@code="u"]');
474 # it's possible for multiple $u's to exist within 1 856 tag.
475 # in that case, honor the label/notes data for the first $u, but
476 # leave any subsequent $u's as unadorned href's.
477 # use href/link/note keys to be consistent with args.uri's
478 args.online_res.push({
479 href => href.textContent,
480 link => (loop.first AND label) ? label.textContent : href.textContent,
481 note => (loop.first) ? notes.textContent : ''
489 args.resolver_isbns = [];
490 args.resolver_issns = [];
492 # we use $9 of ISBN and ISSN as a flag for e-version
493 FOR resolver_isbn IN xml.findnodes('//*[@tag="020"]/*[@code="9"]');
494 IF resolver_isbn.textContent == "SFX" || resolver_isbn.textContent == "CUFTS";
495 my_parent = resolver_isbn.parentNode();
496 FOR resolver_isbn_val IN my_parent.findnodes('./*[@code="a"]');
497 args.resolver_isbns.push(
498 resolver_isbn_val.textContent.replace('-', '').replace('\ .*', '')
504 FOR resolver_issn IN xml.findnodes('//*[@tag="022"]/*[@code="9"]');
505 IF resolver_issn.textContent == "SFX" || resolver_issn.textContent == "CUFTS";
506 my_parent = resolver_issn.parentNode();
507 FOR resolver_issn_val IN my_parent.findnodes('./*[@code="a"]');
508 args.resolver_issns.push(
509 resolver_issn_val.textContent.replace('[^\d\-X]', '')
516 FOR rawissn IN xml.findnodes('//*[@tag="022"]/*[@code="a"]');
518 rawissn.textContent.replace('[^\d\-X]', '')
522 ou_hiding_disabled = ctx.org_hiding_disabled();
524 # explicitly grabbing the first bib_source node, though there should be only one anyway
525 bib_source = xml.findnodes('//*[local-name()="bib_source"][1]');
526 args.bib_source.id = bib_source.getAttribute('ident');
527 args.bib_source.source = bib_source.textContent;
529 FOR volume IN xml.findnodes('//*[local-name()="volumes"]/*[local-name()="volume"]');
531 # Check volume visibility - could push this into XPath
532 vol.label = volume.getAttribute('label');
534 # Prepend prefix, if any
535 prefix = volume.findnodes('./*[local-name()="call_number_prefix"][@ident!="-1"]');
536 IF prefix.getAttribute('label') != '';
537 vol.label = prefix.getAttribute('label') _ " " _ vol.label;
540 # Append prefix, if any
541 suffix = volume.findnodes('./*[local-name()="call_number_suffix"][@ident!="-1"]');
542 IF suffix.getAttribute('label') != '';
543 vol.label = vol.label _ " " _ suffix.getAttribute('label');
546 vol.id = volume.getAttribute('id');
547 NEXT IF volume.getAttribute('opac_visible') == 'false';
548 NEXT IF volume.getAttribute('deleted') == 'true';
550 IF vol.label == '##URI##';
551 FOR uri IN volume.findnodes('./*[local-name()="uris"]/*[local-name()="uri"]');
553 res.href = uri.getAttribute('href');
554 res.link = uri.getAttribute('label');
555 res.note = uri.getAttribute('use_restriction');
556 # Avoid displaying the href as the link text if we can display the note instead
557 IF res.link == res.href AND res.note;
563 IF ebook_api.ebook_test.enabled == 'true';
564 IF !args.ebook_test_id;
565 FOR base_uri IN ebook_api.ebook_test.base_uris;
566 IF res.href.match(base_uri);
567 args.ebook_test_id = res.href.remove(base_uri);
574 IF ebook_api.oneclickdigital.enabled == 'true';
575 # A record might conceivably have multiple OneClickdigital URIs,
576 # but we use (the same) ISBN as the ebook ID in each case.
577 IF !args.oneclickdigital_id;
578 FOR base_uri IN ebook_api.oneclickdigital.base_uris;
579 IF res.href.match(base_uri);
580 # found a OneClickdigital URI, let's grab our ID and move on
581 args.oneclickdigital_id = clean_isbn;
588 IF ebook_api.overdrive.enabled == 'true';
589 # Ideally we already have an OverDrive record ID from MARC 037 (see above).
590 # But for older records, it will be embedded in the URI in MARC 856.
591 IF !args.overdrive_id;
592 FOR base_uri IN ebook_api.overdrive.base_uris;
593 IF res.href.match(base_uri);
594 args.overdrive_id = res.href.remove('^.*/ContentDetails.htm\?ID=');
604 copies = volume.findnodes('./*[local-name()="copies"]/*[local-name()="copy"]');
606 parts = copy.findnodes('./*[local-name()="monograph_parts"]/*[local-name()="monograph_part"]');
608 FOREACH part IN parts;
609 part_label = part.getAttribute('label');
610 LAST IF part_label != '';
612 # Check copy visibility
613 cp.deleted = copy.getAttribute('deleted');
614 cp.visible = copy.getAttribute('opac_visible');
615 NEXT IF (cp.deleted == 'true' OR cp.visible == 'false');
617 # Iterate through all of the children to determine visibility
618 FOR node IN cp.childNodes;
619 NEXT IF cp.visible == 'false';
620 vis = node.getAttribute('opac_visible');
621 del = node.getAttribute('deleted');
622 IF vis == 'false' or del == 'true';
623 cp.visible = 'false';
627 NEXT IF cp.visible == 'false';
629 loc = copy.findnodes('./*[local-name()="location"]');
630 NEXT IF loc.getAttribute('opac_visible') == 'false';
632 circlib = copy.findnodes('./*[local-name()="circlib"]');
633 NEXT IF circlib.getAttribute('opac_visible') == 'false';
635 status = copy.findnodes('./*[local-name()="status"]');
636 NEXT IF status.getAttribute('opac_visible') == 'false';
638 # extract the circ_lib id from the circ_lib node
639 circ_lib = copy.findnodes('./*[local-name()="circ_lib"]');
640 circ_lib_id = circ_lib.getAttribute('id').replace('.*/', '');
642 UNLESS ou_hiding_disabled;
643 NEXT UNLESS ctx.org_within_hiding_scope(circ_lib_id);
647 circ_lib => circ_lib_id,
649 part_label => part_label,
650 location => loc.textContent,
651 library => circlib.textContent,
652 status => status.textContent,
653 status_code => status.getAttribute('ident'),
654 barcode => copy.getAttribute('barcode'),
655 owner => volume.getAttribute('lib')
657 args.holdings.push(holding);
663 # Extract the copy count summary
664 count_type = (ctx.is_staff) ? 'staff' : 'public';
666 # Consortial copy count summary first
667 xpath = '//*[local-name()="counts"]/*[local-name()="count"][@type="' _ count_type _ '"]';
668 args.copy_counts = {};
669 FOR node IN xml.findnodes(xpath);
670 FOR attr IN ['count', 'available', 'unshadow', 'transcendant', 'org_unit'];
671 depth = node.getAttribute('depth');
672 count_org_unit = node.getAttribute('org_unit');
673 args.copy_counts.$depth.$attr = node.getAttribute(attr);
674 args.org_copy_counts.$count_org_unit.$attr = node.getAttribute(attr);
678 # Get preferred library copy count
679 args.plib_copy_counts = {};
680 count_type = 'pref_lib';
681 xpath = '//*[local-name()="counts"]/*[local-name()="count"][@type="' _ count_type _ '"]';
682 FOR node IN xml.findnodes(xpath);
683 FOR attr IN ['count', 'available', 'unshadow', 'transcendant', 'org_unit'];
684 depth = node.getAttribute('depth');
685 args.plib_copy_counts.$depth.$attr = node.getAttribute(attr);
690 # "mattype" == "custom marc format specifier"
691 icon_style = ctx.get_cgf('opac.icon_attr').value || 'item_type';
692 formats_xpath = '//*[local-name()="attributes"]/*[local-name()="field"][@name="' _ icon_style _ '"]';
694 args.all_formats = [];
695 FOR node IN xml.findnodes(formats_xpath);
696 IF node AND node.textContent;
697 ccvm = ctx.get_ccvm(node.getAttribute('cvmid'));
698 NEXT IF ccvm.opac_visible == 'f';
701 this_icon_source = node.getAttribute('source_list');
703 # Just display everything if we don't have the data
704 IF NOT args.mr_constituent_ids OR NOT this_icon_source;
706 # We have an array of search-included bib IDs and we have the bib ID that this icon belongs to
708 FOR mr_constituent_id IN args.mr_constituent_ids;
709 IF this_icon_source.split(',').grep('^' _ mr_constituent_id _ '$' ).size;
710 # This bib appears to be in the array of filtered bibs
716 type = ccvm.code.remove('-'); # blu-ray to bluray
717 format.label = ccvm.search_label || ccvm.value;
718 format.icon = PROCESS get_ccvm_icon ccvm=ccvm;
719 format.itemtype = schema_typemap.$type || 'CreativeWork';
720 format.search_format = ccvm.code;
721 format.source_bibs = this_icon_source.split(',');
722 FOR bib_source IN format.source_bibs;
723 IF NOT mmr_unique_bib.grep(bib_source).size; mmr_unique_bib.push(bib_source); END;
725 args.all_formats.push(format); # metarecords want all formats
727 IF !args.format_label;
728 # use the first format as the default
729 args.format_label = format.label;
730 args.schema.itemtype = format.itemtype;
731 args.format_icon = format.icon;
737 formats_xpath = '//*[local-name()="attributes"]/*[local-name()="field"][@name="item_lang"]';
739 FOR node IN xml.findnodes(formats_xpath);
740 IF node AND node.textContent;
741 ccvm = ctx.get_ccvm(node.getAttribute('cvmid'));
742 NEXT IF ccvm.opac_visible == 'f';
745 this_source = node.getAttribute('source_list');
747 # Just display everything if we don't have the data
748 IF NOT args.mr_constituent_ids OR NOT this_source;
750 # We have an array of search-included bib IDs and we have the bib ID that this lang belongs to
752 FOR mr_constituent_id IN args.mr_constituent_ids;
753 IF this_source.split(',').grep('^' _ mr_constituent_id _ '$' ).size;
754 # This bib appears to be in the array of filtered bibs
760 lang.label = ccvm.search_label || ccvm.value;
761 lang.itemtype = schema_typemap.$type || 'CreativeWork';
762 lang.search_format = node.textContent;
763 lang.source_bibs = this_source.split(',');
764 FOR bib_source IN lang.source_bibs;
765 IF NOT mmr_unique_bib.grep(bib_source).size; mmr_unique_bib.push(bib_source); END;
768 args.all_lang.push(lang); # metarecords want all
772 args.mmr_unique_bib = mmr_unique_bib;
774 IF args.ebook_test_id;
775 args.ebook.ebook_id = args.ebook_test_id;
776 args.ebook.vendor = 'ebook_test';
777 ELSIF args.oneclickdigital_id;
778 args.ebook.ebook_id = args.oneclickdigital_id;
779 args.ebook.vendor = 'oneclickdigital';
780 ELSIF args.overdrive_id;
781 args.ebook.ebook_id = args.overdrive_id;
782 args.ebook.vendor = 'overdrive';
787 # Get the library or location group
789 # magically upgrades any use of 'loc' to 'locg',
790 # which is a superset of 'loc'.
794 # Location groups don't have shortnames, so they'll take priority
795 # (_org doesn't contain the group and breaks the selector).
796 loc_value = ctx.copy_location_group ? CGI.param(loc_name)
797 : ctx.copy_location_group_org # resolved locg
798 || CGI.param(loc_name) || CGI.param('loc') || ctx.search_ou;