ba30e46e15d4ec6d2595cf07c6b2fd76e9d3f674
[working/Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / YYYY.schema.bib-auth-browse.sql
1 BEGIN;
2
3 -- check whether patch can be applied
4 -- SELECT evergreen.upgrade_deps_block_check('YYYY', :eg_version);
5
6 ALTER TABLE metabib.browse_entry_def_map
7     ADD COLUMN authority BIGINT REFERENCES authority.record_entry (id)
8         ON DELETE SET NULL;
9
10 ALTER TABLE config.metabib_field ADD COLUMN authority_xpath TEXT;
11
12 UPDATE config.metabib_field
13     SET authority_xpath = '//@xlink:href'
14     WHERE
15         format = 'mods32' AND
16         field_class IN ('subject','series','title','author') AND
17         browse_field IS TRUE;
18
19 ALTER TYPE metabib.field_entry_template ADD ATTRIBUTE authority BIGINT;
20
21
22 CREATE OR REPLACE FUNCTION metabib.reingest_metabib_field_entries( bib_id BIGINT, skip_facet BOOL DEFAULT FALSE, skip_browse BOOL DEFAULT FALSE, skip_search BOOL DEFAULT FALSE ) RETURNS VOID AS $func$
23 DECLARE
24     fclass          RECORD;
25     ind_data        metabib.field_entry_template%ROWTYPE;
26     mbe_row         metabib.browse_entry%ROWTYPE;
27     mbe_id          BIGINT;
28     b_skip_facet    BOOL;
29     b_skip_browse   BOOL;
30     b_skip_search   BOOL;
31 BEGIN
32
33     SELECT COALESCE(NULLIF(skip_facet, FALSE), EXISTS (SELECT enabled FROM config.internal_flag WHERE name =  'ingest.skip_facet_indexing' AND enabled)) INTO b_skip_facet;
34     SELECT COALESCE(NULLIF(skip_browse, FALSE), EXISTS (SELECT enabled FROM config.internal_flag WHERE name =  'ingest.skip_browse_indexing' AND enabled)) INTO b_skip_browse;
35     SELECT COALESCE(NULLIF(skip_search, FALSE), EXISTS (SELECT enabled FROM config.internal_flag WHERE name =  'ingest.skip_search_indexing' AND enabled)) INTO b_skip_search;
36
37     PERFORM * FROM config.internal_flag WHERE name = 'ingest.assume_inserts_only' AND enabled;
38     IF NOT FOUND THEN
39         IF NOT b_skip_search THEN
40             FOR fclass IN SELECT * FROM config.metabib_class LOOP
41                 -- RAISE NOTICE 'Emptying out %', fclass.name;
42                 EXECUTE $$DELETE FROM metabib.$$ || fclass.name || $$_field_entry WHERE source = $$ || bib_id;
43             END LOOP;
44         END IF;
45         IF NOT b_skip_facet THEN
46             DELETE FROM metabib.facet_entry WHERE source = bib_id;
47         END IF;
48         IF NOT b_skip_browse THEN
49             DELETE FROM metabib.browse_entry_def_map WHERE source = bib_id;
50         END IF;
51     END IF;
52
53     FOR ind_data IN SELECT * FROM biblio.extract_metabib_field_entry( bib_id ) LOOP
54         IF ind_data.field < 0 THEN
55             ind_data.field = -1 * ind_data.field;
56         END IF;
57
58         IF ind_data.facet_field AND NOT b_skip_facet THEN
59             INSERT INTO metabib.facet_entry (field, source, value)
60                 VALUES (ind_data.field, ind_data.source, ind_data.value);
61         END IF;
62
63         IF ind_data.browse_field AND NOT b_skip_browse THEN
64             -- A caveat about this SELECT: this should take care of replacing
65             -- old mbe rows when data changes, but not if normalization (by
66             -- which I mean specifically the output of
67             -- evergreen.oils_tsearch2()) changes.  It may or may not be
68             -- expensive to add a comparison of index_vector to index_vector
69             -- to the WHERE clause below.
70             SELECT INTO mbe_row * FROM metabib.browse_entry WHERE value = ind_data.value;
71             IF FOUND THEN
72                 mbe_id := mbe_row.id;
73             ELSE
74                 INSERT INTO metabib.browse_entry (value) VALUES
75                     (metabib.browse_normalize(ind_data.value, ind_data.field));
76                 mbe_id := CURRVAL('metabib.browse_entry_id_seq'::REGCLASS);
77             END IF;
78
79             INSERT INTO metabib.browse_entry_def_map (entry, def, source, authority)
80                 VALUES (mbe_id, ind_data.field, ind_data.source, ind_data.authority);
81         END IF;
82
83         IF ind_data.search_field AND NOT b_skip_search THEN
84             EXECUTE $$
85                 INSERT INTO metabib.$$ || ind_data.field_class || $$_field_entry (field, source, value)
86                     VALUES ($$ ||
87                         quote_literal(ind_data.field) || $$, $$ ||
88                         quote_literal(ind_data.source) || $$, $$ ||
89                         quote_literal(ind_data.value) ||
90                     $$);$$;
91         END IF;
92
93     END LOOP;
94
95     IF NOT b_skip_search THEN
96         PERFORM metabib.update_combined_index_vectors(bib_id);
97     END IF;
98
99     RETURN;
100 END;
101 $func$ LANGUAGE PLPGSQL;
102
103
104 CREATE OR REPLACE FUNCTION biblio.extract_metabib_field_entry ( rid BIGINT, default_joiner TEXT ) RETURNS SETOF metabib.field_entry_template AS $func$
105 DECLARE
106     bib     biblio.record_entry%ROWTYPE;
107     idx     config.metabib_field%ROWTYPE;
108     xfrm        config.xml_transform%ROWTYPE;
109     prev_xfrm   TEXT;
110     transformed_xml TEXT;
111     xml_node    TEXT;
112     xml_node_list   TEXT[];
113     facet_text  TEXT;
114     browse_text TEXT;
115     raw_text    TEXT;
116     curr_text   TEXT;
117     joiner      TEXT := default_joiner; -- XXX will index defs supply a joiner?
118     authority_text TEXT;
119     authority_link BIGINT;
120     output_row  metabib.field_entry_template%ROWTYPE;
121 BEGIN
122
123     -- Get the record
124     SELECT INTO bib * FROM biblio.record_entry WHERE id = rid;
125
126     -- Loop over the indexing entries
127     FOR idx IN SELECT * FROM config.metabib_field ORDER BY format LOOP
128
129         SELECT INTO xfrm * from config.xml_transform WHERE name = idx.format;
130
131         -- See if we can skip the XSLT ... it's expensive
132         IF prev_xfrm IS NULL OR prev_xfrm <> xfrm.name THEN
133             -- Can't skip the transform
134             IF xfrm.xslt <> '---' THEN
135                 transformed_xml := oils_xslt_process(bib.marc,xfrm.xslt);
136             ELSE
137                 transformed_xml := bib.marc;
138             END IF;
139
140             prev_xfrm := xfrm.name;
141         END IF;
142
143         xml_node_list := oils_xpath( idx.xpath, transformed_xml, ARRAY[ARRAY[xfrm.prefix, xfrm.namespace_uri]] );
144
145         raw_text := NULL;
146         FOR xml_node IN SELECT x FROM unnest(xml_node_list) AS x LOOP
147             CONTINUE WHEN xml_node !~ E'^\\s*<';
148
149             curr_text := ARRAY_TO_STRING(
150                 oils_xpath( '//text()',
151                     REGEXP_REPLACE( -- This escapes all &s not followed by "amp;".  Data ise returned from oils_xpath (above) in UTF-8, not entity encoded
152                         REGEXP_REPLACE( -- This escapes embeded <s
153                             xml_node,
154                             $re$(>[^<]+)(<)([^>]+<)$re$,
155                             E'\\1&lt;\\3',
156                             'g'
157                         ),
158                         '&(?!amp;)',
159                         '&amp;',
160                         'g'
161                     )
162                 ),
163                 ' '
164             );
165
166             CONTINUE WHEN curr_text IS NULL OR curr_text = '';
167
168             IF raw_text IS NOT NULL THEN
169                 raw_text := raw_text || joiner;
170             END IF;
171
172             raw_text := COALESCE(raw_text,'') || curr_text;
173
174             -- autosuggest/metabib.browse_entry
175             IF idx.browse_field THEN
176
177                 IF idx.browse_xpath IS NOT NULL AND idx.browse_xpath <> '' THEN
178                     browse_text := oils_xpath_string( idx.browse_xpath, xml_node, joiner, ARRAY[ARRAY[xfrm.prefix, xfrm.namespace_uri]] );
179                 ELSE
180                     browse_text := curr_text;
181                 END IF;
182
183                 output_row.field_class = idx.field_class;
184                 output_row.field = idx.id;
185                 output_row.source = rid;
186                 output_row.value = BTRIM(REGEXP_REPLACE(browse_text, E'\\s+', ' ', 'g'));
187
188                 IF idx.authority_xpath IS NOT NULL AND idx.authority_xpath <> '' THEN
189                     authority_text := oils_xpath_string(
190                         idx.authority_xpath, xml_node, joiner,
191                         ARRAY[
192                             ARRAY[xfrm.prefix, xfrm.namespace_uri],
193                             ARRAY['xlink','http://www.w3.org/1999/xlink']
194                         ]
195                     );
196
197                     IF authority_text ~ '^\d+$' THEN
198                         authority_link := authority_text::BIGINT;
199                         PERFORM * FROM authority.record_entry WHERE id = authority_link;
200                         IF FOUND THEN
201                             output_row.authority := authority_link;
202                         END IF;
203                     END IF;
204
205                 END IF;
206
207                 output_row.browse_field = TRUE;
208                 RETURN NEXT output_row;
209                 output_row.browse_field = FALSE;
210             END IF;
211
212             -- insert raw node text for faceting
213             IF idx.facet_field THEN
214
215                 IF idx.facet_xpath IS NOT NULL AND idx.facet_xpath <> '' THEN
216                     facet_text := oils_xpath_string( idx.facet_xpath, xml_node, joiner, ARRAY[ARRAY[xfrm.prefix, xfrm.namespace_uri]] );
217                 ELSE
218                     facet_text := curr_text;
219                 END IF;
220
221                 output_row.field_class = idx.field_class;
222                 output_row.field = -1 * idx.id;
223                 output_row.source = rid;
224                 output_row.value = BTRIM(REGEXP_REPLACE(facet_text, E'\\s+', ' ', 'g'));
225
226                 output_row.facet_field = TRUE;
227                 RETURN NEXT output_row;
228                 output_row.facet_field = FALSE;
229             END IF;
230
231         END LOOP;
232
233         CONTINUE WHEN raw_text IS NULL OR raw_text = '';
234
235         -- insert combined node text for searching
236         IF idx.search_field THEN
237             output_row.field_class = idx.field_class;
238             output_row.field = idx.id;
239             output_row.source = rid;
240             output_row.value = BTRIM(REGEXP_REPLACE(raw_text, E'\\s+', ' ', 'g'));
241
242             output_row.search_field = TRUE;
243             RETURN NEXT output_row;
244         END IF;
245
246     END LOOP;
247
248 END;
249
250 $func$ LANGUAGE PLPGSQL;
251
252
253 -- 953.data.MODS32-xsl.sql
254 UPDATE config.xml_transform SET xslt=$$<?xml version="1.0" encoding="UTF-8"?>
255 <xsl:stylesheet xmlns="http://www.loc.gov/mods/v3" xmlns:marc="http://www.loc.gov/MARC21/slim" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="xlink marc" version="1.0">
256         <xsl:output encoding="UTF-8" indent="yes" method="xml"/>
257 <!--
258 Revision 1.14 - Fixed template isValid and fields 010, 020, 022, 024, 028, and 037 to output additional identifier elements 
259   with corresponding @type and @invalid eq 'yes' when subfields z or y (in the case of 022) exist in the MARCXML ::: 2007/01/04 17:35:20 cred
260
261 Revision 1.13 - Changed order of output under cartographics to reflect schema  2006/11/28 tmee
262         
263 Revision 1.12 - Updated to reflect MODS 3.2 Mapping  2006/10/11 tmee
264                 
265 Revision 1.11 - The attribute objectPart moved from <languageTerm> to <language>
266       2006/04/08  jrad
267
268 Revision 1.10 MODS 3.1 revisions to language and classification elements  
269                                 (plus ability to find marc:collection embedded in wrapper elements such as SRU zs: wrappers)
270                                 2006/02/06  ggar
271
272 Revision 1.9 subfield $y was added to field 242 2004/09/02 10:57 jrad
273
274 Revision 1.8 Subject chopPunctuation expanded and attribute fixes 2004/08/12 jrad
275
276 Revision 1.7 2004/03/25 08:29 jrad
277
278 Revision 1.6 various validation fixes 2004/02/20 ntra
279
280 Revision 1.5  2003/10/02 16:18:58  ntra
281 MODS2 to MODS3 updates, language unstacking and 
282 de-duping, chopPunctuation expanded
283
284 Revision 1.3  2003/04/03 00:07:19  ntra
285 Revision 1.3 Additional Changes not related to MODS Version 2.0 by ntra
286
287 Revision 1.2  2003/03/24 19:37:42  ckeith
288 Added Log Comment
289
290 -->
291         <xsl:template match="/">
292                 <xsl:choose>
293                         <xsl:when test="//marc:collection">
294                                 <modsCollection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-2.xsd">
295                                         <xsl:for-each select="//marc:collection/marc:record">
296                                                 <mods version="3.2">
297                                                         <xsl:call-template name="marcRecord"/>
298                                                 </mods>
299                                         </xsl:for-each>
300                                 </modsCollection>
301                         </xsl:when>
302                         <xsl:otherwise>
303                                 <mods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.2" xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-2.xsd">
304                                         <xsl:for-each select="//marc:record">
305                                                 <xsl:call-template name="marcRecord"/>
306                                         </xsl:for-each>
307                                 </mods>
308                         </xsl:otherwise>
309                 </xsl:choose>
310         </xsl:template>
311         <xsl:template name="marcRecord">
312                 <xsl:variable name="leader" select="marc:leader"/>
313                 <xsl:variable name="leader6" select="substring($leader,7,1)"/>
314                 <xsl:variable name="leader7" select="substring($leader,8,1)"/>
315                 <xsl:variable name="controlField008" select="marc:controlfield[@tag='008']"/>
316                 <xsl:variable name="typeOf008">
317                         <xsl:choose>
318                                 <xsl:when test="$leader6='a'">
319                                         <xsl:choose>
320                                                 <xsl:when test="$leader7='a' or $leader7='c' or $leader7='d' or $leader7='m'">BK</xsl:when>
321                                                 <xsl:when test="$leader7='b' or $leader7='i' or $leader7='s'">SE</xsl:when>
322                                         </xsl:choose>
323                                 </xsl:when>
324                                 <xsl:when test="$leader6='t'">BK</xsl:when>
325                                 <xsl:when test="$leader6='p'">MM</xsl:when>
326                                 <xsl:when test="$leader6='m'">CF</xsl:when>
327                                 <xsl:when test="$leader6='e' or $leader6='f'">MP</xsl:when>
328                                 <xsl:when test="$leader6='g' or $leader6='k' or $leader6='o' or $leader6='r'">VM</xsl:when>
329                                 <xsl:when test="$leader6='c' or $leader6='d' or $leader6='i' or $leader6='j'">MU</xsl:when>
330                         </xsl:choose>
331                 </xsl:variable>
332                 <xsl:for-each select="marc:datafield[@tag='245']">
333                         <titleInfo>
334                                 <xsl:variable name="title">
335                                         <xsl:choose>
336                                                 <xsl:when test="marc:subfield[@code='b']">
337                                                         <xsl:call-template name="specialSubfieldSelect">
338                                                                 <xsl:with-param name="axis">b</xsl:with-param>
339                                                                 <xsl:with-param name="beforeCodes">afgk</xsl:with-param>
340                                                         </xsl:call-template>
341                                                 </xsl:when>
342                                                 <xsl:otherwise>
343                                                         <xsl:call-template name="subfieldSelect">
344                                                                 <xsl:with-param name="codes">abfgk</xsl:with-param>
345                                                         </xsl:call-template>
346                                                 </xsl:otherwise>
347                                         </xsl:choose>
348                                 </xsl:variable>
349                                 <xsl:variable name="titleChop">
350                                         <xsl:call-template name="chopPunctuation">
351                                                 <xsl:with-param name="chopString">
352                                                         <xsl:value-of select="$title"/>
353                                                 </xsl:with-param>
354                                         </xsl:call-template>
355                                 </xsl:variable>
356                                 <xsl:choose>
357                                         <xsl:when test="@ind2>0">
358                                                 <nonSort>
359                                                         <xsl:value-of select="substring($titleChop,1,@ind2)"/>
360                                                 </nonSort>
361                                                 <title>
362                                                         <xsl:value-of select="substring($titleChop,@ind2+1)"/>
363                                                 </title>
364                                         </xsl:when>
365                                         <xsl:otherwise>
366                                                 <title>
367                                                         <xsl:value-of select="$titleChop"/>
368                                                 </title>
369                                         </xsl:otherwise>
370                                 </xsl:choose>
371                                 <xsl:if test="marc:subfield[@code='b']">
372                                         <subTitle>
373                                                 <xsl:call-template name="chopPunctuation">
374                                                         <xsl:with-param name="chopString">
375                                                                 <xsl:call-template name="specialSubfieldSelect">
376                                                                         <xsl:with-param name="axis">b</xsl:with-param>
377                                                                         <xsl:with-param name="anyCodes">b</xsl:with-param>
378                                                                         <xsl:with-param name="afterCodes">afgk</xsl:with-param>
379                                                                 </xsl:call-template>
380                                                         </xsl:with-param>
381                                                 </xsl:call-template>
382                                         </subTitle>
383                                 </xsl:if>
384                                 <xsl:call-template name="part"></xsl:call-template>
385                         </titleInfo>
386                         <!-- A form of title that ignores non-filing characters; useful
387                                  for not converting "L'Oreal" into "L' Oreal" at index time -->
388                         <titleNonfiling>
389                                 <xsl:variable name="title">
390                                         <xsl:choose>
391                                                 <xsl:when test="marc:subfield[@code='b']">
392                                                         <xsl:call-template name="specialSubfieldSelect">
393                                                                 <xsl:with-param name="axis">b</xsl:with-param>
394                                                                 <xsl:with-param name="beforeCodes">afgk</xsl:with-param>
395                                                         </xsl:call-template>
396                                                 </xsl:when>
397                                                 <xsl:otherwise>
398                                                         <xsl:call-template name="subfieldSelect">
399                                                                 <xsl:with-param name="codes">abfgk</xsl:with-param>
400                                                         </xsl:call-template>
401                                                 </xsl:otherwise>
402                                         </xsl:choose>
403                                 </xsl:variable>
404                                 <title>
405                                         <xsl:value-of select="$title"/>
406                                 </title>
407                                 <xsl:if test="marc:subfield[@code='b']">
408                                         <subTitle>
409                                                 <xsl:call-template name="chopPunctuation">
410                                                         <xsl:with-param name="chopString">
411                                                                 <xsl:call-template name="specialSubfieldSelect">
412                                                                         <xsl:with-param name="axis">b</xsl:with-param>
413                                                                         <xsl:with-param name="anyCodes">b</xsl:with-param>
414                                                                         <xsl:with-param name="afterCodes">afgk</xsl:with-param>
415                                                                 </xsl:call-template>
416                                                         </xsl:with-param>
417                                                 </xsl:call-template>
418                                         </subTitle>
419                                 </xsl:if>
420                                 <xsl:call-template name="part"></xsl:call-template>
421                         </titleNonfiling>
422                 </xsl:for-each>
423                 <xsl:for-each select="marc:datafield[@tag='210']">
424                         <titleInfo type="abbreviated">
425                                 <title>
426                                         <xsl:call-template name="chopPunctuation">
427                                                 <xsl:with-param name="chopString">
428                                                         <xsl:call-template name="subfieldSelect">
429                                                                 <xsl:with-param name="codes">a</xsl:with-param>
430                                                         </xsl:call-template>
431                                                 </xsl:with-param>
432                                         </xsl:call-template>
433                                 </title>
434                                 <xsl:call-template name="subtitle"/>
435                         </titleInfo>
436                 </xsl:for-each>
437                 <xsl:for-each select="marc:datafield[@tag='242']">
438                         <titleInfo type="translated">
439                                 <!--09/01/04 Added subfield $y-->
440                                 <xsl:for-each select="marc:subfield[@code='y']">
441                                         <xsl:attribute name="lang">
442                                                 <xsl:value-of select="text()"/>
443                                         </xsl:attribute>
444                                 </xsl:for-each>
445                                 <title>
446                                         <xsl:call-template name="chopPunctuation">
447                                                 <xsl:with-param name="chopString">
448                                                         <xsl:call-template name="subfieldSelect">
449                                                                 <!-- 1/04 removed $h, b -->
450                                                                 <xsl:with-param name="codes">a</xsl:with-param>
451                                                         </xsl:call-template>
452                                                 </xsl:with-param>
453                                         </xsl:call-template>
454                                 </title>
455                                 <!-- 1/04 fix -->
456                                 <xsl:call-template name="subtitle"/>
457                                 <xsl:call-template name="part"/>
458                         </titleInfo>
459                 </xsl:for-each>
460                 <xsl:for-each select="marc:datafield[@tag='246']">
461                         <titleInfo type="alternative">
462                                 <xsl:for-each select="marc:subfield[@code='i']">
463                                         <xsl:attribute name="displayLabel">
464                                                 <xsl:value-of select="text()"/>
465                                         </xsl:attribute>
466                                 </xsl:for-each>
467                                 <title>
468                                         <xsl:call-template name="chopPunctuation">
469                                                 <xsl:with-param name="chopString">
470                                                         <xsl:call-template name="subfieldSelect">
471                                                                 <!-- 1/04 removed $h, $b -->
472                                                                 <xsl:with-param name="codes">af</xsl:with-param>
473                                                         </xsl:call-template>
474                                                 </xsl:with-param>
475                                         </xsl:call-template>
476                                 </title>
477                                 <xsl:call-template name="subtitle"/>
478                                 <xsl:call-template name="part"/>
479                         </titleInfo>
480                 </xsl:for-each>
481                 <xsl:for-each select="marc:datafield[@tag='130']|marc:datafield[@tag='240']|marc:datafield[@tag='730'][@ind2!='2']">
482                         <titleInfo type="uniform">
483                                 <title>
484                                         <xsl:call-template name="uri" />
485                                         <xsl:variable name="str">
486                                                 <xsl:for-each select="marc:subfield">
487                                                         <xsl:if test="(contains('adfklmor',@code) and (not(../marc:subfield[@code='n' or @code='p']) or (following-sibling::marc:subfield[@code='n' or @code='p'])))">
488                                                                 <xsl:value-of select="text()"/>
489                                                                 <xsl:text> </xsl:text>
490                                                         </xsl:if>
491                                                 </xsl:for-each>
492                                         </xsl:variable>
493                                         <xsl:call-template name="chopPunctuation">
494                                                 <xsl:with-param name="chopString">
495                                                         <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
496                                                 </xsl:with-param>
497                                         </xsl:call-template>
498                                 </title>
499                                 <xsl:call-template name="part"/>
500                         </titleInfo>
501                 </xsl:for-each>
502                 <xsl:for-each select="marc:datafield[@tag='740'][@ind2!='2']">
503                         <titleInfo type="alternative">
504                                 <title>
505                                         <xsl:call-template name="chopPunctuation">
506                                                 <xsl:with-param name="chopString">
507                                                         <xsl:call-template name="subfieldSelect">
508                                                                 <xsl:with-param name="codes">ah</xsl:with-param>
509                                                         </xsl:call-template>
510                                                 </xsl:with-param>
511                                         </xsl:call-template>
512                                 </title>
513                                 <xsl:call-template name="part"/>
514                         </titleInfo>
515                 </xsl:for-each>
516                 <xsl:for-each select="marc:datafield[@tag='100']">
517                         <name type="personal">
518                                 <xsl:call-template name="uri" />
519                                 <xsl:call-template name="nameABCDQ"/>
520                                 <xsl:call-template name="affiliation"/>
521                                 <role>
522                                         <roleTerm authority="marcrelator" type="text">creator</roleTerm>
523                                 </role>
524                                 <xsl:call-template name="role"/>
525                         </name>
526                 </xsl:for-each>
527                 <xsl:for-each select="marc:datafield[@tag='110']">
528                         <name type="corporate">
529                                 <xsl:call-template name="uri" />
530                                 <xsl:call-template name="nameABCDN"/>
531                                 <role>
532                                         <roleTerm authority="marcrelator" type="text">creator</roleTerm>
533                                 </role>
534                                 <xsl:call-template name="role"/>
535                         </name>
536                 </xsl:for-each>
537                 <xsl:for-each select="marc:datafield[@tag='111']">
538                         <name type="conference">
539                                 <xsl:call-template name="uri" />
540                                 <xsl:call-template name="nameACDEQ"/>
541                                 <role>
542                                         <roleTerm authority="marcrelator" type="text">creator</roleTerm>
543                                 </role>
544                                 <xsl:call-template name="role"/>
545                         </name>
546                 </xsl:for-each>
547                 <xsl:for-each select="marc:datafield[@tag='700'][not(marc:subfield[@code='t'])]">
548                         <name type="personal">
549                                 <xsl:call-template name="uri" />
550                                 <xsl:call-template name="nameABCDQ"/>
551                                 <xsl:call-template name="affiliation"/>
552                                 <xsl:call-template name="role"/>
553                         </name>
554                 </xsl:for-each>
555                 <xsl:for-each select="marc:datafield[@tag='710'][not(marc:subfield[@code='t'])]">
556                         <name type="corporate">
557                                 <xsl:call-template name="uri" />
558                                 <xsl:call-template name="nameABCDN"/>
559                                 <xsl:call-template name="role"/>
560                         </name>
561                 </xsl:for-each>
562                 <xsl:for-each select="marc:datafield[@tag='711'][not(marc:subfield[@code='t'])]">
563                         <name type="conference">
564                                 <xsl:call-template name="uri" />
565                                 <xsl:call-template name="nameACDEQ"/>
566                                 <xsl:call-template name="role"/>
567                         </name>
568                 </xsl:for-each>
569                 <xsl:for-each select="marc:datafield[@tag='720'][not(marc:subfield[@code='t'])]">
570                         <name>
571                                 <xsl:if test="@ind1=1">
572                                         <xsl:attribute name="type">
573                                                 <xsl:text>personal</xsl:text>
574                                         </xsl:attribute>
575                                 </xsl:if>
576                                 <namePart>
577                                         <xsl:value-of select="marc:subfield[@code='a']"/>
578                                 </namePart>
579                                 <xsl:call-template name="role"/>
580                         </name>
581                 </xsl:for-each>
582                 <typeOfResource>
583                         <xsl:if test="$leader7='c'">
584                                 <xsl:attribute name="collection">yes</xsl:attribute>
585                         </xsl:if>
586                         <xsl:if test="$leader6='d' or $leader6='f' or $leader6='p' or $leader6='t'">
587                                 <xsl:attribute name="manuscript">yes</xsl:attribute>
588                         </xsl:if>
589                         <xsl:choose>
590                                 <xsl:when test="$leader6='a' or $leader6='t'">text</xsl:when>
591                                 <xsl:when test="$leader6='e' or $leader6='f'">cartographic</xsl:when>
592                                 <xsl:when test="$leader6='c' or $leader6='d'">notated music</xsl:when>
593                                 <xsl:when test="$leader6='i'">sound recording-nonmusical</xsl:when>
594                                 <xsl:when test="$leader6='j'">sound recording-musical</xsl:when>
595                                 <xsl:when test="$leader6='k'">still image</xsl:when>
596                                 <xsl:when test="$leader6='g'">moving image</xsl:when>
597                                 <xsl:when test="$leader6='r'">three dimensional object</xsl:when>
598                                 <xsl:when test="$leader6='m'">software, multimedia</xsl:when>
599                                 <xsl:when test="$leader6='p'">mixed material</xsl:when>
600                         </xsl:choose>
601                 </typeOfResource>
602                 <xsl:if test="substring($controlField008,26,1)='d'">
603                         <genre authority="marc">globe</genre>
604                 </xsl:if>
605                 <xsl:if test="marc:controlfield[@tag='007'][substring(text(),1,1)='a'][substring(text(),2,1)='r']">
606                         <genre authority="marc">remote sensing image</genre>
607                 </xsl:if>
608                 <xsl:if test="$typeOf008='MP'">
609                         <xsl:variable name="controlField008-25" select="substring($controlField008,26,1)"></xsl:variable>
610                         <xsl:choose>
611                                 <xsl:when test="$controlField008-25='a' or $controlField008-25='b' or $controlField008-25='c' or marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='j']">
612                                         <genre authority="marc">map</genre>
613                                 </xsl:when>
614                                 <xsl:when test="$controlField008-25='e' or marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='d']">
615                                         <genre authority="marc">atlas</genre>
616                                 </xsl:when>
617                         </xsl:choose>
618                 </xsl:if>
619                 <xsl:if test="$typeOf008='SE'">
620                         <xsl:variable name="controlField008-21" select="substring($controlField008,22,1)"></xsl:variable>
621                         <xsl:choose>
622                                 <xsl:when test="$controlField008-21='d'">
623                                         <genre authority="marc">database</genre>
624                                 </xsl:when>
625                                 <xsl:when test="$controlField008-21='l'">
626                                         <genre authority="marc">loose-leaf</genre>
627                                 </xsl:when>
628                                 <xsl:when test="$controlField008-21='m'">
629                                         <genre authority="marc">series</genre>
630                                 </xsl:when>
631                                 <xsl:when test="$controlField008-21='n'">
632                                         <genre authority="marc">newspaper</genre>
633                                 </xsl:when>
634                                 <xsl:when test="$controlField008-21='p'">
635                                         <genre authority="marc">periodical</genre>
636                                 </xsl:when>
637                                 <xsl:when test="$controlField008-21='w'">
638                                         <genre authority="marc">web site</genre>
639                                 </xsl:when>
640                         </xsl:choose>
641                 </xsl:if>
642                 <xsl:if test="$typeOf008='BK' or $typeOf008='SE'">
643                         <xsl:variable name="controlField008-24" select="substring($controlField008,25,4)"></xsl:variable>
644                         <xsl:choose>
645                                 <xsl:when test="contains($controlField008-24,'a')">
646                                         <genre authority="marc">abstract or summary</genre>
647                                 </xsl:when>
648                                 <xsl:when test="contains($controlField008-24,'b')">
649                                         <genre authority="marc">bibliography</genre>
650                                 </xsl:when>
651                                 <xsl:when test="contains($controlField008-24,'c')">
652                                         <genre authority="marc">catalog</genre>
653                                 </xsl:when>
654                                 <xsl:when test="contains($controlField008-24,'d')">
655                                         <genre authority="marc">dictionary</genre>
656                                 </xsl:when>
657                                 <xsl:when test="contains($controlField008-24,'e')">
658                                         <genre authority="marc">encyclopedia</genre>
659                                 </xsl:when>
660                                 <xsl:when test="contains($controlField008-24,'f')">
661                                         <genre authority="marc">handbook</genre>
662                                 </xsl:when>
663                                 <xsl:when test="contains($controlField008-24,'g')">
664                                         <genre authority="marc">legal article</genre>
665                                 </xsl:when>
666                                 <xsl:when test="contains($controlField008-24,'i')">
667                                         <genre authority="marc">index</genre>
668                                 </xsl:when>
669                                 <xsl:when test="contains($controlField008-24,'k')">
670                                         <genre authority="marc">discography</genre>
671                                 </xsl:when>
672                                 <xsl:when test="contains($controlField008-24,'l')">
673                                         <genre authority="marc">legislation</genre>
674                                 </xsl:when>
675                                 <xsl:when test="contains($controlField008-24,'m')">
676                                         <genre authority="marc">theses</genre>
677                                 </xsl:when>
678                                 <xsl:when test="contains($controlField008-24,'n')">
679                                         <genre authority="marc">survey of literature</genre>
680                                 </xsl:when>
681                                 <xsl:when test="contains($controlField008-24,'o')">
682                                         <genre authority="marc">review</genre>
683                                 </xsl:when>
684                                 <xsl:when test="contains($controlField008-24,'p')">
685                                         <genre authority="marc">programmed text</genre>
686                                 </xsl:when>
687                                 <xsl:when test="contains($controlField008-24,'q')">
688                                         <genre authority="marc">filmography</genre>
689                                 </xsl:when>
690                                 <xsl:when test="contains($controlField008-24,'r')">
691                                         <genre authority="marc">directory</genre>
692                                 </xsl:when>
693                                 <xsl:when test="contains($controlField008-24,'s')">
694                                         <genre authority="marc">statistics</genre>
695                                 </xsl:when>
696                                 <xsl:when test="contains($controlField008-24,'t')">
697                                         <genre authority="marc">technical report</genre>
698                                 </xsl:when>
699                                 <xsl:when test="contains($controlField008-24,'v')">
700                                         <genre authority="marc">legal case and case notes</genre>
701                                 </xsl:when>
702                                 <xsl:when test="contains($controlField008-24,'w')">
703                                         <genre authority="marc">law report or digest</genre>
704                                 </xsl:when>
705                                 <xsl:when test="contains($controlField008-24,'z')">
706                                         <genre authority="marc">treaty</genre>
707                                 </xsl:when>
708                         </xsl:choose>
709                         <xsl:variable name="controlField008-29" select="substring($controlField008,30,1)"></xsl:variable>
710                         <xsl:choose>
711                                 <xsl:when test="$controlField008-29='1'">
712                                         <genre authority="marc">conference publication</genre>
713                                 </xsl:when>
714                         </xsl:choose>
715                 </xsl:if>
716                 <xsl:if test="$typeOf008='CF'">
717                         <xsl:variable name="controlField008-26" select="substring($controlField008,27,1)"></xsl:variable>
718                         <xsl:choose>
719                                 <xsl:when test="$controlField008-26='a'">
720                                         <genre authority="marc">numeric data</genre>
721                                 </xsl:when>
722                                 <xsl:when test="$controlField008-26='e'">
723                                         <genre authority="marc">database</genre>
724                                 </xsl:when>
725                                 <xsl:when test="$controlField008-26='f'">
726                                         <genre authority="marc">font</genre>
727                                 </xsl:when>
728                                 <xsl:when test="$controlField008-26='g'">
729                                         <genre authority="marc">game</genre>
730                                 </xsl:when>
731                         </xsl:choose>
732                 </xsl:if>
733                 <xsl:if test="$typeOf008='BK'">
734                         <xsl:if test="substring($controlField008,25,1)='j'">
735                                 <genre authority="marc">patent</genre>
736                         </xsl:if>
737                         <xsl:if test="substring($controlField008,31,1)='1'">
738                                 <genre authority="marc">festschrift</genre>
739                         </xsl:if>
740                         <xsl:variable name="controlField008-34" select="substring($controlField008,35,1)"></xsl:variable>
741                         <xsl:if test="$controlField008-34='a' or $controlField008-34='b' or $controlField008-34='c' or $controlField008-34='d'">
742                                 <genre authority="marc">biography</genre>
743                         </xsl:if>
744                         <xsl:variable name="controlField008-33" select="substring($controlField008,34,1)"></xsl:variable>
745                         <xsl:choose>
746                                 <xsl:when test="$controlField008-33='e'">
747                                         <genre authority="marc">essay</genre>
748                                 </xsl:when>
749                                 <xsl:when test="$controlField008-33='d'">
750                                         <genre authority="marc">drama</genre>
751                                 </xsl:when>
752                                 <xsl:when test="$controlField008-33='c'">
753                                         <genre authority="marc">comic strip</genre>
754                                 </xsl:when>
755                                 <xsl:when test="$controlField008-33='l'">
756                                         <genre authority="marc">fiction</genre>
757                                 </xsl:when>
758                                 <xsl:when test="$controlField008-33='h'">
759                                         <genre authority="marc">humor, satire</genre>
760                                 </xsl:when>
761                                 <xsl:when test="$controlField008-33='i'">
762                                         <genre authority="marc">letter</genre>
763                                 </xsl:when>
764                                 <xsl:when test="$controlField008-33='f'">
765                                         <genre authority="marc">novel</genre>
766                                 </xsl:when>
767                                 <xsl:when test="$controlField008-33='j'">
768                                         <genre authority="marc">short story</genre>
769                                 </xsl:when>
770                                 <xsl:when test="$controlField008-33='s'">
771                                         <genre authority="marc">speech</genre>
772                                 </xsl:when>
773                         </xsl:choose>
774                 </xsl:if>
775                 <xsl:if test="$typeOf008='MU'">
776                         <xsl:variable name="controlField008-30-31" select="substring($controlField008,31,2)"></xsl:variable>
777                         <xsl:if test="contains($controlField008-30-31,'b')">
778                                 <genre authority="marc">biography</genre>
779                         </xsl:if>
780                         <xsl:if test="contains($controlField008-30-31,'c')">
781                                 <genre authority="marc">conference publication</genre>
782                         </xsl:if>
783                         <xsl:if test="contains($controlField008-30-31,'d')">
784                                 <genre authority="marc">drama</genre>
785                         </xsl:if>
786                         <xsl:if test="contains($controlField008-30-31,'e')">
787                                 <genre authority="marc">essay</genre>
788                         </xsl:if>
789                         <xsl:if test="contains($controlField008-30-31,'f')">
790                                 <genre authority="marc">fiction</genre>
791                         </xsl:if>
792                         <xsl:if test="contains($controlField008-30-31,'o')">
793                                 <genre authority="marc">folktale</genre>
794                         </xsl:if>
795                         <xsl:if test="contains($controlField008-30-31,'h')">
796                                 <genre authority="marc">history</genre>
797                         </xsl:if>
798                         <xsl:if test="contains($controlField008-30-31,'k')">
799                                 <genre authority="marc">humor, satire</genre>
800                         </xsl:if>
801                         <xsl:if test="contains($controlField008-30-31,'m')">
802                                 <genre authority="marc">memoir</genre>
803                         </xsl:if>
804                         <xsl:if test="contains($controlField008-30-31,'p')">
805                                 <genre authority="marc">poetry</genre>
806                         </xsl:if>
807                         <xsl:if test="contains($controlField008-30-31,'r')">
808                                 <genre authority="marc">rehearsal</genre>
809                         </xsl:if>
810                         <xsl:if test="contains($controlField008-30-31,'g')">
811                                 <genre authority="marc">reporting</genre>
812                         </xsl:if>
813                         <xsl:if test="contains($controlField008-30-31,'s')">
814                                 <genre authority="marc">sound</genre>
815                         </xsl:if>
816                         <xsl:if test="contains($controlField008-30-31,'l')">
817                                 <genre authority="marc">speech</genre>
818                         </xsl:if>
819                 </xsl:if>
820                 <xsl:if test="$typeOf008='VM'">
821                         <xsl:variable name="controlField008-33" select="substring($controlField008,34,1)"></xsl:variable>
822                         <xsl:choose>
823                                 <xsl:when test="$controlField008-33='a'">
824                                         <genre authority="marc">art original</genre>
825                                 </xsl:when>
826                                 <xsl:when test="$controlField008-33='b'">
827                                         <genre authority="marc">kit</genre>
828                                 </xsl:when>
829                                 <xsl:when test="$controlField008-33='c'">
830                                         <genre authority="marc">art reproduction</genre>
831                                 </xsl:when>
832                                 <xsl:when test="$controlField008-33='d'">
833                                         <genre authority="marc">diorama</genre>
834                                 </xsl:when>
835                                 <xsl:when test="$controlField008-33='f'">
836                                         <genre authority="marc">filmstrip</genre>
837                                 </xsl:when>
838                                 <xsl:when test="$controlField008-33='g'">
839                                         <genre authority="marc">legal article</genre>
840                                 </xsl:when>
841                                 <xsl:when test="$controlField008-33='i'">
842                                         <genre authority="marc">picture</genre>
843                                 </xsl:when>
844                                 <xsl:when test="$controlField008-33='k'">
845                                         <genre authority="marc">graphic</genre>
846                                 </xsl:when>
847                                 <xsl:when test="$controlField008-33='l'">
848                                         <genre authority="marc">technical drawing</genre>
849                                 </xsl:when>
850                                 <xsl:when test="$controlField008-33='m'">
851                                         <genre authority="marc">motion picture</genre>
852                                 </xsl:when>
853                                 <xsl:when test="$controlField008-33='n'">
854                                         <genre authority="marc">chart</genre>
855                                 </xsl:when>
856                                 <xsl:when test="$controlField008-33='o'">
857                                         <genre authority="marc">flash card</genre>
858                                 </xsl:when>
859                                 <xsl:when test="$controlField008-33='p'">
860                                         <genre authority="marc">microscope slide</genre>
861                                 </xsl:when>
862                                 <xsl:when test="$controlField008-33='q' or marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='q']">
863                                         <genre authority="marc">model</genre>
864                                 </xsl:when>
865                                 <xsl:when test="$controlField008-33='r'">
866                                         <genre authority="marc">realia</genre>
867                                 </xsl:when>
868                                 <xsl:when test="$controlField008-33='s'">
869                                         <genre authority="marc">slide</genre>
870                                 </xsl:when>
871                                 <xsl:when test="$controlField008-33='t'">
872                                         <genre authority="marc">transparency</genre>
873                                 </xsl:when>
874                                 <xsl:when test="$controlField008-33='v'">
875                                         <genre authority="marc">videorecording</genre>
876                                 </xsl:when>
877                                 <xsl:when test="$controlField008-33='w'">
878                                         <genre authority="marc">toy</genre>
879                                 </xsl:when>
880                         </xsl:choose>
881                 </xsl:if>
882                 <xsl:for-each select="marc:datafield[@tag=655]">
883                         <genre authority="marc">
884                                 <xsl:attribute name="authority">
885                                         <xsl:value-of select="marc:subfield[@code='2']"/>
886                                 </xsl:attribute>
887                                 <xsl:call-template name="subfieldSelect">
888                                         <xsl:with-param name="codes">abvxyz</xsl:with-param>
889                                         <xsl:with-param name="delimeter">-</xsl:with-param>
890                                 </xsl:call-template>
891                         </genre>
892                 </xsl:for-each>
893                 <originInfo>
894                         <xsl:variable name="MARCpublicationCode" select="normalize-space(substring($controlField008,16,3))"></xsl:variable>
895                         <xsl:if test="translate($MARCpublicationCode,'|','')">
896                                 <place>
897                                         <placeTerm>
898                                                 <xsl:attribute name="type">code</xsl:attribute>
899                                                 <xsl:attribute name="authority">marccountry</xsl:attribute>
900                                                 <xsl:value-of select="$MARCpublicationCode"/>
901                                         </placeTerm>
902                                 </place>
903                         </xsl:if>
904                         <xsl:for-each select="marc:datafield[@tag=044]/marc:subfield[@code='c']">
905                                 <place>
906                                         <placeTerm>
907                                                 <xsl:attribute name="type">code</xsl:attribute>
908                                                 <xsl:attribute name="authority">iso3166</xsl:attribute>
909                                                 <xsl:value-of select="."/>
910                                         </placeTerm>
911                                 </place>
912                         </xsl:for-each>
913                         <xsl:for-each select="marc:datafield[@tag=260]/marc:subfield[@code='a']">
914                                 <place>
915                                         <placeTerm>
916                                                 <xsl:attribute name="type">text</xsl:attribute>
917                                                 <xsl:call-template name="chopPunctuationFront">
918                                                         <xsl:with-param name="chopString">
919                                                                 <xsl:call-template name="chopPunctuation">
920                                                                         <xsl:with-param name="chopString" select="."/>
921                                                                 </xsl:call-template>
922                                                         </xsl:with-param>
923                                                 </xsl:call-template>
924                                         </placeTerm>
925                                 </place>
926                         </xsl:for-each>
927                         <xsl:for-each select="marc:datafield[@tag=046]/marc:subfield[@code='m']">
928                                 <dateValid point="start">
929                                         <xsl:value-of select="."/>
930                                 </dateValid>
931                         </xsl:for-each>
932                         <xsl:for-each select="marc:datafield[@tag=046]/marc:subfield[@code='n']">
933                                 <dateValid point="end">
934                                         <xsl:value-of select="."/>
935                                 </dateValid>
936                         </xsl:for-each>
937                         <xsl:for-each select="marc:datafield[@tag=046]/marc:subfield[@code='j']">
938                                 <dateModified>
939                                         <xsl:value-of select="."/>
940                                 </dateModified>
941                         </xsl:for-each>
942                         <xsl:for-each select="marc:datafield[@tag=260]/marc:subfield[@code='b' or @code='c' or @code='g']">
943                                 <xsl:choose>
944                                         <xsl:when test="@code='b'">
945                                                 <publisher>
946                                                         <xsl:call-template name="chopPunctuation">
947                                                                 <xsl:with-param name="chopString" select="."/>
948                                                                 <xsl:with-param name="punctuation">
949                                                                         <xsl:text>:,;/ </xsl:text>
950                                                                 </xsl:with-param>
951                                                         </xsl:call-template>
952                                                 </publisher>
953                                         </xsl:when>
954                                         <xsl:when test="@code='c'">
955                                                 <dateIssued>
956                                                         <xsl:call-template name="chopPunctuation">
957                                                                 <xsl:with-param name="chopString" select="."/>
958                                                         </xsl:call-template>
959                                                 </dateIssued>
960                                         </xsl:when>
961                                         <xsl:when test="@code='g'">
962                                                 <dateCreated>
963                                                         <xsl:value-of select="."/>
964                                                 </dateCreated>
965                                         </xsl:when>
966                                 </xsl:choose>
967                         </xsl:for-each>
968                         <xsl:variable name="dataField260c">
969                                 <xsl:call-template name="chopPunctuation">
970                                         <xsl:with-param name="chopString" select="marc:datafield[@tag=260]/marc:subfield[@code='c']"></xsl:with-param>
971                                 </xsl:call-template>
972                         </xsl:variable>
973                         <xsl:variable name="controlField008-7-10" select="normalize-space(substring($controlField008, 8, 4))"></xsl:variable>
974                         <xsl:variable name="controlField008-11-14" select="normalize-space(substring($controlField008, 12, 4))"></xsl:variable>
975                         <xsl:variable name="controlField008-6" select="normalize-space(substring($controlField008, 7, 1))"></xsl:variable>
976                         <xsl:if test="$controlField008-6='e' or $controlField008-6='p' or $controlField008-6='r' or $controlField008-6='t' or $controlField008-6='s'">
977                                 <xsl:if test="$controlField008-7-10 and ($controlField008-7-10 != $dataField260c)">
978                                         <dateIssued encoding="marc">
979                                                 <xsl:value-of select="$controlField008-7-10"/>
980                                         </dateIssued>
981                                 </xsl:if>
982                         </xsl:if>
983                         <xsl:if test="$controlField008-6='c' or $controlField008-6='d' or $controlField008-6='i' or $controlField008-6='k' or $controlField008-6='m' or $controlField008-6='q' or $controlField008-6='u'">
984                                 <xsl:if test="$controlField008-7-10">
985                                         <dateIssued encoding="marc" point="start">
986                                                 <xsl:value-of select="$controlField008-7-10"/>
987                                         </dateIssued>
988                                 </xsl:if>
989                         </xsl:if>
990                         <xsl:if test="$controlField008-6='c' or $controlField008-6='d' or $controlField008-6='i' or $controlField008-6='k' or $controlField008-6='m' or $controlField008-6='q' or $controlField008-6='u'">
991                                 <xsl:if test="$controlField008-11-14">
992                                         <dateIssued encoding="marc" point="end">
993                                                 <xsl:value-of select="$controlField008-11-14"/>
994                                         </dateIssued>
995                                 </xsl:if>
996                         </xsl:if>
997                         <xsl:if test="$controlField008-6='q'">
998                                 <xsl:if test="$controlField008-7-10">
999                                         <dateIssued encoding="marc" point="start" qualifier="questionable">
1000                                                 <xsl:value-of select="$controlField008-7-10"/>
1001                                         </dateIssued>
1002                                 </xsl:if>
1003                         </xsl:if>
1004                         <xsl:if test="$controlField008-6='q'">
1005                                 <xsl:if test="$controlField008-11-14">
1006                                         <dateIssued encoding="marc" point="end" qualifier="questionable">
1007                                                 <xsl:value-of select="$controlField008-11-14"/>
1008                                         </dateIssued>
1009                                 </xsl:if>
1010                         </xsl:if>
1011                         <xsl:if test="$controlField008-6='t'">
1012                                 <xsl:if test="$controlField008-11-14">
1013                                         <copyrightDate encoding="marc">
1014                                                 <xsl:value-of select="$controlField008-11-14"/>
1015                                         </copyrightDate>
1016                                 </xsl:if>
1017                         </xsl:if>
1018                         <xsl:for-each select="marc:datafield[@tag=033][@ind1=0 or @ind1=1]/marc:subfield[@code='a']">
1019                                 <dateCaptured encoding="iso8601">
1020                                         <xsl:value-of select="."/>
1021                                 </dateCaptured>
1022                         </xsl:for-each>
1023                         <xsl:for-each select="marc:datafield[@tag=033][@ind1=2]/marc:subfield[@code='a'][1]">
1024                                 <dateCaptured encoding="iso8601" point="start">
1025                                         <xsl:value-of select="."/>
1026                                 </dateCaptured>
1027                         </xsl:for-each>
1028                         <xsl:for-each select="marc:datafield[@tag=033][@ind1=2]/marc:subfield[@code='a'][2]">
1029                                 <dateCaptured encoding="iso8601" point="end">
1030                                         <xsl:value-of select="."/>
1031                                 </dateCaptured>
1032                         </xsl:for-each>
1033                         <xsl:for-each select="marc:datafield[@tag=250]/marc:subfield[@code='a']">
1034                                 <edition>
1035                                         <xsl:value-of select="."/>
1036                                 </edition>
1037                         </xsl:for-each>
1038                         <xsl:for-each select="marc:leader">
1039                                 <issuance>
1040                                         <xsl:choose>
1041                                                 <xsl:when test="$leader7='a' or $leader7='c' or $leader7='d' or $leader7='m'">monographic</xsl:when>
1042                                                 <xsl:when test="$leader7='b' or $leader7='i' or $leader7='s'">continuing</xsl:when>
1043                                         </xsl:choose>
1044                                 </issuance>
1045                         </xsl:for-each>
1046                         <xsl:for-each select="marc:datafield[@tag=310]|marc:datafield[@tag=321]">
1047                                 <frequency>
1048                                         <xsl:call-template name="subfieldSelect">
1049                                                 <xsl:with-param name="codes">ab</xsl:with-param>
1050                                         </xsl:call-template>
1051                                 </frequency>
1052                         </xsl:for-each>
1053                 </originInfo>
1054                 <xsl:variable name="controlField008-35-37" select="normalize-space(translate(substring($controlField008,36,3),'|#',''))"></xsl:variable>
1055                 <xsl:if test="$controlField008-35-37">
1056                         <language>
1057                                 <languageTerm authority="iso639-2b" type="code">
1058                                         <xsl:value-of select="substring($controlField008,36,3)"/>
1059                                 </languageTerm>
1060                         </language>
1061                 </xsl:if>
1062                 <xsl:for-each select="marc:datafield[@tag=041]">
1063                         <xsl:for-each select="marc:subfield[@code='a' or @code='b' or @code='d' or @code='e' or @code='f' or @code='g' or @code='h']">
1064                                 <xsl:variable name="langCodes" select="."/>
1065                                 <xsl:choose>
1066                                         <xsl:when test="../marc:subfield[@code='2']='rfc3066'">
1067                                                 <!-- not stacked but could be repeated -->
1068                                                 <xsl:call-template name="rfcLanguages">
1069                                                         <xsl:with-param name="nodeNum">
1070                                                                 <xsl:value-of select="1"/>
1071                                                         </xsl:with-param>
1072                                                         <xsl:with-param name="usedLanguages">
1073                                                                 <xsl:text></xsl:text>
1074                                                         </xsl:with-param>
1075                                                         <xsl:with-param name="controlField008-35-37">
1076                                                                 <xsl:value-of select="$controlField008-35-37"></xsl:value-of>
1077                                                         </xsl:with-param>
1078                                                 </xsl:call-template>
1079                                         </xsl:when>
1080                                         <xsl:otherwise>
1081                                                 <!-- iso -->
1082                                                 <xsl:variable name="allLanguages">
1083                                                         <xsl:copy-of select="$langCodes"></xsl:copy-of>
1084                                                 </xsl:variable>
1085                                                 <xsl:variable name="currentLanguage">
1086                                                         <xsl:value-of select="substring($allLanguages,1,3)"></xsl:value-of>
1087                                                 </xsl:variable>
1088                                                 <xsl:call-template name="isoLanguage">
1089                                                         <xsl:with-param name="currentLanguage">
1090                                                                 <xsl:value-of select="substring($allLanguages,1,3)"></xsl:value-of>
1091                                                         </xsl:with-param>
1092                                                         <xsl:with-param name="remainingLanguages">
1093                                                                 <xsl:value-of select="substring($allLanguages,4,string-length($allLanguages)-3)"></xsl:value-of>
1094                                                         </xsl:with-param>
1095                                                         <xsl:with-param name="usedLanguages">
1096                                                                 <xsl:if test="$controlField008-35-37">
1097                                                                         <xsl:value-of select="$controlField008-35-37"></xsl:value-of>
1098                                                                 </xsl:if>
1099                                                         </xsl:with-param>
1100                                                 </xsl:call-template>
1101                                         </xsl:otherwise>
1102                                 </xsl:choose>
1103                         </xsl:for-each>
1104                 </xsl:for-each>
1105                 <xsl:variable name="physicalDescription">
1106                         <!--3.2 change tmee 007/11 -->
1107                         <xsl:if test="$typeOf008='CF' and marc:controlfield[@tag=007][substring(.,12,1)='a']">
1108                                 <digitalOrigin>reformatted digital</digitalOrigin>
1109                         </xsl:if>
1110                         <xsl:if test="$typeOf008='CF' and marc:controlfield[@tag=007][substring(.,12,1)='b']">
1111                                 <digitalOrigin>digitized microfilm</digitalOrigin>
1112                         </xsl:if>
1113                         <xsl:if test="$typeOf008='CF' and marc:controlfield[@tag=007][substring(.,12,1)='d']">
1114                                 <digitalOrigin>digitized other analog</digitalOrigin>
1115                         </xsl:if>
1116                         <xsl:variable name="controlField008-23" select="substring($controlField008,24,1)"></xsl:variable>
1117                         <xsl:variable name="controlField008-29" select="substring($controlField008,30,1)"></xsl:variable>
1118                         <xsl:variable name="check008-23">
1119                                 <xsl:if test="$typeOf008='BK' or $typeOf008='MU' or $typeOf008='SE' or $typeOf008='MM'">
1120                                         <xsl:value-of select="true()"></xsl:value-of>
1121                                 </xsl:if>
1122                         </xsl:variable>
1123                         <xsl:variable name="check008-29">
1124                                 <xsl:if test="$typeOf008='MP' or $typeOf008='VM'">
1125                                         <xsl:value-of select="true()"></xsl:value-of>
1126                                 </xsl:if>
1127                         </xsl:variable>
1128                         <xsl:choose>
1129                                 <xsl:when test="($check008-23 and $controlField008-23='f') or ($check008-29 and $controlField008-29='f')">
1130                                         <form authority="marcform">braille</form>
1131                                 </xsl:when>
1132                                 <xsl:when test="($controlField008-23=' ' and ($leader6='c' or $leader6='d')) or (($typeOf008='BK' or $typeOf008='SE') and ($controlField008-23=' ' or $controlField008='r'))">
1133                                         <form authority="marcform">print</form>
1134                                 </xsl:when>
1135                                 <xsl:when test="$leader6 = 'm' or ($check008-23 and $controlField008-23='s') or ($check008-29 and $controlField008-29='s')">
1136                                         <form authority="marcform">electronic</form>
1137                                 </xsl:when>
1138                                 <xsl:when test="($check008-23 and $controlField008-23='b') or ($check008-29 and $controlField008-29='b')">
1139                                         <form authority="marcform">microfiche</form>
1140                                 </xsl:when>
1141                                 <xsl:when test="($check008-23 and $controlField008-23='a') or ($check008-29 and $controlField008-29='a')">
1142                                         <form authority="marcform">microfilm</form>
1143                                 </xsl:when>
1144                         </xsl:choose>
1145                         <!-- 1/04 fix -->
1146                         <xsl:if test="marc:datafield[@tag=130]/marc:subfield[@code='h']">
1147                                 <form authority="gmd">
1148                                         <xsl:call-template name="chopBrackets">
1149                                                 <xsl:with-param name="chopString">
1150                                                         <xsl:value-of select="marc:datafield[@tag=130]/marc:subfield[@code='h']"></xsl:value-of>
1151                                                 </xsl:with-param>
1152                                         </xsl:call-template>
1153                                 </form>
1154                         </xsl:if>
1155                         <xsl:if test="marc:datafield[@tag=240]/marc:subfield[@code='h']">
1156                                 <form authority="gmd">
1157                                         <xsl:call-template name="chopBrackets">
1158                                                 <xsl:with-param name="chopString">
1159                                                         <xsl:value-of select="marc:datafield[@tag=240]/marc:subfield[@code='h']"></xsl:value-of>
1160                                                 </xsl:with-param>
1161                                         </xsl:call-template>
1162                                 </form>
1163                         </xsl:if>
1164                         <xsl:if test="marc:datafield[@tag=242]/marc:subfield[@code='h']">
1165                                 <form authority="gmd">
1166                                         <xsl:call-template name="chopBrackets">
1167                                                 <xsl:with-param name="chopString">
1168                                                         <xsl:value-of select="marc:datafield[@tag=242]/marc:subfield[@code='h']"></xsl:value-of>
1169                                                 </xsl:with-param>
1170                                         </xsl:call-template>
1171                                 </form>
1172                         </xsl:if>
1173                         <xsl:if test="marc:datafield[@tag=245]/marc:subfield[@code='h']">
1174                                 <form authority="gmd">
1175                                         <xsl:call-template name="chopBrackets">
1176                                                 <xsl:with-param name="chopString">
1177                                                         <xsl:value-of select="marc:datafield[@tag=245]/marc:subfield[@code='h']"></xsl:value-of>
1178                                                 </xsl:with-param>
1179                                         </xsl:call-template>
1180                                 </form>
1181                         </xsl:if>
1182                         <xsl:if test="marc:datafield[@tag=246]/marc:subfield[@code='h']">
1183                                 <form authority="gmd">
1184                                         <xsl:call-template name="chopBrackets">
1185                                                 <xsl:with-param name="chopString">
1186                                                         <xsl:value-of select="marc:datafield[@tag=246]/marc:subfield[@code='h']"></xsl:value-of>
1187                                                 </xsl:with-param>
1188                                         </xsl:call-template>
1189                                 </form>
1190                         </xsl:if>
1191                         <xsl:if test="marc:datafield[@tag=730]/marc:subfield[@code='h']">
1192                                 <form authority="gmd">
1193                                         <xsl:call-template name="chopBrackets">
1194                                                 <xsl:with-param name="chopString">
1195                                                         <xsl:value-of select="marc:datafield[@tag=730]/marc:subfield[@code='h']"></xsl:value-of>
1196                                                 </xsl:with-param>
1197                                         </xsl:call-template>
1198                                 </form>
1199                         </xsl:if>
1200                         <xsl:for-each select="marc:datafield[@tag=256]/marc:subfield[@code='a']">
1201                                 <form>
1202                                         <xsl:value-of select="."></xsl:value-of>
1203                                 </form>
1204                         </xsl:for-each>
1205                         <xsl:for-each select="marc:controlfield[@tag=007][substring(text(),1,1)='c']">
1206                                 <xsl:choose>
1207                                         <xsl:when test="substring(text(),14,1)='a'">
1208                                                 <reformattingQuality>access</reformattingQuality>
1209                                         </xsl:when>
1210                                         <xsl:when test="substring(text(),14,1)='p'">
1211                                                 <reformattingQuality>preservation</reformattingQuality>
1212                                         </xsl:when>
1213                                         <xsl:when test="substring(text(),14,1)='r'">
1214                                                 <reformattingQuality>replacement</reformattingQuality>
1215                                         </xsl:when>
1216                                 </xsl:choose>
1217                         </xsl:for-each>
1218                         <!--3.2 change tmee 007/01 -->
1219                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='b']">
1220                                 <form authority="smd">chip cartridge</form>
1221                         </xsl:if>
1222                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='c']">
1223                                 <form authority="smd">computer optical disc cartridge</form>
1224                         </xsl:if>
1225                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='j']">
1226                                 <form authority="smd">magnetic disc</form>
1227                         </xsl:if>
1228                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='m']">
1229                                 <form authority="smd">magneto-optical disc</form>
1230                         </xsl:if>
1231                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='o']">
1232                                 <form authority="smd">optical disc</form>
1233                         </xsl:if>
1234                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='r']">
1235                                 <form authority="smd">remote</form>
1236                         </xsl:if>
1237                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='a']">
1238                                 <form authority="smd">tape cartridge</form>
1239                         </xsl:if>
1240                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='f']">
1241                                 <form authority="smd">tape cassette</form>
1242                         </xsl:if>
1243                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='h']">
1244                                 <form authority="smd">tape reel</form>
1245                         </xsl:if>
1246                         
1247                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='d'][substring(text(),2,1)='a']">
1248                                 <form authority="smd">celestial globe</form>
1249                         </xsl:if>
1250                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='d'][substring(text(),2,1)='e']">
1251                                 <form authority="smd">earth moon globe</form>
1252                         </xsl:if>
1253                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='d'][substring(text(),2,1)='b']">
1254                                 <form authority="smd">planetary or lunar globe</form>
1255                         </xsl:if>
1256                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='d'][substring(text(),2,1)='c']">
1257                                 <form authority="smd">terrestrial globe</form>
1258                         </xsl:if>
1259                         
1260                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='o'][substring(text(),2,1)='o']">
1261                                 <form authority="smd">kit</form>
1262                         </xsl:if>
1263                         
1264                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='d']">
1265                                 <form authority="smd">atlas</form>
1266                         </xsl:if>
1267                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='g']">
1268                                 <form authority="smd">diagram</form>
1269                         </xsl:if>
1270                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='j']">
1271                                 <form authority="smd">map</form>
1272                         </xsl:if>
1273                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='q']">
1274                                 <form authority="smd">model</form>
1275                         </xsl:if>
1276                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='k']">
1277                                 <form authority="smd">profile</form>
1278                         </xsl:if>
1279                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='r']">
1280                                 <form authority="smd">remote-sensing image</form>
1281                         </xsl:if>
1282                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='s']">
1283                                 <form authority="smd">section</form>
1284                         </xsl:if>
1285                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='y']">
1286                                 <form authority="smd">view</form>
1287                         </xsl:if>
1288                         
1289                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='a']">
1290                                 <form authority="smd">aperture card</form>
1291                         </xsl:if>
1292                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='e']">
1293                                 <form authority="smd">microfiche</form>
1294                         </xsl:if>
1295                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='f']">
1296                                 <form authority="smd">microfiche cassette</form>
1297                         </xsl:if>
1298                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='b']">
1299                                 <form authority="smd">microfilm cartridge</form>
1300                         </xsl:if>
1301                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='c']">
1302                                 <form authority="smd">microfilm cassette</form>
1303                         </xsl:if>
1304                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='d']">
1305                                 <form authority="smd">microfilm reel</form>
1306                         </xsl:if>
1307                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='g']">
1308                                 <form authority="smd">microopaque</form>
1309                         </xsl:if>
1310                         
1311                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='m'][substring(text(),2,1)='c']">
1312                                 <form authority="smd">film cartridge</form>
1313                         </xsl:if>
1314                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='m'][substring(text(),2,1)='f']">
1315                                 <form authority="smd">film cassette</form>
1316                         </xsl:if>
1317                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='m'][substring(text(),2,1)='r']">
1318                                 <form authority="smd">film reel</form>
1319                         </xsl:if>
1320                         
1321                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='n']">
1322                                 <form authority="smd">chart</form>
1323                         </xsl:if>
1324                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='c']">
1325                                 <form authority="smd">collage</form>
1326                         </xsl:if>
1327                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='d']">
1328                                 <form authority="smd">drawing</form>
1329                         </xsl:if>
1330                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='o']">
1331                                 <form authority="smd">flash card</form>
1332                         </xsl:if>
1333                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='e']">
1334                                 <form authority="smd">painting</form>
1335                         </xsl:if>
1336                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='f']">
1337                                 <form authority="smd">photomechanical print</form>
1338                         </xsl:if>
1339                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='g']">
1340                                 <form authority="smd">photonegative</form>
1341                         </xsl:if>
1342                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='h']">
1343                                 <form authority="smd">photoprint</form>
1344                         </xsl:if>
1345                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='i']">
1346                                 <form authority="smd">picture</form>
1347                         </xsl:if>
1348                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='j']">
1349                                 <form authority="smd">print</form>
1350                         </xsl:if>
1351                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='l']">
1352                                 <form authority="smd">technical drawing</form>
1353                         </xsl:if>
1354                         
1355                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='q'][substring(text(),2,1)='q']">
1356                                 <form authority="smd">notated music</form>
1357                         </xsl:if>
1358                         
1359                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='d']">
1360                                 <form authority="smd">filmslip</form>
1361                         </xsl:if>
1362                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='c']">
1363                                 <form authority="smd">filmstrip cartridge</form>
1364                         </xsl:if>
1365                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='o']">
1366                                 <form authority="smd">filmstrip roll</form>
1367                         </xsl:if>
1368                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='f']">
1369                                 <form authority="smd">other filmstrip type</form>
1370                         </xsl:if>
1371                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='s']">
1372                                 <form authority="smd">slide</form>
1373                         </xsl:if>
1374                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='t']">
1375                                 <form authority="smd">transparency</form>
1376                         </xsl:if>
1377                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='r'][substring(text(),2,1)='r']">
1378                                 <form authority="smd">remote-sensing image</form>
1379                         </xsl:if>
1380                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='e']">
1381                                 <form authority="smd">cylinder</form>
1382                         </xsl:if>
1383                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='q']">
1384                                 <form authority="smd">roll</form>
1385                         </xsl:if>
1386                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='g']">
1387                                 <form authority="smd">sound cartridge</form>
1388                         </xsl:if>
1389                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='s']">
1390                                 <form authority="smd">sound cassette</form>
1391                         </xsl:if>
1392                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='d']">
1393                                 <form authority="smd">sound disc</form>
1394                         </xsl:if>
1395                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='t']">
1396                                 <form authority="smd">sound-tape reel</form>
1397                         </xsl:if>
1398                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='i']">
1399                                 <form authority="smd">sound-track film</form>
1400                         </xsl:if>
1401                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='w']">
1402                                 <form authority="smd">wire recording</form>
1403                         </xsl:if>
1404                         
1405                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='f'][substring(text(),2,1)='c']">
1406                                 <form authority="smd">braille</form>
1407                         </xsl:if>
1408                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='f'][substring(text(),2,1)='b']">
1409                                 <form authority="smd">combination</form>
1410                         </xsl:if>
1411                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='f'][substring(text(),2,1)='a']">
1412                                 <form authority="smd">moon</form>
1413                         </xsl:if>
1414                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='f'][substring(text(),2,1)='d']">
1415                                 <form authority="smd">tactile, with no writing system</form>
1416                         </xsl:if>
1417                         
1418                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='t'][substring(text(),2,1)='c']">
1419                                 <form authority="smd">braille</form>
1420                         </xsl:if>
1421                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='t'][substring(text(),2,1)='b']">
1422                                 <form authority="smd">large print</form>
1423                         </xsl:if>
1424                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='t'][substring(text(),2,1)='a']">
1425                                 <form authority="smd">regular print</form>
1426                         </xsl:if>
1427                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='t'][substring(text(),2,1)='d']">
1428                                 <form authority="smd">text in looseleaf binder</form>
1429                         </xsl:if>
1430                         
1431                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='v'][substring(text(),2,1)='c']">
1432                                 <form authority="smd">videocartridge</form>
1433                         </xsl:if>
1434                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='v'][substring(text(),2,1)='f']">
1435                                 <form authority="smd">videocassette</form>
1436                         </xsl:if>
1437                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='v'][substring(text(),2,1)='d']">
1438                                 <form authority="smd">videodisc</form>
1439                         </xsl:if>
1440                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='v'][substring(text(),2,1)='r']">
1441                                 <form authority="smd">videoreel</form>
1442                         </xsl:if>
1443                         
1444                         <xsl:for-each select="marc:datafield[@tag=856]/marc:subfield[@code='q'][string-length(.)>1]">
1445                                 <internetMediaType>
1446                                         <xsl:value-of select="."></xsl:value-of>
1447                                 </internetMediaType>
1448                         </xsl:for-each>
1449                         <xsl:for-each select="marc:datafield[@tag=300]">
1450                                 <extent>
1451                                         <xsl:call-template name="subfieldSelect">
1452                                                 <xsl:with-param name="codes">abce</xsl:with-param>
1453                                         </xsl:call-template>
1454                                 </extent>
1455                         </xsl:for-each>
1456                 </xsl:variable>
1457                 <xsl:if test="string-length(normalize-space($physicalDescription))">
1458                         <physicalDescription>
1459                                 <xsl:copy-of select="$physicalDescription"></xsl:copy-of>
1460                         </physicalDescription>
1461                 </xsl:if>
1462                 <xsl:for-each select="marc:datafield[@tag=520]">
1463                         <abstract>
1464                                 <xsl:call-template name="uri"></xsl:call-template>
1465                                 <xsl:call-template name="subfieldSelect">
1466                                         <xsl:with-param name="codes">ab</xsl:with-param>
1467                                 </xsl:call-template>
1468                         </abstract>
1469                 </xsl:for-each>
1470                 <xsl:for-each select="marc:datafield[@tag=505]">
1471                         <tableOfContents>
1472                                 <xsl:call-template name="uri"></xsl:call-template>
1473                                 <xsl:call-template name="subfieldSelect">
1474                                         <xsl:with-param name="codes">agrt</xsl:with-param>
1475                                 </xsl:call-template>
1476                         </tableOfContents>
1477                 </xsl:for-each>
1478                 <xsl:for-each select="marc:datafield[@tag=521]">
1479                         <targetAudience>
1480                                 <xsl:call-template name="subfieldSelect">
1481                                         <xsl:with-param name="codes">ab</xsl:with-param>
1482                                 </xsl:call-template>
1483                         </targetAudience>
1484                 </xsl:for-each>
1485                 <xsl:if test="$typeOf008='BK' or $typeOf008='CF' or $typeOf008='MU' or $typeOf008='VM'">
1486                         <xsl:variable name="controlField008-22" select="substring($controlField008,23,1)"></xsl:variable>
1487                         <xsl:choose>
1488                                 <!-- 01/04 fix -->
1489                                 <xsl:when test="$controlField008-22='d'">
1490                                         <targetAudience authority="marctarget">adolescent</targetAudience>
1491                                 </xsl:when>
1492                                 <xsl:when test="$controlField008-22='e'">
1493                                         <targetAudience authority="marctarget">adult</targetAudience>
1494                                 </xsl:when>
1495                                 <xsl:when test="$controlField008-22='g'">
1496                                         <targetAudience authority="marctarget">general</targetAudience>
1497                                 </xsl:when>
1498                                 <xsl:when test="$controlField008-22='b' or $controlField008-22='c' or $controlField008-22='j'">
1499                                         <targetAudience authority="marctarget">juvenile</targetAudience>
1500                                 </xsl:when>
1501                                 <xsl:when test="$controlField008-22='a'">
1502                                         <targetAudience authority="marctarget">preschool</targetAudience>
1503                                 </xsl:when>
1504                                 <xsl:when test="$controlField008-22='f'">
1505                                         <targetAudience authority="marctarget">specialized</targetAudience>
1506                                 </xsl:when>
1507                         </xsl:choose>
1508                 </xsl:if>
1509                 <xsl:for-each select="marc:datafield[@tag=245]/marc:subfield[@code='c']">
1510                         <note type="statement of responsibility">
1511                                 <xsl:value-of select="."></xsl:value-of>
1512                         </note>
1513                 </xsl:for-each>
1514                 <xsl:for-each select="marc:datafield[@tag=500]">
1515                         <note>
1516                                 <xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
1517                                 <xsl:call-template name="uri"></xsl:call-template>
1518                         </note>
1519                 </xsl:for-each>
1520                 
1521                 <!--3.2 change tmee additional note fields-->
1522                 
1523                 <xsl:for-each select="marc:datafield[@tag=506]">
1524                         <note type="restrictions">
1525                                 <xsl:call-template name="uri"></xsl:call-template>
1526                                 <xsl:variable name="str">
1527                                         <xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
1528                                                 <xsl:value-of select="."></xsl:value-of>
1529                                                 <xsl:text> </xsl:text>
1530                                         </xsl:for-each>
1531                                 </xsl:variable>
1532                                 <xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
1533                         </note>
1534                 </xsl:for-each>
1535                 
1536                 <xsl:for-each select="marc:datafield[@tag=510]">
1537                         <note  type="citation/reference">
1538                                 <xsl:call-template name="uri"></xsl:call-template>
1539                                 <xsl:variable name="str">
1540                                         <xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
1541                                                 <xsl:value-of select="."></xsl:value-of>
1542                                                 <xsl:text> </xsl:text>
1543                                         </xsl:for-each>
1544                                 </xsl:variable>
1545                                 <xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
1546                         </note>
1547                 </xsl:for-each>
1548                 
1549                         
1550                 <xsl:for-each select="marc:datafield[@tag=511]">
1551                         <note type="performers">
1552                                 <xsl:call-template name="uri"></xsl:call-template>
1553                                 <xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
1554                         </note>
1555                 </xsl:for-each>
1556                 <xsl:for-each select="marc:datafield[@tag=518]">
1557                         <note type="venue">
1558                                 <xsl:call-template name="uri"></xsl:call-template>
1559                                 <xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
1560                         </note>
1561                 </xsl:for-each>
1562                 
1563                 <xsl:for-each select="marc:datafield[@tag=530]">
1564                         <note  type="additional physical form">
1565                                 <xsl:call-template name="uri"></xsl:call-template>
1566                                 <xsl:variable name="str">
1567                                         <xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
1568                                                 <xsl:value-of select="."></xsl:value-of>
1569                                                 <xsl:text> </xsl:text>
1570                                         </xsl:for-each>
1571                                 </xsl:variable>
1572                                 <xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
1573                         </note>
1574                 </xsl:for-each>
1575                 
1576                 <xsl:for-each select="marc:datafield[@tag=533]">
1577                         <note  type="reproduction">
1578                                 <xsl:call-template name="uri"></xsl:call-template>
1579                                 <xsl:variable name="str">
1580                                         <xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
1581                                                 <xsl:value-of select="."></xsl:value-of>
1582                                                 <xsl:text> </xsl:text>
1583                                         </xsl:for-each>
1584                                 </xsl:variable>
1585                                 <xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
1586                         </note>
1587                 </xsl:for-each>
1588                 
1589                 <xsl:for-each select="marc:datafield[@tag=534]">
1590                         <note  type="original version">
1591                                 <xsl:call-template name="uri"></xsl:call-template>
1592                                 <xsl:variable name="str">
1593                                         <xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
1594                                                 <xsl:value-of select="."></xsl:value-of>
1595                                                 <xsl:text> </xsl:text>
1596                                         </xsl:for-each>
1597                                 </xsl:variable>
1598                                 <xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
1599                         </note>
1600                 </xsl:for-each>
1601                 
1602                 <xsl:for-each select="marc:datafield[@tag=538]">
1603                         <note  type="system details">
1604                                 <xsl:call-template name="uri"></xsl:call-template>
1605                                 <xsl:variable name="str">
1606                                         <xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
1607                                                 <xsl:value-of select="."></xsl:value-of>
1608                                                 <xsl:text> </xsl:text>
1609                                         </xsl:for-each>
1610                                 </xsl:variable>
1611                                 <xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
1612                         </note>
1613                 </xsl:for-each>
1614                 
1615                 <xsl:for-each select="marc:datafield[@tag=583]">
1616                         <note type="action">
1617                                 <xsl:call-template name="uri"></xsl:call-template>
1618                                 <xsl:variable name="str">
1619                                         <xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
1620                                                 <xsl:value-of select="."></xsl:value-of>
1621                                                 <xsl:text> </xsl:text>
1622                                         </xsl:for-each>
1623                                 </xsl:variable>
1624                                 <xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
1625                         </note>
1626                 </xsl:for-each>
1627                 
1628
1629                 
1630                 
1631                 
1632                 <xsl:for-each select="marc:datafield[@tag=501 or @tag=502 or @tag=504 or @tag=507 or @tag=508 or  @tag=513 or @tag=514 or @tag=515 or @tag=516 or @tag=522 or @tag=524 or @tag=525 or @tag=526 or @tag=535 or @tag=536 or @tag=540 or @tag=541 or @tag=544 or @tag=545 or @tag=546 or @tag=547 or @tag=550 or @tag=552 or @tag=555 or @tag=556 or @tag=561 or @tag=562 or @tag=565 or @tag=567 or @tag=580 or @tag=581 or @tag=584 or @tag=585 or @tag=586]">
1633                         <note>
1634                                 <xsl:call-template name="uri"></xsl:call-template>
1635                                 <xsl:variable name="str">
1636                                         <xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
1637                                                 <xsl:value-of select="."></xsl:value-of>
1638                                                 <xsl:text> </xsl:text>
1639                                         </xsl:for-each>
1640                                 </xsl:variable>
1641                                 <xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
1642                         </note>
1643                 </xsl:for-each>
1644                 <xsl:for-each select="marc:datafield[@tag=034][marc:subfield[@code='d' or @code='e' or @code='f' or @code='g']]">
1645                         <subject>
1646                                 <cartographics>
1647                                         <coordinates>
1648                                                 <xsl:call-template name="subfieldSelect">
1649                                                         <xsl:with-param name="codes">defg</xsl:with-param>
1650                                                 </xsl:call-template>
1651                                         </coordinates>
1652                                 </cartographics>
1653                         </subject>
1654                 </xsl:for-each>
1655                 <xsl:for-each select="marc:datafield[@tag=043]">
1656                         <subject>
1657                                 <xsl:for-each select="marc:subfield[@code='a' or @code='b' or @code='c']">
1658                                         <geographicCode>
1659                                                 <xsl:attribute name="authority">
1660                                                         <xsl:if test="@code='a'">
1661                                                                 <xsl:text>marcgac</xsl:text>
1662                                                         </xsl:if>
1663                                                         <xsl:if test="@code='b'">
1664                                                                 <xsl:value-of select="following-sibling::marc:subfield[@code=2]"></xsl:value-of>
1665                                                         </xsl:if>
1666                                                         <xsl:if test="@code='c'">
1667                                                                 <xsl:text>iso3166</xsl:text>
1668                                                         </xsl:if>
1669                                                 </xsl:attribute>
1670                                                 <xsl:value-of select="self::marc:subfield"></xsl:value-of>
1671                                         </geographicCode>
1672                                 </xsl:for-each>
1673                         </subject>
1674                 </xsl:for-each>
1675                 <!-- tmee 2006/11/27 -->
1676                 <xsl:for-each select="marc:datafield[@tag=255]">
1677                         <subject>
1678                                 <xsl:for-each select="marc:subfield[@code='a' or @code='b' or @code='c']">
1679                                 <cartographics>
1680                                         <xsl:if test="@code='a'">
1681                                                 <scale>
1682                                                         <xsl:value-of select="."></xsl:value-of>
1683                                                 </scale>
1684                                         </xsl:if>
1685                                         <xsl:if test="@code='b'">
1686                                                 <projection>
1687                                                         <xsl:value-of select="."></xsl:value-of>
1688                                                 </projection>
1689                                         </xsl:if>
1690                                         <xsl:if test="@code='c'">
1691                                                 <coordinates>
1692                                                         <xsl:value-of select="."></xsl:value-of>
1693                                                 </coordinates>
1694                                         </xsl:if>
1695                                 </cartographics>
1696                                 </xsl:for-each>
1697                         </subject>
1698                 </xsl:for-each>
1699                                 
1700                 <xsl:apply-templates select="marc:datafield[653 >= @tag and @tag >= 600]"></xsl:apply-templates>
1701                 <xsl:apply-templates select="marc:datafield[@tag=656]"></xsl:apply-templates>
1702                 <xsl:for-each select="marc:datafield[@tag=752]">
1703                         <subject>
1704                                 <hierarchicalGeographic>
1705                                         <xsl:for-each select="marc:subfield[@code='a']">
1706                                                 <country>
1707                                                         <xsl:call-template name="chopPunctuation">
1708                                                                 <xsl:with-param name="chopString" select="."></xsl:with-param>
1709                                                         </xsl:call-template>
1710                                                 </country>
1711                                         </xsl:for-each>
1712                                         <xsl:for-each select="marc:subfield[@code='b']">
1713                                                 <state>
1714                                                         <xsl:call-template name="chopPunctuation">
1715                                                                 <xsl:with-param name="chopString" select="."></xsl:with-param>
1716                                                         </xsl:call-template>
1717                                                 </state>
1718                                         </xsl:for-each>
1719                                         <xsl:for-each select="marc:subfield[@code='c']">
1720                                                 <county>
1721                                                         <xsl:call-template name="chopPunctuation">
1722                                                                 <xsl:with-param name="chopString" select="."></xsl:with-param>
1723                                                         </xsl:call-template>
1724                                                 </county>
1725                                         </xsl:for-each>
1726                                         <xsl:for-each select="marc:subfield[@code='d']">
1727                                                 <city>
1728                                                         <xsl:call-template name="chopPunctuation">
1729                                                                 <xsl:with-param name="chopString" select="."></xsl:with-param>
1730                                                         </xsl:call-template>
1731                                                 </city>
1732                                         </xsl:for-each>
1733                                 </hierarchicalGeographic>
1734                         </subject>
1735                 </xsl:for-each>
1736                 <xsl:for-each select="marc:datafield[@tag=045][marc:subfield[@code='b']]">
1737                         <subject>
1738                                 <xsl:choose>
1739                                         <xsl:when test="@ind1=2">
1740                                                 <temporal encoding="iso8601" point="start">
1741                                                         <xsl:call-template name="chopPunctuation">
1742                                                                 <xsl:with-param name="chopString">
1743                                                                         <xsl:value-of select="marc:subfield[@code='b'][1]"></xsl:value-of>
1744                                                                 </xsl:with-param>
1745                                                         </xsl:call-template>
1746                                                 </temporal>
1747                                                 <temporal encoding="iso8601" point="end">
1748                                                         <xsl:call-template name="chopPunctuation">
1749                                                                 <xsl:with-param name="chopString">
1750                                                                         <xsl:value-of select="marc:subfield[@code='b'][2]"></xsl:value-of>
1751                                                                 </xsl:with-param>
1752                                                         </xsl:call-template>
1753                                                 </temporal>
1754                                         </xsl:when>
1755                                         <xsl:otherwise>
1756                                                 <xsl:for-each select="marc:subfield[@code='b']">
1757                                                         <temporal encoding="iso8601">
1758                                                                 <xsl:call-template name="chopPunctuation">
1759                                                                         <xsl:with-param name="chopString" select="."></xsl:with-param>
1760                                                                 </xsl:call-template>
1761                                                         </temporal>
1762                                                 </xsl:for-each>
1763                                         </xsl:otherwise>
1764                                 </xsl:choose>
1765                         </subject>
1766                 </xsl:for-each>
1767                 <xsl:for-each select="marc:datafield[@tag=050]">
1768                         <xsl:for-each select="marc:subfield[@code='b']">
1769                                 <classification authority="lcc">
1770                                         <xsl:if test="../marc:subfield[@code='3']">
1771                                                 <xsl:attribute name="displayLabel">
1772                                                         <xsl:value-of select="../marc:subfield[@code='3']"></xsl:value-of>
1773                                                 </xsl:attribute>
1774                                         </xsl:if>
1775                                         <xsl:value-of select="preceding-sibling::marc:subfield[@code='a'][1]"></xsl:value-of>
1776                                         <xsl:text> </xsl:text>
1777                                         <xsl:value-of select="text()"></xsl:value-of>
1778                                 </classification>
1779                         </xsl:for-each>
1780                         <xsl:for-each select="marc:subfield[@code='a'][not(following-sibling::marc:subfield[@code='b'])]">
1781                                 <classification authority="lcc">
1782                                         <xsl:if test="../marc:subfield[@code='3']">
1783                                                 <xsl:attribute name="displayLabel">
1784                                                         <xsl:value-of select="../marc:subfield[@code='3']"></xsl:value-of>
1785                                                 </xsl:attribute>
1786                                         </xsl:if>
1787                                         <xsl:value-of select="text()"></xsl:value-of>
1788                                 </classification>
1789                         </xsl:for-each>
1790                 </xsl:for-each>
1791                 <xsl:for-each select="marc:datafield[@tag=082]">
1792                         <classification authority="ddc">
1793                                 <xsl:if test="marc:subfield[@code='2']">
1794                                         <xsl:attribute name="edition">
1795                                                 <xsl:value-of select="marc:subfield[@code='2']"></xsl:value-of>
1796                                         </xsl:attribute>
1797                                 </xsl:if>
1798                                 <xsl:call-template name="subfieldSelect">
1799                                         <xsl:with-param name="codes">ab</xsl:with-param>
1800                                 </xsl:call-template>
1801                         </classification>
1802                 </xsl:for-each>
1803                 <xsl:for-each select="marc:datafield[@tag=080]">
1804                         <classification authority="udc">
1805                                 <xsl:call-template name="subfieldSelect">
1806                                         <xsl:with-param name="codes">abx</xsl:with-param>
1807                                 </xsl:call-template>
1808                         </classification>
1809                 </xsl:for-each>
1810                 <xsl:for-each select="marc:datafield[@tag=060]">
1811                         <classification authority="nlm">
1812                                 <xsl:call-template name="subfieldSelect">
1813                                         <xsl:with-param name="codes">ab</xsl:with-param>
1814                                 </xsl:call-template>
1815                         </classification>
1816                 </xsl:for-each>
1817                 <xsl:for-each select="marc:datafield[@tag=086][@ind1=0]">
1818                         <classification authority="sudocs">
1819                                 <xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
1820                         </classification>
1821                 </xsl:for-each>
1822                 <xsl:for-each select="marc:datafield[@tag=086][@ind1=1]">
1823                         <classification authority="candoc">
1824                                 <xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
1825                         </classification>
1826                 </xsl:for-each>
1827                 <xsl:for-each select="marc:datafield[@tag=086]">
1828                         <classification>
1829                                 <xsl:attribute name="authority">
1830                                         <xsl:value-of select="marc:subfield[@code='2']"></xsl:value-of>
1831                                 </xsl:attribute>
1832                                 <xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
1833                         </classification>
1834                 </xsl:for-each>
1835                 <xsl:for-each select="marc:datafield[@tag=084]">
1836                         <classification>
1837                                 <xsl:attribute name="authority">
1838                                         <xsl:value-of select="marc:subfield[@code='2']"></xsl:value-of>
1839                                 </xsl:attribute>
1840                                 <xsl:call-template name="subfieldSelect">
1841                                         <xsl:with-param name="codes">ab</xsl:with-param>
1842                                 </xsl:call-template>
1843                         </classification>
1844                 </xsl:for-each>
1845                 <xsl:for-each select="marc:datafield[@tag=440]">
1846                         <relatedItem type="series">
1847                                 <titleInfo>
1848                                         <title>
1849                                                 <xsl:call-template name="chopPunctuation">
1850                                                         <xsl:with-param name="chopString">
1851                                                                 <xsl:call-template name="subfieldSelect">
1852                                                                         <xsl:with-param name="codes">av</xsl:with-param>
1853                                                                 </xsl:call-template>
1854                                                         </xsl:with-param>
1855                                                 </xsl:call-template>
1856                                         </title>
1857                                         <xsl:call-template name="part"></xsl:call-template>
1858                                 </titleInfo>
1859                         </relatedItem>
1860                 </xsl:for-each>
1861                 <xsl:for-each select="marc:datafield[@tag=490][@ind1=0]">
1862                         <relatedItem type="series">
1863                                 <titleInfo>
1864                                         <title>
1865                                                 <xsl:call-template name="chopPunctuation">
1866                                                         <xsl:with-param name="chopString">
1867                                                                 <xsl:call-template name="subfieldSelect">
1868                                                                         <xsl:with-param name="codes">av</xsl:with-param>
1869                                                                 </xsl:call-template>
1870                                                         </xsl:with-param>
1871                                                 </xsl:call-template>
1872                                         </title>
1873                                         <xsl:call-template name="part"></xsl:call-template>
1874                                 </titleInfo>
1875                         </relatedItem>
1876                 </xsl:for-each>
1877                 <xsl:for-each select="marc:datafield[@tag=510]">
1878                         <relatedItem type="isReferencedBy">
1879                                 <note>
1880                                         <xsl:call-template name="subfieldSelect">
1881                                                 <xsl:with-param name="codes">abcx3</xsl:with-param>
1882                                         </xsl:call-template>
1883                                 </note>
1884                         </relatedItem>
1885                 </xsl:for-each>
1886                 <xsl:for-each select="marc:datafield[@tag=534]">
1887                         <relatedItem type="original">
1888                                 <xsl:call-template name="relatedTitle"></xsl:call-template>
1889                                 <xsl:call-template name="relatedName"></xsl:call-template>
1890                                 <xsl:if test="marc:subfield[@code='b' or @code='c']">
1891                                         <originInfo>
1892                                                 <xsl:for-each select="marc:subfield[@code='c']">
1893                                                         <publisher>
1894                                                                 <xsl:value-of select="."></xsl:value-of>
1895                                                         </publisher>
1896                                                 </xsl:for-each>
1897                                                 <xsl:for-each select="marc:subfield[@code='b']">
1898                                                         <edition>
1899                                                                 <xsl:value-of select="."></xsl:value-of>
1900                                                         </edition>
1901                                                 </xsl:for-each>
1902                                         </originInfo>
1903                                 </xsl:if>
1904                                 <xsl:call-template name="relatedIdentifierISSN"></xsl:call-template>
1905                                 <xsl:for-each select="marc:subfield[@code='z']">
1906                                         <identifier type="isbn">
1907                                                 <xsl:value-of select="."></xsl:value-of>
1908                                         </identifier>
1909                                 </xsl:for-each>
1910                                 <xsl:call-template name="relatedNote"></xsl:call-template>
1911                         </relatedItem>
1912                 </xsl:for-each>
1913                 <xsl:for-each select="marc:datafield[@tag=700][marc:subfield[@code='t']]">
1914                         <relatedItem>
1915                                 <xsl:call-template name="constituentOrRelatedType"></xsl:call-template>
1916                                 <titleInfo>
1917                                         <title>
1918                                                 <xsl:call-template name="chopPunctuation">
1919                                                         <xsl:with-param name="chopString">
1920                                                                 <xsl:call-template name="specialSubfieldSelect">
1921                                                                         <xsl:with-param name="anyCodes">tfklmorsv</xsl:with-param>
1922                                                                         <xsl:with-param name="axis">t</xsl:with-param>
1923                                                                         <xsl:with-param name="afterCodes">g</xsl:with-param>
1924                                                                 </xsl:call-template>
1925                                                         </xsl:with-param>
1926                                                 </xsl:call-template>
1927                                         </title>
1928                                         <xsl:call-template name="part"></xsl:call-template>
1929                                 </titleInfo>
1930                                 <name type="personal">
1931                                         <namePart>
1932                                                 <xsl:call-template name="specialSubfieldSelect">
1933                                                         <xsl:with-param name="anyCodes">aq</xsl:with-param>
1934                                                         <xsl:with-param name="axis">t</xsl:with-param>
1935                                                         <xsl:with-param name="beforeCodes">g</xsl:with-param>
1936                                                 </xsl:call-template>
1937                                         </namePart>
1938                                         <xsl:call-template name="termsOfAddress"></xsl:call-template>
1939                                         <xsl:call-template name="nameDate"></xsl:call-template>
1940                                         <xsl:call-template name="role"></xsl:call-template>
1941                                 </name>
1942                                 <xsl:call-template name="relatedForm"></xsl:call-template>
1943                                 <xsl:call-template name="relatedIdentifierISSN"></xsl:call-template>
1944                         </relatedItem>
1945                 </xsl:for-each>
1946                 <xsl:for-each select="marc:datafield[@tag=710][marc:subfield[@code='t']]">
1947                         <relatedItem>
1948                                 <xsl:call-template name="constituentOrRelatedType"></xsl:call-template>
1949                                 <titleInfo>
1950                                         <title>
1951                                                 <xsl:call-template name="chopPunctuation">
1952                                                         <xsl:with-param name="chopString">
1953                                                                 <xsl:call-template name="specialSubfieldSelect">
1954                                                                         <xsl:with-param name="anyCodes">tfklmorsv</xsl:with-param>
1955                                                                         <xsl:with-param name="axis">t</xsl:with-param>
1956                                                                         <xsl:with-param name="afterCodes">dg</xsl:with-param>
1957                                                                 </xsl:call-template>
1958                                                         </xsl:with-param>
1959                                                 </xsl:call-template>
1960                                         </title>
1961                                         <xsl:call-template name="relatedPartNumName"></xsl:call-template>
1962                                 </titleInfo>
1963                                 <name type="corporate">
1964                                         <xsl:for-each select="marc:subfield[@code='a']">
1965                                                 <namePart>
1966                                                         <xsl:value-of select="."></xsl:value-of>
1967                                                 </namePart>
1968                                         </xsl:for-each>
1969                                         <xsl:for-each select="marc:subfield[@code='b']">
1970                                                 <namePart>
1971                                                         <xsl:value-of select="."></xsl:value-of>
1972                                                 </namePart>
1973                                         </xsl:for-each>
1974                                         <xsl:variable name="tempNamePart">
1975                                                 <xsl:call-template name="specialSubfieldSelect">
1976                                                         <xsl:with-param name="anyCodes">c</xsl:with-param>
1977                                                         <xsl:with-param name="axis">t</xsl:with-param>
1978                                                         <xsl:with-param name="beforeCodes">dgn</xsl:with-param>
1979                                                 </xsl:call-template>
1980                                         </xsl:variable>
1981                                         <xsl:if test="normalize-space($tempNamePart)">
1982                                                 <namePart>
1983                                                         <xsl:value-of select="$tempNamePart"></xsl:value-of>
1984                                                 </namePart>
1985                                         </xsl:if>
1986                                         <xsl:call-template name="role"></xsl:call-template>
1987                                 </name>
1988                                 <xsl:call-template name="relatedForm"></xsl:call-template>
1989                                 <xsl:call-template name="relatedIdentifierISSN"></xsl:call-template>
1990                         </relatedItem>
1991                 </xsl:for-each>
1992                 <xsl:for-each select="marc:datafield[@tag=711][marc:subfield[@code='t']]">
1993                         <relatedItem>
1994                                 <xsl:call-template name="constituentOrRelatedType"></xsl:call-template>
1995                                 <titleInfo>
1996                                         <title>
1997                                                 <xsl:call-template name="chopPunctuation">
1998                                                         <xsl:with-param name="chopString">
1999                                                                 <xsl:call-template name="specialSubfieldSelect">
2000                                                                         <xsl:with-param name="anyCodes">tfklsv</xsl:with-param>
2001                                                                         <xsl:with-param name="axis">t</xsl:with-param>
2002                                                                         <xsl:with-param name="afterCodes">g</xsl:with-param>
2003                                                                 </xsl:call-template>
2004                                                         </xsl:with-param>
2005                                                 </xsl:call-template>
2006                                         </title>
2007                                         <xsl:call-template name="relatedPartNumName"></xsl:call-template>
2008                                 </titleInfo>
2009                                 <name type="conference">
2010                                         <namePart>
2011                                                 <xsl:call-template name="specialSubfieldSelect">
2012                                                         <xsl:with-param name="anyCodes">aqdc</xsl:with-param>
2013                                                         <xsl:with-param name="axis">t</xsl:with-param>
2014                                                         <xsl:with-param name="beforeCodes">gn</xsl:with-param>
2015                                                 </xsl:call-template>
2016                                         </namePart>
2017                                 </name>
2018                                 <xsl:call-template name="relatedForm"></xsl:call-template>
2019                                 <xsl:call-template name="relatedIdentifierISSN"></xsl:call-template>
2020                         </relatedItem>
2021                 </xsl:for-each>
2022                 <xsl:for-each select="marc:datafield[@tag=730][@ind2=2]">
2023                         <relatedItem>
2024                                 <xsl:call-template name="constituentOrRelatedType"></xsl:call-template>
2025                                 <titleInfo>
2026                                         <title>
2027                                                 <xsl:call-template name="chopPunctuation">
2028                                                         <xsl:with-param name="chopString">
2029                                                                 <xsl:call-template name="subfieldSelect">
2030                                                                         <xsl:with-param name="codes">adfgklmorsv</xsl:with-param>
2031                                                                 </xsl:call-template>
2032                                                         </xsl:with-param>
2033                                                 </xsl:call-template>
2034                                         </title>
2035                                         <xsl:call-template name="part"></xsl:call-template>
2036                                 </titleInfo>
2037                                 <xsl:call-template name="relatedForm"></xsl:call-template>
2038                                 <xsl:call-template name="relatedIdentifierISSN"></xsl:call-template>
2039                         </relatedItem>
2040                 </xsl:for-each>
2041                 <xsl:for-each select="marc:datafield[@tag=740][@ind2=2]">
2042                         <relatedItem>
2043                                 <xsl:call-template name="constituentOrRelatedType"></xsl:call-template>
2044                                 <titleInfo>
2045                                         <title>
2046                                                 <xsl:call-template name="chopPunctuation">
2047                                                         <xsl:with-param name="chopString">
2048                                                                 <xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
2049                                                         </xsl:with-param>
2050                                                 </xsl:call-template>
2051                                         </title>
2052                                         <xsl:call-template name="part"></xsl:call-template>
2053                                 </titleInfo>
2054                                 <xsl:call-template name="relatedForm"></xsl:call-template>
2055                         </relatedItem>
2056                 </xsl:for-each>
2057                 <xsl:for-each select="marc:datafield[@tag=760]|marc:datafield[@tag=762]">
2058                         <relatedItem type="series">
2059                                 <xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
2060                         </relatedItem>
2061                 </xsl:for-each>
2062                 <xsl:for-each select="marc:datafield[@tag=765]|marc:datafield[@tag=767]|marc:datafield[@tag=777]|marc:datafield[@tag=787]">
2063                         <relatedItem>
2064                                 <xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
2065                         </relatedItem>
2066                 </xsl:for-each>
2067                 <xsl:for-each select="marc:datafield[@tag=775]">
2068                         <relatedItem type="otherVersion">
2069                                 <xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
2070                         </relatedItem>
2071                 </xsl:for-each>
2072                 <xsl:for-each select="marc:datafield[@tag=770]|marc:datafield[@tag=774]">
2073                         <relatedItem type="constituent">
2074                                 <xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
2075                         </relatedItem>
2076                 </xsl:for-each>
2077                 <xsl:for-each select="marc:datafield[@tag=772]|marc:datafield[@tag=773]">
2078                         <relatedItem type="host">
2079                                 <xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
2080                         </relatedItem>
2081                 </xsl:for-each>
2082                 <xsl:for-each select="marc:datafield[@tag=776]">
2083                         <relatedItem type="otherFormat">
2084                                 <xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
2085                         </relatedItem>
2086                 </xsl:for-each>
2087                 <xsl:for-each select="marc:datafield[@tag=780]">
2088                         <relatedItem type="preceding">
2089                                 <xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
2090                         </relatedItem>
2091                 </xsl:for-each>
2092                 <xsl:for-each select="marc:datafield[@tag=785]">
2093                         <relatedItem type="succeeding">
2094                                 <xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
2095                         </relatedItem>
2096                 </xsl:for-each>
2097                 <xsl:for-each select="marc:datafield[@tag=786]">
2098                         <relatedItem type="original">
2099                                 <xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
2100                         </relatedItem>
2101                 </xsl:for-each>
2102                 <xsl:for-each select="marc:datafield[@tag=800]">
2103                         <relatedItem type="series">
2104                                 <titleInfo>
2105                                         <title>
2106                                                 <xsl:call-template name="chopPunctuation">
2107                                                         <xsl:with-param name="chopString">
2108                                                                 <xsl:call-template name="specialSubfieldSelect">
2109                                                                         <xsl:with-param name="anyCodes">tfklmorsv</xsl:with-param>
2110                                                                         <xsl:with-param name="axis">t</xsl:with-param>
2111                                                                         <xsl:with-param name="afterCodes">g</xsl:with-param>
2112                                                                 </xsl:call-template>
2113                                                         </xsl:with-param>
2114                                                 </xsl:call-template>
2115                                         </title>
2116                                         <xsl:call-template name="part"></xsl:call-template>
2117                                 </titleInfo>
2118                                 <name type="personal">
2119                                         <namePart>
2120                                                 <xsl:call-template name="chopPunctuation">
2121                                                         <xsl:with-param name="chopString">
2122                                                                 <xsl:call-template name="specialSubfieldSelect">
2123                                                                         <xsl:with-param name="anyCodes">aq</xsl:with-param>
2124                                                                         <xsl:with-param name="axis">t</xsl:with-param>
2125                                                                         <xsl:with-param name="beforeCodes">g</xsl:with-param>
2126                                                                 </xsl:call-template>
2127                                                         </xsl:with-param>
2128                                                 </xsl:call-template>
2129                                         </namePart>
2130                                         <xsl:call-template name="termsOfAddress"></xsl:call-template>
2131                                         <xsl:call-template name="nameDate"></xsl:call-template>
2132                                         <xsl:call-template name="role"></xsl:call-template>
2133                                 </name>
2134                                 <xsl:call-template name="relatedForm"></xsl:call-template>
2135                         </relatedItem>
2136                 </xsl:for-each>
2137                 <xsl:for-each select="marc:datafield[@tag=810]">
2138                         <relatedItem type="series">
2139                                 <titleInfo>
2140                                         <title>
2141                                                 <xsl:call-template name="chopPunctuation">
2142                                                         <xsl:with-param name="chopString">
2143                                                                 <xsl:call-template name="specialSubfieldSelect">
2144                                                                         <xsl:with-param name="anyCodes">tfklmorsv</xsl:with-param>
2145                                                                         <xsl:with-param name="axis">t</xsl:with-param>
2146                                                                         <xsl:with-param name="afterCodes">dg</xsl:with-param>
2147                                                                 </xsl:call-template>
2148                                                         </xsl:with-param>
2149                                                 </xsl:call-template>
2150                                         </title>
2151                                         <xsl:call-template name="relatedPartNumName"></xsl:call-template>
2152                                 </titleInfo>
2153                                 <name type="corporate">
2154                                         <xsl:for-each select="marc:subfield[@code='a']">
2155                                                 <namePart>
2156                                                         <xsl:value-of select="."></xsl:value-of>
2157                                                 </namePart>
2158                                         </xsl:for-each>
2159                                         <xsl:for-each select="marc:subfield[@code='b']">
2160                                                 <namePart>
2161                                                         <xsl:value-of select="."></xsl:value-of>
2162                                                 </namePart>
2163                                         </xsl:for-each>
2164                                         <namePart>
2165                                                 <xsl:call-template name="specialSubfieldSelect">
2166                                                         <xsl:with-param name="anyCodes">c</xsl:with-param>
2167                                                         <xsl:with-param name="axis">t</xsl:with-param>
2168                                                         <xsl:with-param name="beforeCodes">dgn</xsl:with-param>
2169                                                 </xsl:call-template>
2170                                         </namePart>
2171                                         <xsl:call-template name="role"></xsl:call-template>
2172                                 </name>
2173                                 <xsl:call-template name="relatedForm"></xsl:call-template>
2174                         </relatedItem>
2175                 </xsl:for-each>
2176                 <xsl:for-each select="marc:datafield[@tag=811]">
2177                         <relatedItem type="series">
2178                                 <titleInfo>
2179                                         <title>
2180                                                 <xsl:call-template name="chopPunctuation">
2181                                                         <xsl:with-param name="chopString">
2182                                                                 <xsl:call-template name="specialSubfieldSelect">
2183                                                                         <xsl:with-param name="anyCodes">tfklsv</xsl:with-param>
2184                                                                         <xsl:with-param name="axis">t</xsl:with-param>
2185                                                                         <xsl:with-param name="afterCodes">g</xsl:with-param>
2186                                                                 </xsl:call-template>
2187                                                         </xsl:with-param>
2188                                                 </xsl:call-template>
2189                                         </title>
2190                                         <xsl:call-template name="relatedPartNumName"/>
2191                                 </titleInfo>
2192                                 <name type="conference">
2193                                         <namePart>
2194                                                 <xsl:call-template name="specialSubfieldSelect">
2195                                                         <xsl:with-param name="anyCodes">aqdc</xsl:with-param>
2196                                                         <xsl:with-param name="axis">t</xsl:with-param>
2197                                                         <xsl:with-param name="beforeCodes">gn</xsl:with-param>
2198                                                 </xsl:call-template>
2199                                         </namePart>
2200                                         <xsl:call-template name="role"/>
2201                                 </name>
2202                                 <xsl:call-template name="relatedForm"/>
2203                         </relatedItem>
2204                 </xsl:for-each>
2205                 <xsl:for-each select="marc:datafield[@tag='830']">
2206                         <relatedItem type="series">
2207                                 <titleInfo>
2208                                         <title>
2209                                                 <xsl:call-template name="chopPunctuation">
2210                                                         <xsl:with-param name="chopString">
2211                                                                 <xsl:call-template name="subfieldSelect">
2212                                                                         <xsl:with-param name="codes">adfgklmorsv</xsl:with-param>
2213                                                                 </xsl:call-template>
2214                                                         </xsl:with-param>
2215                                                 </xsl:call-template>
2216                                         </title>
2217                                         <xsl:call-template name="part"/>
2218                                 </titleInfo>
2219                                 <xsl:call-template name="relatedForm"/>
2220                         </relatedItem>
2221                 </xsl:for-each>
2222                 <xsl:for-each select="marc:datafield[@tag='856'][@ind2='2']/marc:subfield[@code='q']">
2223                         <relatedItem>
2224                                 <internetMediaType>
2225                                         <xsl:value-of select="."/>
2226                                 </internetMediaType>
2227                         </relatedItem>
2228                 </xsl:for-each>
2229                 <xsl:for-each select="marc:datafield[@tag='020']">
2230                         <xsl:call-template name="isInvalid">
2231                                 <xsl:with-param name="type">isbn</xsl:with-param>
2232                         </xsl:call-template>
2233                         <xsl:if test="marc:subfield[@code='a']">
2234                                 <identifier type="isbn">
2235                                         <xsl:value-of select="marc:subfield[@code='a']"/>
2236                                 </identifier>
2237                         </xsl:if>
2238                 </xsl:for-each>
2239                 <xsl:for-each select="marc:datafield[@tag='024'][@ind1='0']">
2240                         <xsl:call-template name="isInvalid">
2241                                 <xsl:with-param name="type">isrc</xsl:with-param>
2242                         </xsl:call-template>
2243                         <xsl:if test="marc:subfield[@code='a']">
2244                                 <identifier type="isrc">
2245                                         <xsl:value-of select="marc:subfield[@code='a']"/>
2246                                 </identifier>
2247                         </xsl:if>
2248                 </xsl:for-each>
2249                 <xsl:for-each select="marc:datafield[@tag='024'][@ind1='2']">
2250                         <xsl:call-template name="isInvalid">
2251                                 <xsl:with-param name="type">ismn</xsl:with-param>
2252                         </xsl:call-template>
2253                         <xsl:if test="marc:subfield[@code='a']">
2254                                 <identifier type="ismn">
2255                                         <xsl:value-of select="marc:subfield[@code='a']"/>
2256                                 </identifier>
2257                         </xsl:if>
2258                 </xsl:for-each>
2259                 <xsl:for-each select="marc:datafield[@tag='024'][@ind1='4']">
2260                         <xsl:call-template name="isInvalid">
2261                                 <xsl:with-param name="type">sici</xsl:with-param>
2262                         </xsl:call-template>
2263                         <identifier type="sici">
2264                                 <xsl:call-template name="subfieldSelect">
2265                                         <xsl:with-param name="codes">ab</xsl:with-param>
2266                                 </xsl:call-template>
2267                         </identifier>
2268                 </xsl:for-each>
2269                 <xsl:for-each select="marc:datafield[@tag='022']">
2270                         <xsl:call-template name="isInvalid">
2271                                 <xsl:with-param name="type">issn</xsl:with-param>
2272                         </xsl:call-template>
2273                         <identifier type="issn">
2274                                 <xsl:value-of select="marc:subfield[@code='a']"/>
2275                         </identifier>
2276                 </xsl:for-each>
2277                 <xsl:for-each select="marc:datafield[@tag='010']">
2278                         <xsl:call-template name="isInvalid">
2279                                 <xsl:with-param name="type">lccn</xsl:with-param>
2280                         </xsl:call-template>
2281                         <identifier type="lccn">
2282                                 <xsl:value-of select="normalize-space(marc:subfield[@code='a'])"/>
2283                         </identifier>
2284                 </xsl:for-each>
2285                 <xsl:for-each select="marc:datafield[@tag='028']">
2286                         <identifier>
2287                                 <xsl:attribute name="type">
2288                                         <xsl:choose>
2289                                                 <xsl:when test="@ind1='0'">issue number</xsl:when>
2290                                                 <xsl:when test="@ind1='1'">matrix number</xsl:when>
2291                                                 <xsl:when test="@ind1='2'">music plate</xsl:when>
2292                                                 <xsl:when test="@ind1='3'">music publisher</xsl:when>
2293                                                 <xsl:when test="@ind1='4'">videorecording identifier</xsl:when>
2294                                         </xsl:choose>
2295                                 </xsl:attribute>
2296                                 <!--<xsl:call-template name="isInvalid"/>--> <!-- no $z in 028 -->
2297                                 <xsl:call-template name="subfieldSelect">
2298                                         <xsl:with-param name="codes">
2299                                                 <xsl:choose>
2300                                                         <xsl:when test="@ind1='0'">ba</xsl:when>
2301                                                         <xsl:otherwise>ab</xsl:otherwise>
2302                                                 </xsl:choose>
2303                                         </xsl:with-param>
2304                                 </xsl:call-template>
2305                         </identifier>