]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/templates/opac/parts/misc_util.tt2
lp1427331: Remove relator information from author links
[Evergreen.git] / Open-ILS / src / templates / opac / parts / misc_util.tt2
1 [% 
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 _ '"]');
8             raw_vals = [];
9             core_val = '';
10             FOR subnode IN node.findnodes('./*[not(contains("e w 0 4 5 6 7 8 9", @code))]');
11                 raw_vals.push(subnode.textContent());
12             END;
13             core_val = raw_vals.join(" ");
14             raw_vals = [];
15
16             linked_fields = [];
17             FOR sub IN node.findnodes('./*[@code="6"]');
18                 linked_fields.push(sub.textContent);
19             END;
20             graphics = [];
21             get_linked_880s;
22             graphic_880s.push({
23                 primary => {"occur" => occurrence, "value" => core_val},
24                 graphic => graphics
25             });
26         END;
27     END;
28
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
33             raw_val = '';
34             dir = '';
35             occurrence = '';
36             script = '';
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);
44                         SWITCH rawscript;
45                         CASE '(3';
46                             script = 'Arabic';
47                         CASE '(B';
48                             script = 'Latin';
49                         CASE '$1';
50                             script = 'CJK';
51                         CASE '(N';
52                             script = 'Cyrillic';
53                         CASE '(S';
54                             script = 'Greek';
55                         CASE '(2';
56                             script = 'Hebrew';
57                         END;
58
59                         rawdir = lf.substr(9, 1);
60                         SWITCH rawdir;
61                         CASE 'r';
62                             dir = 'rtl';
63                         END;
64
65                         raw_vals = [];
66                         FOR subnode IN node.findnodes('./*[not(contains("w 0 5 6 8 9", @code))]');
67                             raw_vals.push(subnode.textContent());
68                         END;
69                         raw_val = raw_vals.join(" ");
70                     END;
71                 END;
72             END;
73             graphics.push({
74                 occur => occurrence,
75                 value => raw_val,
76                 script => script,
77                 dir => dir
78             });
79         END;
80     END;
81
82     BLOCK get_ccvm_icon;
83         ctx.media_prefix _ '/images/format_icons/' _ ccvm.ctype _ '/' _ ccvm.code _ '.png';
84     END;
85
86     # Extract MARC fields from XML
87     #   get_marc_attrs( { marc_xml => doc } )
88     BLOCK get_marc_attrs;
89         xml = args.marc_xml;
90
91         # Map item types to schema.org types; impedance mismatch :(
92         args.schema.itemtype = {};
93         schema_typemap = {};
94
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';
119
120         schema_typemap.a = 'Book';
121         schema_typemap.e = 'Map';
122         schema_typemap.j = 'MusicAlbum';
123
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
134
135         args.isbns = [];
136         FOR isbn IN xml.findnodes('//*[@tag="020"]/*[@code="a"]');
137             args.isbns.push(isbn.textContent);
138         END;
139
140         # UPCs can be identified either by ind1="1" or subfield 2 of "upc"
141         args.upcs = [];
142         FOR upc IN xml.findnodes('//*[@tag="024" and @ind="1"]/*[@code="a"]');
143             args.upcs.push(upc.textContent);
144         END;
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);
149             END;
150         END;
151         args.upc = args.upcs.0; # use first UPC as the default
152
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
155
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);
168                 ELSE;
169                     args.links.sameAs.push(link_uri);
170                 END;
171             END;
172         END;
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);
176         END;
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);
186         END;
187         args.links.sameAs = args.links.sameAs.unique;
188
189         args.issns = [];
190         FOR sub IN xml.findnodes('//*[@tag="022"]/*[@code="a"]');
191             args.issns.push(sub.textContent);
192         END;
193         args.issn = (args.issns.size) ? args.issn.0 : '';
194
195         graphic_880s = [];
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;
200         args.authors = [];
201         FOR author IN args.graphic_authors;
202             args.authors.push(author.primary.value);
203         END;
204         args.author = (args.authors.size) ? args.authors.0 : '';
205
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;
210         args.title = titresults_content.join(" ");
211         # Avoid ugly trailing syntax on brief titles
212         args.title = args.title | replace('[:;/]$', '');
213
214         graphic_880s = [];
215         get_graphic_880s(target_field='245');
216         args.graphic_titles = graphic_880s;
217         args.titles = [];
218         FOR title IN args.graphic_titles;
219             args.titles.push(title.primary.value);
220         END;
221         args.title_extended = (args.titles.size) ? args.titles.0 : '';
222
223         args.pubplaces = [];
224         pubplace_hunt = xml.findnodes('//*[@tag="260"]/*[@code="a"]') ||
225             xml.findnodes('//*[@tag="264" and @ind2="1"]/*[@code="a"]');
226         FOR sub IN pubplace_hunt;
227             args.pubplaces.push(sub.textContent);
228         END;
229         args.pubplace = (args.pubplaces.size) ? args.pubplaces.0 : '';
230
231         args.publishers = [];
232         publishers_hunt = xml.findnodes('//*[@tag="260"]/*[@code="b"]') ||
233             xml.findnodes('//*[@tag="264" and @ind2="1"]/*[@code="b"]');
234         FOR sub IN publishers_hunt;
235             args.publishers.push(sub.textContent);
236         END;
237         args.publisher = (args.publishers.size) ? args.publishers.0 : '';
238
239         args.pubdates = [];
240         pubdates_hunt = xml.findnodes('//*[@tag="260"]/*[@code="c"]') || 
241             xml.findnodes('//*[@tag="264" and @ind2="1"]/*[@code="c"]');
242         FOR sub IN pubdates_hunt;
243             args.pubdates.push(sub.textContent);
244         END;
245         args.pubdate = (args.pubdates.size) ? args.pubdates.0 : '';
246
247         # Get RDA Copyright Info.
248         args.copyrights = [];
249         FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="4"]/*[@code="c"]');
250             args.copyrights.push(sub.textContent);
251         END;
252         args.copyright = (args.copyrights.size) ? args.copyrights.0 : '';
253
254         IF args.copyright.length >= 4;
255             args.copyrightYear = args.copyright.match('(\d{4})');
256             IF args.copyrightYear;
257                 args.copyrightYear = args.copyrightYear.0;
258             END;
259         END;
260
261         # Get the RDA Production info.
262         args.producers = [];
263         FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="0"]/*[@code="b"]');
264             args.producers.push(sub.textContent);
265         END;
266         args.producer = (args.producers.size) ? args.producers.0 : '';
267
268         args.prodplaces = [];
269         FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="0"]/*[@code="a"]');
270             args.prodplaces.push(sub.textContent);
271         END;
272         args.prodplace = (args.prodplaces.size) ? args.prodplaces.0 : '';
273
274         args.proddates = [];
275         FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="0"]/*[@code="c"]');
276             args.proddates.push(sub.textContent);
277         END;
278         args.proddate = (args.proddates.size) ? args.proddates.0 : '';
279
280         # Get the RDA Distribution args.
281         args.distributors = [];
282         FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="2"]/*[@code="b"]');
283             args.distributors.push(sub.textContent);
284         END;
285         args.distributor = (args.distributors.size) ? args.distributors.0 : '';
286
287         args.distplaces = [];
288         FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="2"]/*[@code="a"]');
289             args.distplaces.push(sub.textContent);
290         END;
291         args.distplace = (args.distplaces.size) ? args.distplaces.0 : '';
292
293         args.distdates = [];
294         FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="2"]/*[@code="c"]');
295             args.distdates.push(sub.textContent);
296         END;
297         args.distdate = (args.distdates.size) ? args.distdates.0 : '';
298
299         # Get the RDA Manufacture args.
300         args.manufacturers = [];
301         FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="3"]/*[@code="b"]');
302             args.manufacturers.push(sub.textContent);
303         END;
304         args.manufacturer = (args.manufacturers.size) ? args.manufacturers.0 : '';
305
306         args.manplaces = [];
307         FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="3"]/*[@code="a"]');
308             args.manplaces.push(sub.textContent);
309         END;
310         args.manplace = (args.manplaces.size) ? args.manplaces.0 : '';
311
312         args.mandates = [];
313         FOR sub IN xml.findnodes('//*[@tag="264" and @ind2="3"]/*[@code="c"]');
314             args.mandates.push(sub.textContent);
315         END;
316         args.mandate = (args.mandates.size) ? args.mandates.0 : '';
317
318         # RDA adds 264 to the pubinfo 880 consideration mix
319         graphic_880s = [];
320         get_graphic_880s(target_field='260');
321         get_graphic_880s(target_field='264');
322         args.graphic_pubinfos = graphic_880s;
323         args.pubinfos = [];
324         FOR pubinfo IN args.graphic_pubinfos;
325             args.pubinfos.push(pubinfo.primary.value);
326         END;
327         args.pubinfo = (args.pubinfos.size) ? args.pubinfos.0 : '';
328
329         args.summaries = [];
330         FOR sub IN xml.findnodes('//*[@tag="520"]/*[@code="a"]');
331             args.summaries.push(sub.textContent);
332         END;
333         args.summary = (args.summaries.size) ? args.summaries.0 : '';
334
335         # 250 gets pride of place for edition statement, and is the
336         # only logical choice for 880 graphic fields
337         graphic_880s = [];
338         get_graphic_880s(target_field='250');
339         args.graphic_editions = graphic_880s;
340         args.editions = [];
341         FOR edition IN args.graphic_editions;
342             args.editions.push(edition.primary.value);
343         END;
344
345         ed_hunt = xml.findnodes('//*[@tag="250"]/*[@code="a"]') ||
346             xml.findnodes('//*[@tag="534"]/*[@code="b"]') ||
347             xml.findnodes('//*[@tag="775"]/*[@code="b"]');
348         FOR sub IN ed_hunt;
349             args.editions.push(sub.textContent);
350         END;
351         args.edition = (args.editions.size) ? args.editions.0 : '';
352
353         phys_content = [];
354         FOR sub IN xml.findnodes(
355             '//*[@tag="300"]/*[@code="a" or @code="b" or @code="c" or @code="e"]'
356         );
357             phys_content.push(sub.textContent);
358         END;
359         args.phys_desc = phys_content.join(" ");
360
361         graphic_880s = [];
362         get_graphic_880s(target_field='505');
363         args.graphic_contents = graphic_880s;
364         FOR content IN args.graphic_contents;
365             args.contents.push(content.primary.value);
366         END;
367         args.content = (args.contents.size) ? args.contents.0 : '';
368
369         # Maintain contents_list in case any custom use was made of it
370         args.contents_list = [];
371         FOR sub IN xml.findnodes('//*[@tag="505"]');
372             args.contents_list.push(sub.textContent);
373         END;
374
375         # MARC Callnumber
376         args.marc_cns = [];
377         FOR sub IN xml.findnodes('//*[@tag="092" or @tag="099"]/*');
378             args.marc_cns.push(sub.textContent);
379         END;
380         args.marc_cn = (args.marc_cns.size ) ? args.marc_cns.0 : '';
381             
382
383         # clean up the ISBN
384         args.isbn_clean = args.isbns.0.replace('\ .*', '');
385         FOR isbn IN args.isbns;
386             clean_isbn = isbn.replace('\ .*', '');
387             clean_isbn = clean_isbn.replace('-', '');
388             IF clean_isbn.length == 13;
389                 args.gtin13 = clean_isbn;
390                 LAST;
391             END;
392         END;
393
394         # Extract the 856 URLs that are not otherwise represented by asset.uri's
395         args.online_res = [];
396         FOR node IN xml.findnodes('//*[@tag="856" and @ind1="4" and (@ind2="0" or @ind2="1")]');
397             IF node.findnodes('./*[@code="9" or @code="w" or @code="n"]'); NEXT; END; # asset.uri's
398             label = node.findnodes('./*[@code="y"]');
399             notes = node.findnodes('./*[@code="z" or @code="3"]');
400             FOR href IN node.findnodes('./*[@code="u"]');
401                 NEXT UNLESS href;
402                 # it's possible for multiple $u's to exist within 1 856 tag.
403                 # in that case, honor the label/notes data for the first $u, but
404                 # leave any subsequent $u's as unadorned href's. 
405                 # use href/link/note keys to be consistent with args.uri's
406                 args.online_res.push({
407                     href => href.textContent, 
408                     link => (loop.first AND label) ? label.textContent : href.textContent,
409                     note => (loop.first) ? notes.textContent : ''
410                 });
411             END;
412         END;
413  
414         args.holdings = [];
415         args.uris = [];
416         args.issns = [];
417         args.resolver_isbns = [];
418         args.resolver_issns = [];
419
420         # we use $9 of ISBN and ISSN as a flag for e-version
421         FOR resolver_isbn IN xml.findnodes('//*[@tag="020"]/*[@code="9"]');
422             IF resolver_isbn.textContent == "SFX" || resolver_isbn.textContent == "CUFTS";
423                 my_parent = resolver_isbn.parentNode();
424                 FOR resolver_isbn_val IN my_parent.findnodes('./*[@code="a"]');
425                     args.resolver_isbns.push(
426                         resolver_isbn_val.textContent.replace('-', '').replace('\ .*', '')
427                     );
428                 END;
429             END;
430         END;
431
432         FOR resolver_issn IN xml.findnodes('//*[@tag="022"]/*[@code="9"]');
433             IF resolver_issn.textContent == "SFX" || resolver_issn.textContent == "CUFTS";
434                 my_parent = resolver_issn.parentNode();
435                 FOR resolver_issn_val IN my_parent.findnodes('./*[@code="a"]');
436                     args.resolver_issns.push(
437                         resolver_issn_val.textContent.replace('[^\d\-X]', '')
438                     );
439                 END;
440             END;
441         END;
442
443         # now snag all issns 
444         FOR rawissn IN xml.findnodes('//*[@tag="022"]/*[@code="a"]');
445             args.issns.push(
446                 rawissn.textContent.replace('[^\d\-X]', '')
447             );
448         END;
449
450         ou_hiding_disabled = ctx.org_hiding_disabled();
451
452         FOR volume IN xml.findnodes('//*[local-name()="volumes"]/*[local-name()="volume"]');
453
454             # Check volume visibility - could push this into XPath
455             vol.label = volume.getAttribute('label');
456
457             # Prepend prefix, if any
458             prefix = volume.findnodes('./*[local-name()="call_number_prefix"][@ident!="-1"]');
459             IF prefix.getAttribute('label') != '';
460                 vol.label = prefix.getAttribute('label') _ " " _ vol.label;
461             END;
462
463             # Append prefix, if any
464             suffix = volume.findnodes('./*[local-name()="call_number_suffix"][@ident!="-1"]');
465             IF suffix.getAttribute('label') != '';
466                 vol.label = vol.label _ " " _ suffix.getAttribute('label');
467             END;
468
469             vol.id = volume.getAttribute('id');
470             NEXT IF volume.getAttribute('opac_visible') == 'false';
471             NEXT IF volume.getAttribute('deleted') == 'true';
472
473             IF vol.label == '##URI##';
474                 FOR uri IN volume.findnodes('./*[local-name()="uris"]/*[local-name()="uri"]');
475                     res = {};
476                     res.href = uri.getAttribute('href');
477                     res.link = uri.getAttribute('label');
478                     res.note = uri.getAttribute('use_restriction');
479                     # Avoid displaying the href as the link text if we can display the note instead
480                     IF res.link == res.href AND res.note;
481                         res.link = res.note;
482                         res.note = '';
483                     END;
484                     args.uris.push(res);
485                 END;
486                 NEXT;
487             ELSE;
488                 copies = volume.findnodes('./*[local-name()="copies"]/*[local-name()="copy"]');
489                 FOR copy IN copies;
490                     parts = copy.findnodes('./*[local-name()="monograph_parts"]/*[local-name()="monograph_part"]');
491                     FOREACH part IN parts;
492                         part_label = part.getAttribute('label');
493                         LAST IF part_label != '';
494                     END;
495                     # Check copy visibility
496                     cp.deleted = copy.getAttribute('deleted');    
497                     cp.visible = copy.getAttribute('opac_visible');
498                     NEXT IF (cp.deleted == 'true' OR cp.visible == 'false');
499
500                     # Iterate through all of the children to determine visibility
501                     FOR node IN cp.childNodes;
502                         NEXT IF cp.visible == 'false';
503                         vis = node.getAttribute('opac_visible');
504                         del = node.getAttribute('deleted');
505                         IF vis == 'false' or del == 'true';
506                             cp.visible = 'false';
507                         END;
508                     END;
509
510                     NEXT IF cp.visible == 'false';
511                     
512                     loc = copy.findnodes('./*[local-name()="location"]');
513                     NEXT IF loc.getAttribute('opac_visible') == 'false';
514
515                     circlib = copy.findnodes('./*[local-name()="circlib"]');
516                     NEXT IF circlib.getAttribute('opac_visible') == 'false';
517
518                     status = copy.findnodes('./*[local-name()="status"]');
519                     NEXT IF status.getAttribute('opac_visible') == 'false';
520
521                     # extract the circ_lib id from the circ_lib node
522                     circ_lib = copy.findnodes('./*[local-name()="circ_lib"]');
523                     circ_lib_id = circ_lib.getAttribute('id').replace('.*/', '');
524
525                     UNLESS ou_hiding_disabled;
526                         NEXT UNLESS ctx.org_within_hiding_scope(circ_lib_id);
527                     END;
528
529                     holding = {
530                         circ_lib => circ_lib_id,
531                         label => vol.label,
532                         part_label => part_label,
533                         location => loc.textContent,
534                         library => circlib.textContent,
535                         status => status.textContent,
536                         status_code => status.getAttribute('ident'),
537                         barcode => copy.getAttribute('barcode'),
538                         owner => volume.getAttribute('lib')
539                     };
540                     args.holdings.push(holding);
541                     part_label = '';
542                 END;
543             END;
544         END;
545
546         # Extract the copy count summary
547         count_type = (ctx.is_staff) ? 'staff' : 'public';
548
549         # Consortial copy count summary first
550         xpath = '//*[local-name()="counts"]/*[local-name()="count"][@type="' _ count_type _ '"]';
551         args.copy_counts = {};
552         FOR node IN xml.findnodes(xpath);
553             FOR attr IN ['count', 'available', 'unshadow', 'transcendant', 'org_unit']; 
554                 depth = node.getAttribute('depth');
555                 count_org_unit = node.getAttribute('org_unit');
556                 args.copy_counts.$depth.$attr = node.getAttribute(attr);
557                 args.org_copy_counts.$count_org_unit.$attr = node.getAttribute(attr);
558             END;
559         END;
560
561         # Get preferred library copy count
562         args.plib_copy_counts = {};
563         count_type = 'pref_lib';
564         xpath = '//*[local-name()="counts"]/*[local-name()="count"][@type="' _ count_type _ '"]';
565         FOR node IN xml.findnodes(xpath);
566             FOR attr IN ['count', 'available', 'unshadow', 'transcendant', 'org_unit']; 
567                 depth = node.getAttribute('depth');
568                 args.plib_copy_counts.$depth.$attr = node.getAttribute(attr);
569             END;
570         END;
571
572         # "mattype" == "custom marc format specifier"
573         icon_style = ctx.get_cgf('opac.icon_attr').value || 'item_type';
574         formats_xpath = '//*[local-name()="attributes"]/*[local-name()="field"][@name="' _ icon_style _ '"]';
575
576         args.all_formats = [];
577         FOR node IN xml.findnodes(formats_xpath);
578             IF node AND node.textContent;
579                 ccvm = ctx.get_ccvm(node.getAttribute('cvmid'));
580                 NEXT IF ccvm.opac_visible == 'f';
581
582                 format = {};
583                 type = ccvm.code.remove('-'); # blu-ray to bluray
584                 format.label = ccvm.search_label || ccvm.value;
585                 format.icon = PROCESS get_ccvm_icon ccvm=ccvm;
586                 format.itemtype = schema_typemap.$type || 'CreativeWork';
587
588                 args.all_formats.push(format); # metarecords want all formats
589
590                 IF !args.format_label;
591                     # use the first format as the default
592                     args.format_label = format.label; 
593                     args.schema.itemtype = format.itemtype;
594                     args.format_icon = format.icon;
595                 END;
596             END;
597         END;
598         
599         args.bibid = [];
600         FOR bibid IN xml.findnodes('//*[@tag="901"]/*[@code="c"]');
601             args.bibid.push(bibid.textContent);
602         END;
603         args.bibid = args.bibid.0; 
604
605     END;
606
607     # Get the library or location group
608     # get_library()
609     # magically upgrades any use of 'loc' to 'locg', 
610     # which is a superset of 'loc'.
611     BLOCK get_library;
612         loc_name = 'locg';
613         loc_value = ctx.copy_location_group_org ||  # resolved locg
614             CGI.param(loc_name) || CGI.param('loc') || ctx.search_ou;
615     END;
616
617 %]