2 # Extract MARC fields from XML
3 # get_marc_attrs( { marc_xml => doc } )
7 FOR isbn IN xml.findnodes('//*[@tag="020"]/*[@code="a"]');
8 args.isbns.push(isbn.textContent);
11 FOR upc IN xml.findnodes('//*[@tag="024"]/*[@code="a"]');
12 args.upcs.push(upc.textContent);
14 args.upc = args.upcs.0; # use first UPC as the default
15 args.issn = xml.findnodes('//*[@tag="022"]/*[@code="a"]').textContent;
16 args.title = xml.findnodes('//*[@tag="245"]/*[@code="a"]').textContent;
17 args.title_extended = xml.findnodes('//*[@tag="245"]').textContent;
18 args.author = xml.findnodes('//*[@tag="100"]/*[@code="a"]').textContent;
19 args.publisher = xml.findnodes('//*[@tag="260"]/*[@code="b"]').textContent;
20 args.pubdate = xml.findnodes('//*[@tag="260"]/*[@code="c"]').textContent;
21 args.summary = xml.findnodes('//*[@tag="520"]/*[@code="a"]').textContent;
22 args.edition = xml.findnodes('//*[@tag="250"]/*[@code="a"]').textContent ||
23 xml.findnodes('//*[@tag="534"]/*[@code="b"]').textContent ||
24 xml.findnodes('//*[@tag="775"]/*[@code="b"]').textContent;
26 '//*[@tag="300"]/*[@code="a" or @code="b" or @code="c" or @code="e"]'
29 FOR p IN phys; phys_content.push(p.textContent); END;
30 args.phys_desc = phys_content.join("");
32 args.contents = xml.findnodes('//*[@tag="505"]').textContent;
35 args.marc_cn = xml.findnodes('//*[@tag="092" or @tag="099"]/*').textContent;
38 args.isbn_clean = args.isbns.0.replace('\ .*', '');
40 # Extract the 856 URLs that are not otherwise represented by asset.uri's
42 FOR node IN xml.findnodes('//*[@tag="856" and @ind1="4" and (@ind2="0" or @ind2="1")]');
43 IF node.findnodes('./*[@code="9" or @code="w" or @code="n"]'); NEXT; END; # asset.uri's
44 label = node.findnodes('./*[@code="y"]');
45 notes = node.findnodes('./*[@code="z" or @code="3"]');
46 FOR href IN node.findnodes('./*[@code="u"]');
48 # it's possible for multiple $u's to exist within 1 856 tag.
49 # in that case, honor the label/notes data for the first $u, but
50 # leave any subsequent $u's as unadorned href's.
51 # use href/link/note keys to be consistent with args.uri's
52 args.online_res.push({
53 href => href.textContent,
54 link => (loop.first AND label) ? label.textContent : href.textContent,
55 note => (loop.first) ? notes.textContent : ''
63 args.resolver_isbns = [];
64 args.resolver_issns = [];
66 # we use $9 of ISBN and ISSN as a flag for e-version
67 FOR resolver_isbn IN xml.findnodes('//*[@tag="020"]/*[@code="9"]');
68 IF resolver_isbn.textContent == "SFX" || resolver_isbn.textContent == "CUFTS";
69 my_parent = resolver_isbn.parentNode();
70 FOR resolver_isbn_val IN my_parent.findnodes('./*[@code="a"]');
71 args.resolver_isbns.push(
72 resolver_isbn_val.textContent.replace('-', '').replace('\ .*', '')
78 FOR resolver_issn IN xml.findnodes('//*[@tag="022"]/*[@code="9"]');
79 IF resolver_issn.textContent == "SFX" || resolver_issn.textContent == "CUFTS";
80 my_parent = resolver_issn.parentNode();
81 FOR resolver_issn_val IN my_parent.findnodes('./*[@code="a"]');
82 args.resolver_issns.push(
83 resolver_issn_val.textContent.replace('[^\d\-X]', '')
90 FOR rawissn IN xml.findnodes('//*[@tag="022"]/*[@code="a"]');
92 rawissn.textContent.replace('[^\d\-X]', '')
96 FOR volume IN xml.findnodes('//*[local-name()="volumes"]/*[local-name()="volume"]');
98 # Check volume visibility - could push this into XPath
99 vol.label = volume.getAttribute('label');
101 # Prepend prefix, if any
102 prefix = volume.findnodes('./*[local-name()="call_number_prefix"][@ident!="-1"]');
103 IF prefix.getAttribute('label') != '';
104 vol.label = prefix.getAttribute('label') _ " " _ vol.label;
107 # Append prefix, if any
108 suffix = volume.findnodes('./*[local-name()="call_number_suffix"][@ident!="-1"]');
109 IF suffix.getAttribute('label') != '';
110 vol.label = vol.label _ " " _ suffix.getAttribute('label');
113 vol.id = volume.getAttribute('id');
114 NEXT IF volume.getAttribute('opac_visible') == 'false';
115 NEXT IF volume.getAttribute('deleted') == 'true';
117 IF vol.label == '##URI##';
118 FOR uri IN volume.findnodes('./*[local-name()="uris"]/*[local-name()="uri"]');
119 res.href = uri.getAttribute('href');
120 res.link = uri.getAttribute('label');
121 res.note = uri.getAttribute('use_restriction');
126 copies = volume.findnodes('./*[local-name()="copies"]/*[local-name()="copy"]');
128 parts = copy.findnodes('./*[local-name()="monograph_parts"]/*[local-name()="monograph_part"]');
129 FOREACH part IN parts;
130 part_label = part.getAttribute('label');
131 LAST IF part_label != '';
133 # Check copy visibility
134 cp.deleted = copy.getAttribute('deleted');
135 cp.visible = copy.getAttribute('opac_visible');
136 NEXT IF (cp.deleted == 'true' OR cp.visible == 'false');
138 # Iterate through all of the children to determine visibility
139 FOR node IN cp.childNodes;
140 NEXT IF cp.visible == 'false';
141 vis = node.getAttribute('opac_visible');
142 del = node.getAttribute('deleted');
143 IF vis == 'false' or del == 'true';
144 cp.visible = 'false';
148 NEXT IF cp.visible == 'false';
150 loc = copy.findnodes('./*[local-name()="location"]');
151 circlib = copy.findnodes('./*[local-name()="circlib"]');
152 status = copy.findnodes('./*[local-name()="status"]');
156 part_label => part_label,
157 location => loc.textContent,
158 library => circlib.textContent,
159 status => status.textContent
160 barcode => copy.getAttribute('barcode')
162 args.holdings.push(holding);
168 # Extract the copy count summary
169 count_type = (ctx.is_staff) ? 'staff' : 'public';
171 # Consortial copy count summary first
172 xpath = '//*[local-name()="counts"]/*[local-name()="count"][@type="' _ count_type _ '"]';
173 args.copy_counts = {};
174 FOR node IN xml.findnodes(xpath);
175 FOR attr IN ['count', 'available', 'unshadow', 'transcendant', 'org_unit'];
176 depth = node.getAttribute('depth');
177 args.copy_counts.$depth.$attr = node.getAttribute(attr);
181 # "mattype" == "custom marc format specifier"
182 FOR icon_style IN ['mattype', 'item_type'];
183 node = xml.findnodes(
184 '//*[local-name()="attributes"]/*[local-name()="field"][@name="' _ icon_style _ '"]');
185 IF node AND node.textContent;
186 args.format_label = node.getAttribute('coded-value')
187 args.format_icon = ctx.media_prefix _ '/images/format_icons/' _ icon_style _ '/' _ node.textContent _ '.png';