]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/YYYY.schema.bib-auth-browse.sql
Bib record browser with 'see also', etc from linked authority headings
[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 authority.control_set_authority_field
7     ADD COLUMN display_sf_list TEXT;
8
9 UPDATE authority.control_set_authority_field
10     SET display_sf_list = REGEXP_REPLACE(sf_list, '[w254]', '', 'g');
11
12 ALTER TABLE authority.control_set_authority_field
13     ALTER COLUMN display_sf_list SET NOT NULL;
14
15 ALTER TABLE metabib.browse_entry_def_map
16     ADD COLUMN authority BIGINT REFERENCES authority.record_entry (id)
17         ON DELETE SET NULL;
18
19 ALTER TABLE config.metabib_field ADD COLUMN authority_xpath TEXT;
20 ALTER TABLE config.metabib_field ADD COLUMN browse_sort_xpath TEXT;
21
22 UPDATE config.metabib_field
23     SET authority_xpath = '//@xlink:href'
24     WHERE
25         format = 'mods32' AND
26         field_class IN ('subject','series','title','author') AND
27         browse_field IS TRUE;
28
29 ALTER TYPE metabib.field_entry_template ADD ATTRIBUTE authority BIGINT;
30 ALTER TYPE metabib.field_entry_template ADD ATTRIBUTE sort_value TEXT;
31
32 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$
33 DECLARE
34     fclass          RECORD;
35     ind_data        metabib.field_entry_template%ROWTYPE;
36     mbe_row         metabib.browse_entry%ROWTYPE;
37     mbe_id          BIGINT;
38     b_skip_facet    BOOL;
39     b_skip_browse   BOOL;
40     b_skip_search   BOOL;
41     value_prepped   TEXT;
42 BEGIN
43
44     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;
45     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;
46     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;
47
48     PERFORM * FROM config.internal_flag WHERE name = 'ingest.assume_inserts_only' AND enabled;
49     IF NOT FOUND THEN
50         IF NOT b_skip_search THEN
51             FOR fclass IN SELECT * FROM config.metabib_class LOOP
52                 -- RAISE NOTICE 'Emptying out %', fclass.name;
53                 EXECUTE $$DELETE FROM metabib.$$ || fclass.name || $$_field_entry WHERE source = $$ || bib_id;
54             END LOOP;
55         END IF;
56         IF NOT b_skip_facet THEN
57             DELETE FROM metabib.facet_entry WHERE source = bib_id;
58         END IF;
59         IF NOT b_skip_browse THEN
60             DELETE FROM metabib.browse_entry_def_map WHERE source = bib_id;
61         END IF;
62     END IF;
63
64     FOR ind_data IN SELECT * FROM biblio.extract_metabib_field_entry( bib_id ) LOOP
65         IF ind_data.field < 0 THEN
66             ind_data.field = -1 * ind_data.field;
67         END IF;
68
69         IF ind_data.facet_field AND NOT b_skip_facet THEN
70             INSERT INTO metabib.facet_entry (field, source, value)
71                 VALUES (ind_data.field, ind_data.source, ind_data.value);
72         END IF;
73
74         IF ind_data.browse_field AND NOT b_skip_browse THEN
75             -- A caveat about this SELECT: this should take care of replacing
76             -- old mbe rows when data changes, but not if normalization (by
77             -- which I mean specifically the output of
78             -- evergreen.oils_tsearch2()) changes.  It may or may not be
79             -- expensive to add a comparison of index_vector to index_vector
80             -- to the WHERE clause below.
81
82             value_prepped := metabib.browse_normalize(ind_data.value, ind_data.field);
83             SELECT INTO mbe_row * FROM metabib.browse_entry
84                 WHERE value = value_prepped AND sort_value = ind_data.sort_value;
85
86             IF FOUND THEN
87                 mbe_id := mbe_row.id;
88             ELSE
89                 INSERT INTO metabib.browse_entry
90                     ( value, sort_value ) VALUES
91                     ( value_prepped, ind_data.sort_value );
92
93                 mbe_id := CURRVAL('metabib.browse_entry_id_seq'::REGCLASS);
94             END IF;
95
96             INSERT INTO metabib.browse_entry_def_map (entry, def, source, authority)
97                 VALUES (mbe_id, ind_data.field, ind_data.source, ind_data.authority);
98         END IF;
99
100         IF ind_data.search_field AND NOT b_skip_search THEN
101             EXECUTE $$
102                 INSERT INTO metabib.$$ || ind_data.field_class || $$_field_entry (field, source, value)
103                     VALUES ($$ ||
104                         quote_literal(ind_data.field) || $$, $$ ||
105                         quote_literal(ind_data.source) || $$, $$ ||
106                         quote_literal(ind_data.value) ||
107                     $$);$$;
108         END IF;
109
110     END LOOP;
111
112     IF NOT b_skip_search THEN
113         PERFORM metabib.update_combined_index_vectors(bib_id);
114     END IF;
115
116     RETURN;
117 END;
118 $func$ LANGUAGE PLPGSQL;
119
120
121 CREATE OR REPLACE FUNCTION biblio.extract_metabib_field_entry ( rid BIGINT, default_joiner TEXT ) RETURNS SETOF metabib.field_entry_template AS $func$
122 DECLARE
123     bib     biblio.record_entry%ROWTYPE;
124     idx     config.metabib_field%ROWTYPE;
125     xfrm        config.xml_transform%ROWTYPE;
126     prev_xfrm   TEXT;
127     transformed_xml TEXT;
128     xml_node    TEXT;
129     xml_node_list   TEXT[];
130     facet_text  TEXT;
131     browse_text TEXT;
132     sort_value  TEXT;
133     raw_text    TEXT;
134     curr_text   TEXT;
135     joiner      TEXT := default_joiner; -- XXX will index defs supply a joiner?
136     authority_text TEXT;
137     authority_link BIGINT;
138     output_row  metabib.field_entry_template%ROWTYPE;
139 BEGIN
140
141     -- Get the record
142     SELECT INTO bib * FROM biblio.record_entry WHERE id = rid;
143
144     -- Loop over the indexing entries
145     FOR idx IN SELECT * FROM config.metabib_field ORDER BY format LOOP
146
147         SELECT INTO xfrm * from config.xml_transform WHERE name = idx.format;
148
149         -- See if we can skip the XSLT ... it's expensive
150         IF prev_xfrm IS NULL OR prev_xfrm <> xfrm.name THEN
151             -- Can't skip the transform
152             IF xfrm.xslt <> '---' THEN
153                 transformed_xml := oils_xslt_process(bib.marc,xfrm.xslt);
154             ELSE
155                 transformed_xml := bib.marc;
156             END IF;
157
158             prev_xfrm := xfrm.name;
159         END IF;
160
161         xml_node_list := oils_xpath( idx.xpath, transformed_xml, ARRAY[ARRAY[xfrm.prefix, xfrm.namespace_uri]] );
162
163         raw_text := NULL;
164         FOR xml_node IN SELECT x FROM unnest(xml_node_list) AS x LOOP
165             CONTINUE WHEN xml_node !~ E'^\\s*<';
166
167             curr_text := ARRAY_TO_STRING(
168                 oils_xpath( '//text()',
169                     REGEXP_REPLACE( -- This escapes all &s not followed by "amp;".  Data ise returned from oils_xpath (above) in UTF-8, not entity encoded
170                         REGEXP_REPLACE( -- This escapes embeded <s
171                             xml_node,
172                             $re$(>[^<]+)(<)([^>]+<)$re$,
173                             E'\\1&lt;\\3',
174                             'g'
175                         ),
176                         '&(?!amp;)',
177                         '&amp;',
178                         'g'
179                     )
180                 ),
181                 ' '
182             );
183
184             CONTINUE WHEN curr_text IS NULL OR curr_text = '';
185
186             IF raw_text IS NOT NULL THEN
187                 raw_text := raw_text || joiner;
188             END IF;
189
190             raw_text := COALESCE(raw_text,'') || curr_text;
191
192             -- autosuggest/metabib.browse_entry
193             IF idx.browse_field THEN
194
195                 IF idx.browse_xpath IS NOT NULL AND idx.browse_xpath <> '' THEN
196                     browse_text := oils_xpath_string( idx.browse_xpath, xml_node, joiner, ARRAY[ARRAY[xfrm.prefix, xfrm.namespace_uri]] );
197                 ELSE
198                     browse_text := curr_text;
199                 END IF;
200
201                 IF idx.browse_sort_xpath IS NOT NULL AND
202                     idx.browse_sort_xpath <> '' THEN
203
204                     sort_value := oils_xpath_string(
205                         idx.browse_sort_xpath, xml_node, joiner,
206                         ARRAY[ARRAY[xfrm.prefix, xfrm.namespace_uri]]
207                     );
208                 ELSE
209                     sort_value := browse_text;
210                 END IF;
211
212                 output_row.field_class = idx.field_class;
213                 output_row.field = idx.id;
214                 output_row.source = rid;
215                 output_row.value = BTRIM(REGEXP_REPLACE(browse_text, E'\\s+', ' ', 'g'));
216                 output_row.sort_value :=
217                     public.search_normalize(sort_value);
218
219                 output_row.authority := NULL;
220
221                 IF idx.authority_xpath IS NOT NULL AND idx.authority_xpath <> '' THEN
222                     authority_text := oils_xpath_string(
223                         idx.authority_xpath, xml_node, joiner,
224                         ARRAY[
225                             ARRAY[xfrm.prefix, xfrm.namespace_uri],
226                             ARRAY['xlink','http://www.w3.org/1999/xlink']
227                         ]
228                     );
229
230                     IF authority_text ~ '^\d+$' THEN
231                         authority_link := authority_text::BIGINT;
232                         PERFORM * FROM authority.record_entry WHERE id = authority_link;
233                         IF FOUND THEN
234                             output_row.authority := authority_link;
235                         END IF;
236                     END IF;
237
238                 END IF;
239
240                 output_row.browse_field = TRUE;
241                 RETURN NEXT output_row;
242                 output_row.browse_field = FALSE;
243                 output_row.sort_value := NULL;
244             END IF;
245
246             -- insert raw node text for faceting
247             IF idx.facet_field THEN
248
249                 IF idx.facet_xpath IS NOT NULL AND idx.facet_xpath <> '' THEN
250                     facet_text := oils_xpath_string( idx.facet_xpath, xml_node, joiner, ARRAY[ARRAY[xfrm.prefix, xfrm.namespace_uri]] );
251                 ELSE
252                     facet_text := curr_text;
253                 END IF;
254
255                 output_row.field_class = idx.field_class;
256                 output_row.field = -1 * idx.id;
257                 output_row.source = rid;
258                 output_row.value = BTRIM(REGEXP_REPLACE(facet_text, E'\\s+', ' ', 'g'));
259
260                 output_row.facet_field = TRUE;
261                 RETURN NEXT output_row;
262                 output_row.facet_field = FALSE;
263             END IF;
264
265         END LOOP;
266
267         CONTINUE WHEN raw_text IS NULL OR raw_text = '';
268
269         -- insert combined node text for searching
270         IF idx.search_field THEN
271             output_row.field_class = idx.field_class;
272             output_row.field = idx.id;
273             output_row.source = rid;
274             output_row.value = BTRIM(REGEXP_REPLACE(raw_text, E'\\s+', ' ', 'g'));
275
276             output_row.search_field = TRUE;
277             RETURN NEXT output_row;
278             output_row.search_field = FALSE;
279         END IF;
280
281     END LOOP;
282
283 END;
284
285 $func$ LANGUAGE PLPGSQL;
286
287
288 -- 953.data.MODS32-xsl.sql
289 UPDATE config.xml_transform SET xslt=$$<?xml version="1.0" encoding="UTF-8"?>
290 <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">
291         <xsl:output encoding="UTF-8" indent="yes" method="xml"/>
292 <!--
293 Revision 1.14 - Fixed template isValid and fields 010, 020, 022, 024, 028, and 037 to output additional identifier elements 
294   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
295
296 Revision 1.13 - Changed order of output under cartographics to reflect schema  2006/11/28 tmee
297         
298 Revision 1.12 - Updated to reflect MODS 3.2 Mapping  2006/10/11 tmee
299                 
300 Revision 1.11 - The attribute objectPart moved from <languageTerm> to <language>
301       2006/04/08  jrad
302
303 Revision 1.10 MODS 3.1 revisions to language and classification elements  
304                                 (plus ability to find marc:collection embedded in wrapper elements such as SRU zs: wrappers)
305                                 2006/02/06  ggar
306
307 Revision 1.9 subfield $y was added to field 242 2004/09/02 10:57 jrad
308
309 Revision 1.8 Subject chopPunctuation expanded and attribute fixes 2004/08/12 jrad
310
311 Revision 1.7 2004/03/25 08:29 jrad
312
313 Revision 1.6 various validation fixes 2004/02/20 ntra
314
315 Revision 1.5  2003/10/02 16:18:58  ntra
316 MODS2 to MODS3 updates, language unstacking and 
317 de-duping, chopPunctuation expanded
318
319 Revision 1.3  2003/04/03 00:07:19  ntra
320 Revision 1.3 Additional Changes not related to MODS Version 2.0 by ntra
321
322 Revision 1.2  2003/03/24 19:37:42  ckeith
323 Added Log Comment
324
325 -->
326         <xsl:template match="/">
327                 <xsl:choose>
328                         <xsl:when test="//marc:collection">
329                                 <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">
330                                         <xsl:for-each select="//marc:collection/marc:record">
331                                                 <mods version="3.2">
332                                                         <xsl:call-template name="marcRecord"/>
333                                                 </mods>
334                                         </xsl:for-each>
335                                 </modsCollection>
336                         </xsl:when>
337                         <xsl:otherwise>
338                                 <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">
339                                         <xsl:for-each select="//marc:record">
340                                                 <xsl:call-template name="marcRecord"/>
341                                         </xsl:for-each>
342                                 </mods>
343                         </xsl:otherwise>
344                 </xsl:choose>
345         </xsl:template>
346         <xsl:template name="marcRecord">
347                 <xsl:variable name="leader" select="marc:leader"/>
348                 <xsl:variable name="leader6" select="substring($leader,7,1)"/>
349                 <xsl:variable name="leader7" select="substring($leader,8,1)"/>
350                 <xsl:variable name="controlField008" select="marc:controlfield[@tag='008']"/>
351                 <xsl:variable name="typeOf008">
352                         <xsl:choose>
353                                 <xsl:when test="$leader6='a'">
354                                         <xsl:choose>
355                                                 <xsl:when test="$leader7='a' or $leader7='c' or $leader7='d' or $leader7='m'">BK</xsl:when>
356                                                 <xsl:when test="$leader7='b' or $leader7='i' or $leader7='s'">SE</xsl:when>
357                                         </xsl:choose>
358                                 </xsl:when>
359                                 <xsl:when test="$leader6='t'">BK</xsl:when>
360                                 <xsl:when test="$leader6='p'">MM</xsl:when>
361                                 <xsl:when test="$leader6='m'">CF</xsl:when>
362                                 <xsl:when test="$leader6='e' or $leader6='f'">MP</xsl:when>
363                                 <xsl:when test="$leader6='g' or $leader6='k' or $leader6='o' or $leader6='r'">VM</xsl:when>
364                                 <xsl:when test="$leader6='c' or $leader6='d' or $leader6='i' or $leader6='j'">MU</xsl:when>
365                         </xsl:choose>
366                 </xsl:variable>
367                 <xsl:for-each select="marc:datafield[@tag='245']">
368                         <titleInfo>
369                                 <xsl:variable name="title">
370                                         <xsl:choose>
371                                                 <xsl:when test="marc:subfield[@code='b']">
372                                                         <xsl:call-template name="specialSubfieldSelect">
373                                                                 <xsl:with-param name="axis">b</xsl:with-param>
374                                                                 <xsl:with-param name="beforeCodes">afgk</xsl:with-param>
375                                                         </xsl:call-template>
376                                                 </xsl:when>
377                                                 <xsl:otherwise>
378                                                         <xsl:call-template name="subfieldSelect">
379                                                                 <xsl:with-param name="codes">abfgk</xsl:with-param>
380                                                         </xsl:call-template>
381                                                 </xsl:otherwise>
382                                         </xsl:choose>
383                                 </xsl:variable>
384                                 <xsl:variable name="titleChop">
385                                         <xsl:call-template name="chopPunctuation">
386                                                 <xsl:with-param name="chopString">
387                                                         <xsl:value-of select="$title"/>
388                                                 </xsl:with-param>
389                                         </xsl:call-template>
390                                 </xsl:variable>
391                                 <xsl:choose>
392                                         <xsl:when test="@ind2>0">
393                                                 <nonSort>
394                                                         <xsl:value-of select="substring($titleChop,1,@ind2)"/>
395                                                 </nonSort>
396                                                 <title>
397                                                         <xsl:value-of select="substring($titleChop,@ind2+1)"/>
398                                                 </title>
399                                         </xsl:when>
400                                         <xsl:otherwise>
401                                                 <title>
402                                                         <xsl:value-of select="$titleChop"/>
403                                                 </title>
404                                         </xsl:otherwise>
405                                 </xsl:choose>
406                                 <xsl:if test="marc:subfield[@code='b']">
407                                         <subTitle>
408                                                 <xsl:call-template name="chopPunctuation">
409                                                         <xsl:with-param name="chopString">
410                                                                 <xsl:call-template name="specialSubfieldSelect">
411                                                                         <xsl:with-param name="axis">b</xsl:with-param>
412                                                                         <xsl:with-param name="anyCodes">b</xsl:with-param>
413                                                                         <xsl:with-param name="afterCodes">afgk</xsl:with-param>
414                                                                 </xsl:call-template>
415                                                         </xsl:with-param>
416                                                 </xsl:call-template>
417                                         </subTitle>
418                                 </xsl:if>
419                                 <xsl:call-template name="part"></xsl:call-template>
420                         </titleInfo>
421                         <!-- A form of title that ignores non-filing characters; useful
422                                  for not converting "L'Oreal" into "L' Oreal" at index time -->
423                         <titleNonfiling>
424                                 <xsl:variable name="title">
425                                         <xsl:choose>
426                                                 <xsl:when test="marc:subfield[@code='b']">
427                                                         <xsl:call-template name="specialSubfieldSelect">
428                                                                 <xsl:with-param name="axis">b</xsl:with-param>
429                                                                 <xsl:with-param name="beforeCodes">afgk</xsl:with-param>
430                                                         </xsl:call-template>
431                                                 </xsl:when>
432                                                 <xsl:otherwise>
433                                                         <xsl:call-template name="subfieldSelect">
434                                                                 <xsl:with-param name="codes">abfgk</xsl:with-param>
435                                                         </xsl:call-template>
436                                                 </xsl:otherwise>
437                                         </xsl:choose>
438                                 </xsl:variable>
439                                 <title>
440                                         <xsl:value-of select="$title"/>
441                                 </title>
442                                 <xsl:if test="marc:subfield[@code='b']">
443                                         <subTitle>
444                                                 <xsl:call-template name="chopPunctuation">
445                                                         <xsl:with-param name="chopString">
446                                                                 <xsl:call-template name="specialSubfieldSelect">
447                                                                         <xsl:with-param name="axis">b</xsl:with-param>
448                                                                         <xsl:with-param name="anyCodes">b</xsl:with-param>
449                                                                         <xsl:with-param name="afterCodes">afgk</xsl:with-param>
450                                                                 </xsl:call-template>
451                                                         </xsl:with-param>
452                                                 </xsl:call-template>
453                                         </subTitle>
454                                 </xsl:if>
455                                 <xsl:call-template name="part"></xsl:call-template>
456                         </titleNonfiling>
457                 </xsl:for-each>
458                 <xsl:for-each select="marc:datafield[@tag='210']">
459                         <titleInfo type="abbreviated">
460                                 <title>
461                                         <xsl:call-template name="chopPunctuation">
462                                                 <xsl:with-param name="chopString">
463                                                         <xsl:call-template name="subfieldSelect">
464                                                                 <xsl:with-param name="codes">a</xsl:with-param>
465                                                         </xsl:call-template>
466                                                 </xsl:with-param>
467                                         </xsl:call-template>
468                                 </title>
469                                 <xsl:call-template name="subtitle"/>
470                         </titleInfo>
471                 </xsl:for-each>
472                 <xsl:for-each select="marc:datafield[@tag='242']">
473                         <xsl:variable name="titleChop">
474                                 <xsl:call-template name="chopPunctuation">
475                                         <xsl:with-param name="chopString">
476                                                 <xsl:call-template name="subfieldSelect">
477                                                         <!-- 1/04 removed $h, b -->
478                                                         <xsl:with-param name="codes">a</xsl:with-param>
479                                                 </xsl:call-template>
480                                         </xsl:with-param>
481                                 </xsl:call-template>
482                         </xsl:variable>
483                         <titleInfo type="translated">
484                                 <!--09/01/04 Added subfield $y-->
485                                 <xsl:for-each select="marc:subfield[@code='y']">
486                                         <xsl:attribute name="lang">
487                                                 <xsl:value-of select="text()"/>
488                                         </xsl:attribute>
489                                 </xsl:for-each>
490                                 <title>
491                                         <xsl:value-of select="$titleChop" />
492                                 </title>
493                                 <!-- 1/04 fix -->
494                                 <xsl:call-template name="subtitle"/>
495                                 <xsl:call-template name="part"/>
496                         </titleInfo>
497                         <titleInfo type="translated-nfi">
498                                 <xsl:for-each select="marc:subfield[@code='y']">
499                                         <xsl:attribute name="lang">
500                                                 <xsl:value-of select="text()"/>
501                                         </xsl:attribute>
502                                 </xsl:for-each>
503                                 <xsl:choose>
504                                         <xsl:when test="@ind2>0">
505                                                 <nonSort>
506                                                         <xsl:value-of select="substring($titleChop,1,@ind2)"/>
507                                                 </nonSort>
508                                                 <title>
509                                                         <xsl:value-of select="substring($titleChop,@ind2+1)"/>
510                                                 </title>
511                                         </xsl:when>
512                                         <xsl:otherwise>
513                                                 <title>
514                                                         <xsl:value-of select="$titleChop" />
515                                                 </title>
516                                         </xsl:otherwise>
517                                 </xsl:choose>
518                                 <xsl:call-template name="subtitle"/>
519                                 <xsl:call-template name="part"/>
520                         </titleInfo>
521                 </xsl:for-each>
522                 <xsl:for-each select="marc:datafield[@tag='246']">
523                         <titleInfo type="alternative">
524                                 <xsl:for-each select="marc:subfield[@code='i']">
525                                         <xsl:attribute name="displayLabel">
526                                                 <xsl:value-of select="text()"/>
527                                         </xsl:attribute>
528                                 </xsl:for-each>
529                                 <title>
530                                         <xsl:call-template name="chopPunctuation">
531                                                 <xsl:with-param name="chopString">
532                                                         <xsl:call-template name="subfieldSelect">
533                                                                 <!-- 1/04 removed $h, $b -->
534                                                                 <xsl:with-param name="codes">af</xsl:with-param>
535                                                         </xsl:call-template>
536                                                 </xsl:with-param>
537                                         </xsl:call-template>
538                                 </title>
539                                 <xsl:call-template name="subtitle"/>
540                                 <xsl:call-template name="part"/>
541                         </titleInfo>
542                 </xsl:for-each>
543                 <xsl:for-each select="marc:datafield[@tag='130']|marc:datafield[@tag='240']|marc:datafield[@tag='730'][@ind2!='2']">
544                         <xsl:variable name="nfi">
545                                 <xsl:choose>
546                                         <xsl:when test="@tag='240'">
547                                                 <xsl:value-of select="@ind2"/>
548                                         </xsl:when>
549                                         <xsl:otherwise>
550                                                 <xsl:value-of select="@ind1"/>
551                                         </xsl:otherwise>
552                                 </xsl:choose>
553                         </xsl:variable>
554                         <xsl:variable name="titleChop">
555                                 <xsl:call-template name="uri" />
556                                 <xsl:variable name="str">
557                                         <xsl:for-each select="marc:subfield">
558                                                 <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'])))">
559                                                         <xsl:value-of select="text()"/>
560                                                         <xsl:text> </xsl:text>
561                                                 </xsl:if>
562                                         </xsl:for-each>
563                                 </xsl:variable>
564                                 <xsl:call-template name="chopPunctuation">
565                                         <xsl:with-param name="chopString">
566                                                 <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
567                                         </xsl:with-param>
568                                 </xsl:call-template>
569                         </xsl:variable>
570                         <titleInfo type="uniform">
571                                 <title>
572                                         <xsl:value-of select="$titleChop"/>
573                                 </title>
574                                 <xsl:call-template name="part"/>
575                         </titleInfo>
576                         <titleInfo type="uniform-nfi">
577                                 <xsl:choose>
578                                         <xsl:when test="$nfi>0">
579                                                 <nonSort>
580                                                         <xsl:value-of select="substring($titleChop,1,$nfi)"/>
581                                                 </nonSort>
582                                                 <title>
583                                                         <xsl:value-of select="substring($titleChop,$nfi+1)"/>
584                                                 </title>
585                                         </xsl:when>
586                                         <xsl:otherwise>
587                                                 <title>
588                                                         <xsl:value-of select="$titleChop"/>
589                                                 </title>
590                                         </xsl:otherwise>
591                                 </xsl:choose>
592                                 <xsl:call-template name="part"/>
593                         </titleInfo>
594                 </xsl:for-each>
595                 <xsl:for-each select="marc:datafield[@tag='740'][@ind2!='2']">
596                         <xsl:variable name="titleChop">
597                                 <xsl:call-template name="chopPunctuation">
598                                         <xsl:with-param name="chopString">
599                                                 <xsl:call-template name="subfieldSelect">
600                                                         <xsl:with-param name="codes">ah</xsl:with-param>
601                                                 </xsl:call-template>
602                                         </xsl:with-param>
603                                 </xsl:call-template>
604                         </xsl:variable>
605                         <titleInfo type="alternative">
606                                 <title>
607                                         <xsl:value-of select="$titleChop" />
608                                 </title>
609                                 <xsl:call-template name="part"/>
610                         </titleInfo>
611                         <titleInfo type="alternative-nfi">
612                                 <xsl:choose>
613                                         <xsl:when test="@ind1>0">
614                                                 <nonSort>
615                                                         <xsl:value-of select="substring($titleChop,1,@ind1)"/>
616                                                 </nonSort>
617                                                 <title>
618                                                         <xsl:value-of select="substring($titleChop,@ind1+1)"/>
619                                                 </title>
620                                         </xsl:when>
621                                         <xsl:otherwise>
622                                                 <title>
623                                                         <xsl:value-of select="$titleChop" />
624                                                 </title>
625                                         </xsl:otherwise>
626                                 </xsl:choose>
627                                 <xsl:call-template name="part"/>
628                         </titleInfo>
629                 </xsl:for-each>
630                 <xsl:for-each select="marc:datafield[@tag='100']">
631                         <name type="personal">
632                                 <xsl:call-template name="uri" />
633                                 <xsl:call-template name="nameABCDQ"/>
634                                 <xsl:call-template name="affiliation"/>
635                                 <role>
636                                         <roleTerm authority="marcrelator" type="text">creator</roleTerm>
637                                 </role>
638                                 <xsl:call-template name="role"/>
639                         </name>
640                 </xsl:for-each>
641                 <xsl:for-each select="marc:datafield[@tag='110']">
642                         <name type="corporate">
643                                 <xsl:call-template name="uri" />
644                                 <xsl:call-template name="nameABCDN"/>
645                                 <role>
646                                         <roleTerm authority="marcrelator" type="text">creator</roleTerm>
647                                 </role>
648                                 <xsl:call-template name="role"/>
649                         </name>
650                 </xsl:for-each>
651                 <xsl:for-each select="marc:datafield[@tag='111']">
652                         <name type="conference">
653                                 <xsl:call-template name="uri" />
654                                 <xsl:call-template name="nameACDEQ"/>
655                                 <role>
656                                         <roleTerm authority="marcrelator" type="text">creator</roleTerm>
657                                 </role>
658                                 <xsl:call-template name="role"/>
659                         </name>
660                 </xsl:for-each>
661                 <xsl:for-each select="marc:datafield[@tag='700'][not(marc:subfield[@code='t'])]">
662                         <name type="personal">
663                                 <xsl:call-template name="uri" />
664                                 <xsl:call-template name="nameABCDQ"/>
665                                 <xsl:call-template name="affiliation"/>
666                                 <xsl:call-template name="role"/>
667                         </name>
668                 </xsl:for-each>
669                 <xsl:for-each select="marc:datafield[@tag='710'][not(marc:subfield[@code='t'])]">
670                         <name type="corporate">
671                                 <xsl:call-template name="uri" />
672                                 <xsl:call-template name="nameABCDN"/>
673                                 <xsl:call-template name="role"/>
674                         </name>
675                 </xsl:for-each>
676                 <xsl:for-each select="marc:datafield[@tag='711'][not(marc:subfield[@code='t'])]">
677                         <name type="conference">
678                                 <xsl:call-template name="uri" />
679                                 <xsl:call-template name="nameACDEQ"/>
680                                 <xsl:call-template name="role"/>
681                         </name>
682                 </xsl:for-each>
683                 <xsl:for-each select="marc:datafield[@tag='720'][not(marc:subfield[@code='t'])]">
684                         <name>
685                                 <xsl:if test="@ind1=1">
686                                         <xsl:attribute name="type">
687                                                 <xsl:text>personal</xsl:text>
688                                         </xsl:attribute>
689                                 </xsl:if>
690                                 <namePart>
691                                         <xsl:value-of select="marc:subfield[@code='a']"/>
692                                 </namePart>
693                                 <xsl:call-template name="role"/>
694                         </name>
695                 </xsl:for-each>
696                 <typeOfResource>
697                         <xsl:if test="$leader7='c'">
698                                 <xsl:attribute name="collection">yes</xsl:attribute>
699                         </xsl:if>
700                         <xsl:if test="$leader6='d' or $leader6='f' or $leader6='p' or $leader6='t'">
701                                 <xsl:attribute name="manuscript">yes</xsl:attribute>
702                         </xsl:if>
703                         <xsl:choose>
704                                 <xsl:when test="$leader6='a' or $leader6='t'">text</xsl:when>
705                                 <xsl:when test="$leader6='e' or $leader6='f'">cartographic</xsl:when>
706                                 <xsl:when test="$leader6='c' or $leader6='d'">notated music</xsl:when>
707                                 <xsl:when test="$leader6='i'">sound recording-nonmusical</xsl:when>
708                                 <xsl:when test="$leader6='j'">sound recording-musical</xsl:when>
709                                 <xsl:when test="$leader6='k'">still image</xsl:when>
710                                 <xsl:when test="$leader6='g'">moving image</xsl:when>
711                                 <xsl:when test="$leader6='r'">three dimensional object</xsl:when>
712                                 <xsl:when test="$leader6='m'">software, multimedia</xsl:when>
713                                 <xsl:when test="$leader6='p'">mixed material</xsl:when>
714                         </xsl:choose>
715                 </typeOfResource>
716                 <xsl:if test="substring($controlField008,26,1)='d'">
717                         <genre authority="marc">globe</genre>
718                 </xsl:if>
719                 <xsl:if test="marc:controlfield[@tag='007'][substring(text(),1,1)='a'][substring(text(),2,1)='r']">
720                         <genre authority="marc">remote sensing image</genre>
721                 </xsl:if>
722                 <xsl:if test="$typeOf008='MP'">
723                         <xsl:variable name="controlField008-25" select="substring($controlField008,26,1)"></xsl:variable>
724                         <xsl:choose>
725                                 <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']">
726                                         <genre authority="marc">map</genre>
727                                 </xsl:when>
728                                 <xsl:when test="$controlField008-25='e' or marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='d']">
729                                         <genre authority="marc">atlas</genre>
730                                 </xsl:when>
731                         </xsl:choose>
732                 </xsl:if>
733                 <xsl:if test="$typeOf008='SE'">
734                         <xsl:variable name="controlField008-21" select="substring($controlField008,22,1)"></xsl:variable>
735                         <xsl:choose>
736                                 <xsl:when test="$controlField008-21='d'">
737                                         <genre authority="marc">database</genre>
738                                 </xsl:when>
739                                 <xsl:when test="$controlField008-21='l'">
740                                         <genre authority="marc">loose-leaf</genre>
741                                 </xsl:when>
742                                 <xsl:when test="$controlField008-21='m'">
743                                         <genre authority="marc">series</genre>
744                                 </xsl:when>
745                                 <xsl:when test="$controlField008-21='n'">
746                                         <genre authority="marc">newspaper</genre>
747                                 </xsl:when>
748                                 <xsl:when test="$controlField008-21='p'">
749                                         <genre authority="marc">periodical</genre>
750                                 </xsl:when>
751                                 <xsl:when test="$controlField008-21='w'">
752                                         <genre authority="marc">web site</genre>
753                                 </xsl:when>
754                         </xsl:choose>
755                 </xsl:if>
756                 <xsl:if test="$typeOf008='BK' or $typeOf008='SE'">
757                         <xsl:variable name="controlField008-24" select="substring($controlField008,25,4)"></xsl:variable>
758                         <xsl:choose>
759                                 <xsl:when test="contains($controlField008-24,'a')">
760                                         <genre authority="marc">abstract or summary</genre>
761                                 </xsl:when>
762                                 <xsl:when test="contains($controlField008-24,'b')">
763                                         <genre authority="marc">bibliography</genre>
764                                 </xsl:when>
765                                 <xsl:when test="contains($controlField008-24,'c')">
766                                         <genre authority="marc">catalog</genre>
767                                 </xsl:when>
768                                 <xsl:when test="contains($controlField008-24,'d')">
769                                         <genre authority="marc">dictionary</genre>
770                                 </xsl:when>
771                                 <xsl:when test="contains($controlField008-24,'e')">
772                                         <genre authority="marc">encyclopedia</genre>
773                                 </xsl:when>
774                                 <xsl:when test="contains($controlField008-24,'f')">
775                                         <genre authority="marc">handbook</genre>
776                                 </xsl:when>
777                                 <xsl:when test="contains($controlField008-24,'g')">
778                                         <genre authority="marc">legal article</genre>
779                                 </xsl:when>
780                                 <xsl:when test="contains($controlField008-24,'i')">
781                                         <genre authority="marc">index</genre>
782                                 </xsl:when>
783                                 <xsl:when test="contains($controlField008-24,'k')">
784                                         <genre authority="marc">discography</genre>
785                                 </xsl:when>
786                                 <xsl:when test="contains($controlField008-24,'l')">
787                                         <genre authority="marc">legislation</genre>
788                                 </xsl:when>
789                                 <xsl:when test="contains($controlField008-24,'m')">
790                                         <genre authority="marc">theses</genre>
791                                 </xsl:when>
792                                 <xsl:when test="contains($controlField008-24,'n')">
793                                         <genre authority="marc">survey of literature</genre>
794                                 </xsl:when>
795                                 <xsl:when test="contains($controlField008-24,'o')">
796                                         <genre authority="marc">review</genre>
797                                 </xsl:when>
798                                 <xsl:when test="contains($controlField008-24,'p')">
799                                         <genre authority="marc">programmed text</genre>
800                                 </xsl:when>
801                                 <xsl:when test="contains($controlField008-24,'q')">
802                                         <genre authority="marc">filmography</genre>
803                                 </xsl:when>
804                                 <xsl:when test="contains($controlField008-24,'r')">
805                                         <genre authority="marc">directory</genre>
806                                 </xsl:when>
807                                 <xsl:when test="contains($controlField008-24,'s')">
808                                         <genre authority="marc">statistics</genre>
809                                 </xsl:when>
810                                 <xsl:when test="contains($controlField008-24,'t')">
811                                         <genre authority="marc">technical report</genre>
812                                 </xsl:when>
813                                 <xsl:when test="contains($controlField008-24,'v')">
814                                         <genre authority="marc">legal case and case notes</genre>
815                                 </xsl:when>
816                                 <xsl:when test="contains($controlField008-24,'w')">
817                                         <genre authority="marc">law report or digest</genre>
818                                 </xsl:when>
819                                 <xsl:when test="contains($controlField008-24,'z')">
820                                         <genre authority="marc">treaty</genre>
821                                 </xsl:when>
822                         </xsl:choose>
823                         <xsl:variable name="controlField008-29" select="substring($controlField008,30,1)"></xsl:variable>
824                         <xsl:choose>
825                                 <xsl:when test="$controlField008-29='1'">
826                                         <genre authority="marc">conference publication</genre>
827                                 </xsl:when>
828                         </xsl:choose>
829                 </xsl:if>
830                 <xsl:if test="$typeOf008='CF'">
831                         <xsl:variable name="controlField008-26" select="substring($controlField008,27,1)"></xsl:variable>
832                         <xsl:choose>
833                                 <xsl:when test="$controlField008-26='a'">
834                                         <genre authority="marc">numeric data</genre>
835                                 </xsl:when>
836                                 <xsl:when test="$controlField008-26='e'">
837                                         <genre authority="marc">database</genre>
838                                 </xsl:when>
839                                 <xsl:when test="$controlField008-26='f'">
840                                         <genre authority="marc">font</genre>
841                                 </xsl:when>
842                                 <xsl:when test="$controlField008-26='g'">
843                                         <genre authority="marc">game</genre>
844                                 </xsl:when>
845                         </xsl:choose>
846                 </xsl:if>
847                 <xsl:if test="$typeOf008='BK'">
848                         <xsl:if test="substring($controlField008,25,1)='j'">
849                                 <genre authority="marc">patent</genre>
850                         </xsl:if>
851                         <xsl:if test="substring($controlField008,31,1)='1'">
852                                 <genre authority="marc">festschrift</genre>
853                         </xsl:if>
854                         <xsl:variable name="controlField008-34" select="substring($controlField008,35,1)"></xsl:variable>
855                         <xsl:if test="$controlField008-34='a' or $controlField008-34='b' or $controlField008-34='c' or $controlField008-34='d'">
856                                 <genre authority="marc">biography</genre>
857                         </xsl:if>
858                         <xsl:variable name="controlField008-33" select="substring($controlField008,34,1)"></xsl:variable>
859                         <xsl:choose>
860                                 <xsl:when test="$controlField008-33='e'">
861                                         <genre authority="marc">essay</genre>
862                                 </xsl:when>
863                                 <xsl:when test="$controlField008-33='d'">
864                                         <genre authority="marc">drama</genre>
865                                 </xsl:when>
866                                 <xsl:when test="$controlField008-33='c'">
867                                         <genre authority="marc">comic strip</genre>
868                                 </xsl:when>
869                                 <xsl:when test="$controlField008-33='l'">
870                                         <genre authority="marc">fiction</genre>
871                                 </xsl:when>
872                                 <xsl:when test="$controlField008-33='h'">
873                                         <genre authority="marc">humor, satire</genre>
874                                 </xsl:when>
875                                 <xsl:when test="$controlField008-33='i'">
876                                         <genre authority="marc">letter</genre>
877                                 </xsl:when>
878                                 <xsl:when test="$controlField008-33='f'">
879                                         <genre authority="marc">novel</genre>
880                                 </xsl:when>
881                                 <xsl:when test="$controlField008-33='j'">
882                                         <genre authority="marc">short story</genre>
883                                 </xsl:when>
884                                 <xsl:when test="$controlField008-33='s'">
885                                         <genre authority="marc">speech</genre>
886                                 </xsl:when>
887                         </xsl:choose>
888                 </xsl:if>
889                 <xsl:if test="$typeOf008='MU'">
890                         <xsl:variable name="controlField008-30-31" select="substring($controlField008,31,2)"></xsl:variable>
891                         <xsl:if test="contains($controlField008-30-31,'b')">
892                                 <genre authority="marc">biography</genre>
893                         </xsl:if>
894                         <xsl:if test="contains($controlField008-30-31,'c')">
895                                 <genre authority="marc">conference publication</genre>
896                         </xsl:if>
897                         <xsl:if test="contains($controlField008-30-31,'d')">
898                                 <genre authority="marc">drama</genre>
899                         </xsl:if>
900                         <xsl:if test="contains($controlField008-30-31,'e')">
901                                 <genre authority="marc">essay</genre>
902                         </xsl:if>
903                         <xsl:if test="contains($controlField008-30-31,'f')">
904                                 <genre authority="marc">fiction</genre>
905                         </xsl:if>
906                         <xsl:if test="contains($controlField008-30-31,'o')">
907                                 <genre authority="marc">folktale</genre>
908                         </xsl:if>
909                         <xsl:if test="contains($controlField008-30-31,'h')">
910                                 <genre authority="marc">history</genre>
911                         </xsl:if>
912                         <xsl:if test="contains($controlField008-30-31,'k')">
913                                 <genre authority="marc">humor, satire</genre>
914                         </xsl:if>
915                         <xsl:if test="contains($controlField008-30-31,'m')">
916                                 <genre authority="marc">memoir</genre>
917                         </xsl:if>
918                         <xsl:if test="contains($controlField008-30-31,'p')">
919                                 <genre authority="marc">poetry</genre>
920                         </xsl:if>
921                         <xsl:if test="contains($controlField008-30-31,'r')">
922                                 <genre authority="marc">rehearsal</genre>
923                         </xsl:if>
924                         <xsl:if test="contains($controlField008-30-31,'g')">
925                                 <genre authority="marc">reporting</genre>
926                         </xsl:if>
927                         <xsl:if test="contains($controlField008-30-31,'s')">
928                                 <genre authority="marc">sound</genre>
929                         </xsl:if>
930                         <xsl:if test="contains($controlField008-30-31,'l')">
931                                 <genre authority="marc">speech</genre>
932                         </xsl:if>
933                 </xsl:if>
934                 <xsl:if test="$typeOf008='VM'">
935                         <xsl:variable name="controlField008-33" select="substring($controlField008,34,1)"></xsl:variable>
936                         <xsl:choose>
937                                 <xsl:when test="$controlField008-33='a'">
938                                         <genre authority="marc">art original</genre>
939                                 </xsl:when>
940                                 <xsl:when test="$controlField008-33='b'">
941                                         <genre authority="marc">kit</genre>
942                                 </xsl:when>
943                                 <xsl:when test="$controlField008-33='c'">
944                                         <genre authority="marc">art reproduction</genre>
945                                 </xsl:when>
946                                 <xsl:when test="$controlField008-33='d'">
947                                         <genre authority="marc">diorama</genre>
948                                 </xsl:when>
949                                 <xsl:when test="$controlField008-33='f'">
950                                         <genre authority="marc">filmstrip</genre>
951                                 </xsl:when>
952                                 <xsl:when test="$controlField008-33='g'">
953                                         <genre authority="marc">legal article</genre>
954                                 </xsl:when>
955                                 <xsl:when test="$controlField008-33='i'">
956                                         <genre authority="marc">picture</genre>
957                                 </xsl:when>
958                                 <xsl:when test="$controlField008-33='k'">
959                                         <genre authority="marc">graphic</genre>
960                                 </xsl:when>
961                                 <xsl:when test="$controlField008-33='l'">
962                                         <genre authority="marc">technical drawing</genre>
963                                 </xsl:when>
964                                 <xsl:when test="$controlField008-33='m'">
965                                         <genre authority="marc">motion picture</genre>
966                                 </xsl:when>
967                                 <xsl:when test="$controlField008-33='n'">
968                                         <genre authority="marc">chart</genre>
969                                 </xsl:when>
970                                 <xsl:when test="$controlField008-33='o'">
971                                         <genre authority="marc">flash card</genre>
972                                 </xsl:when>
973                                 <xsl:when test="$controlField008-33='p'">
974                                         <genre authority="marc">microscope slide</genre>
975                                 </xsl:when>
976                                 <xsl:when test="$controlField008-33='q' or marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='q']">
977                                         <genre authority="marc">model</genre>
978                                 </xsl:when>
979                                 <xsl:when test="$controlField008-33='r'">
980                                         <genre authority="marc">realia</genre>
981                                 </xsl:when>
982                                 <xsl:when test="$controlField008-33='s'">
983                                         <genre authority="marc">slide</genre>
984                                 </xsl:when>
985                                 <xsl:when test="$controlField008-33='t'">
986                                         <genre authority="marc">transparency</genre>
987                                 </xsl:when>
988                                 <xsl:when test="$controlField008-33='v'">
989                                         <genre authority="marc">videorecording</genre>
990                                 </xsl:when>
991                                 <xsl:when test="$controlField008-33='w'">
992                                         <genre authority="marc">toy</genre>
993                                 </xsl:when>
994                         </xsl:choose>
995                 </xsl:if>
996                 <xsl:for-each select="marc:datafield[@tag=655]">
997                         <genre authority="marc">
998                                 <xsl:attribute name="authority">
999                                         <xsl:value-of select="marc:subfield[@code='2']"/>
1000                                 </xsl:attribute>
1001                                 <xsl:call-template name="subfieldSelect">
1002                                         <xsl:with-param name="codes">abvxyz</xsl:with-param>
1003                                         <xsl:with-param name="delimeter">-</xsl:with-param>
1004                                 </xsl:call-template>
1005                         </genre>
1006                 </xsl:for-each>
1007                 <originInfo>
1008                         <xsl:variable name="MARCpublicationCode" select="normalize-space(substring($controlField008,16,3))"></xsl:variable>
1009                         <xsl:if test="translate($MARCpublicationCode,'|','')">
1010                                 <place>
1011                                         <placeTerm>
1012                                                 <xsl:attribute name="type">code</xsl:attribute>
1013                                                 <xsl:attribute name="authority">marccountry</xsl:attribute>
1014                                                 <xsl:value-of select="$MARCpublicationCode"/>
1015                                         </placeTerm>
1016                                 </place>
1017                         </xsl:if>
1018                         <xsl:for-each select="marc:datafield[@tag=044]/marc:subfield[@code='c']">
1019                                 <place>
1020                                         <placeTerm>
1021                                                 <xsl:attribute name="type">code</xsl:attribute>
1022                                                 <xsl:attribute name="authority">iso3166</xsl:attribute>
1023                                                 <xsl:value-of select="."/>
1024                                         </placeTerm>
1025                                 </place>
1026                         </xsl:for-each>
1027                         <xsl:for-each select="marc:datafield[@tag=260]/marc:subfield[@code='a']">
1028                                 <place>
1029                                         <placeTerm>
1030                                                 <xsl:attribute name="type">text</xsl:attribute>
1031                                                 <xsl:call-template name="chopPunctuationFront">
1032                                                         <xsl:with-param name="chopString">
1033                                                                 <xsl:call-template name="chopPunctuation">
1034                                                                         <xsl:with-param name="chopString" select="."/>
1035                                                                 </xsl:call-template>
1036                                                         </xsl:with-param>
1037                                                 </xsl:call-template>
1038                                         </placeTerm>
1039                                 </place>
1040                         </xsl:for-each>
1041                         <xsl:for-each select="marc:datafield[@tag=046]/marc:subfield[@code='m']">
1042                                 <dateValid point="start">
1043                                         <xsl:value-of select="."/>
1044                                 </dateValid>
1045                         </xsl:for-each>
1046                         <xsl:for-each select="marc:datafield[@tag=046]/marc:subfield[@code='n']">
1047                                 <dateValid point="end">
1048                                         <xsl:value-of select="."/>
1049                                 </dateValid>
1050                         </xsl:for-each>
1051                         <xsl:for-each select="marc:datafield[@tag=046]/marc:subfield[@code='j']">
1052                                 <dateModified>
1053                                         <xsl:value-of select="."/>
1054                                 </dateModified>
1055                         </xsl:for-each>
1056                         <xsl:for-each select="marc:datafield[@tag=260]/marc:subfield[@code='b' or @code='c' or @code='g']">
1057                                 <xsl:choose>
1058                                         <xsl:when test="@code='b'">
1059                                                 <publisher>
1060                                                         <xsl:call-template name="chopPunctuation">
1061                                                                 <xsl:with-param name="chopString" select="."/>
1062                                                                 <xsl:with-param name="punctuation">
1063                                                                         <xsl:text>:,;/ </xsl:text>
1064                                                                 </xsl:with-param>
1065                                                         </xsl:call-template>
1066                                                 </publisher>
1067                                         </xsl:when>
1068                                         <xsl:when test="@code='c'">
1069                                                 <dateIssued>
1070                                                         <xsl:call-template name="chopPunctuation">
1071                                                                 <xsl:with-param name="chopString" select="."/>
1072                                                         </xsl:call-template>
1073                                                 </dateIssued>
1074                                         </xsl:when>
1075                                         <xsl:when test="@code='g'">
1076                                                 <dateCreated>
1077                                                         <xsl:value-of select="."/>
1078                                                 </dateCreated>
1079                                         </xsl:when>
1080                                 </xsl:choose>
1081                         </xsl:for-each>
1082                         <xsl:variable name="dataField260c">
1083                                 <xsl:call-template name="chopPunctuation">
1084                                         <xsl:with-param name="chopString" select="marc:datafield[@tag=260]/marc:subfield[@code='c']"></xsl:with-param>
1085                                 </xsl:call-template>
1086                         </xsl:variable>
1087                         <xsl:variable name="controlField008-7-10" select="normalize-space(substring($controlField008, 8, 4))"></xsl:variable>
1088                         <xsl:variable name="controlField008-11-14" select="normalize-space(substring($controlField008, 12, 4))"></xsl:variable>
1089                         <xsl:variable name="controlField008-6" select="normalize-space(substring($controlField008, 7, 1))"></xsl:variable>
1090                         <xsl:if test="$controlField008-6='e' or $controlField008-6='p' or $controlField008-6='r' or $controlField008-6='t' or $controlField008-6='s'">
1091                                 <xsl:if test="$controlField008-7-10 and ($controlField008-7-10 != $dataField260c)">
1092                                         <dateIssued encoding="marc">
1093                                                 <xsl:value-of select="$controlField008-7-10"/>
1094                                         </dateIssued>
1095                                 </xsl:if>
1096                         </xsl:if>
1097                         <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'">
1098                                 <xsl:if test="$controlField008-7-10">
1099                                         <dateIssued encoding="marc" point="start">
1100                                                 <xsl:value-of select="$controlField008-7-10"/>
1101                                         </dateIssued>
1102                                 </xsl:if>
1103                         </xsl:if>
1104                         <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'">
1105                                 <xsl:if test="$controlField008-11-14">
1106                                         <dateIssued encoding="marc" point="end">
1107                                                 <xsl:value-of select="$controlField008-11-14"/>
1108                                         </dateIssued>
1109                                 </xsl:if>
1110                         </xsl:if>
1111                         <xsl:if test="$controlField008-6='q'">
1112                                 <xsl:if test="$controlField008-7-10">
1113                                         <dateIssued encoding="marc" point="start" qualifier="questionable">
1114                                                 <xsl:value-of select="$controlField008-7-10"/>
1115                                         </dateIssued>
1116                                 </xsl:if>
1117                         </xsl:if>
1118                         <xsl:if test="$controlField008-6='q'">
1119                                 <xsl:if test="$controlField008-11-14">
1120                                         <dateIssued encoding="marc" point="end" qualifier="questionable">
1121                                                 <xsl:value-of select="$controlField008-11-14"/>
1122                                         </dateIssued>
1123                                 </xsl:if>
1124                         </xsl:if>
1125                         <xsl:if test="$controlField008-6='t'">
1126                                 <xsl:if test="$controlField008-11-14">
1127                                         <copyrightDate encoding="marc">
1128                                                 <xsl:value-of select="$controlField008-11-14"/>
1129                                         </copyrightDate>
1130                                 </xsl:if>
1131                         </xsl:if>
1132                         <xsl:for-each select="marc:datafield[@tag=033][@ind1=0 or @ind1=1]/marc:subfield[@code='a']">
1133                                 <dateCaptured encoding="iso8601">
1134                                         <xsl:value-of select="."/>
1135                                 </dateCaptured>
1136                         </xsl:for-each>
1137                         <xsl:for-each select="marc:datafield[@tag=033][@ind1=2]/marc:subfield[@code='a'][1]">
1138                                 <dateCaptured encoding="iso8601" point="start">
1139                                         <xsl:value-of select="."/>
1140                                 </dateCaptured>
1141                         </xsl:for-each>
1142                         <xsl:for-each select="marc:datafield[@tag=033][@ind1=2]/marc:subfield[@code='a'][2]">
1143                                 <dateCaptured encoding="iso8601" point="end">
1144                                         <xsl:value-of select="."/>
1145                                 </dateCaptured>
1146                         </xsl:for-each>
1147                         <xsl:for-each select="marc:datafield[@tag=250]/marc:subfield[@code='a']">
1148                                 <edition>
1149                                         <xsl:value-of select="."/>
1150                                 </edition>
1151                         </xsl:for-each>
1152                         <xsl:for-each select="marc:leader">
1153                                 <issuance>
1154                                         <xsl:choose>
1155                                                 <xsl:when test="$leader7='a' or $leader7='c' or $leader7='d' or $leader7='m'">monographic</xsl:when>
1156                                                 <xsl:when test="$leader7='b' or $leader7='i' or $leader7='s'">continuing</xsl:when>
1157                                         </xsl:choose>
1158                                 </issuance>
1159                         </xsl:for-each>
1160                         <xsl:for-each select="marc:datafield[@tag=310]|marc:datafield[@tag=321]">
1161                                 <frequency>
1162                                         <xsl:call-template name="subfieldSelect">
1163                                                 <xsl:with-param name="codes">ab</xsl:with-param>
1164                                         </xsl:call-template>
1165                                 </frequency>
1166                         </xsl:for-each>
1167                 </originInfo>
1168                 <xsl:variable name="controlField008-35-37" select="normalize-space(translate(substring($controlField008,36,3),'|#',''))"></xsl:variable>
1169                 <xsl:if test="$controlField008-35-37">
1170                         <language>
1171                                 <languageTerm authority="iso639-2b" type="code">
1172                                         <xsl:value-of select="substring($controlField008,36,3)"/>
1173                                 </languageTerm>
1174                         </language>
1175                 </xsl:if>
1176                 <xsl:for-each select="marc:datafield[@tag=041]">
1177                         <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']">
1178                                 <xsl:variable name="langCodes" select="."/>
1179                                 <xsl:choose>
1180                                         <xsl:when test="../marc:subfield[@code='2']='rfc3066'">
1181                                                 <!-- not stacked but could be repeated -->
1182                                                 <xsl:call-template name="rfcLanguages">
1183                                                         <xsl:with-param name="nodeNum">
1184                                                                 <xsl:value-of select="1"/>
1185                                                         </xsl:with-param>
1186                                                         <xsl:with-param name="usedLanguages">
1187                                                                 <xsl:text></xsl:text>
1188                                                         </xsl:with-param>
1189                                                         <xsl:with-param name="controlField008-35-37">
1190                                                                 <xsl:value-of select="$controlField008-35-37"></xsl:value-of>
1191                                                         </xsl:with-param>
1192                                                 </xsl:call-template>
1193                                         </xsl:when>
1194                                         <xsl:otherwise>
1195                                                 <!-- iso -->
1196                                                 <xsl:variable name="allLanguages">
1197                                                         <xsl:copy-of select="$langCodes"></xsl:copy-of>
1198                                                 </xsl:variable>
1199                                                 <xsl:variable name="currentLanguage">
1200                                                         <xsl:value-of select="substring($allLanguages,1,3)"></xsl:value-of>
1201                                                 </xsl:variable>
1202                                                 <xsl:call-template name="isoLanguage">
1203                                                         <xsl:with-param name="currentLanguage">
1204                                                                 <xsl:value-of select="substring($allLanguages,1,3)"></xsl:value-of>
1205                                                         </xsl:with-param>
1206                                                         <xsl:with-param name="remainingLanguages">
1207                                                                 <xsl:value-of select="substring($allLanguages,4,string-length($allLanguages)-3)"></xsl:value-of>
1208                                                         </xsl:with-param>
1209                                                         <xsl:with-param name="usedLanguages">
1210                                                                 <xsl:if test="$controlField008-35-37">
1211                                                                         <xsl:value-of select="$controlField008-35-37"></xsl:value-of>
1212                                                                 </xsl:if>
1213                                                         </xsl:with-param>
1214                                                 </xsl:call-template>
1215                                         </xsl:otherwise>
1216                                 </xsl:choose>
1217                         </xsl:for-each>
1218                 </xsl:for-each>
1219                 <xsl:variable name="physicalDescription">
1220                         <!--3.2 change tmee 007/11 -->
1221                         <xsl:if test="$typeOf008='CF' and marc:controlfield[@tag=007][substring(.,12,1)='a']">
1222                                 <digitalOrigin>reformatted digital</digitalOrigin>
1223                         </xsl:if>
1224                         <xsl:if test="$typeOf008='CF' and marc:controlfield[@tag=007][substring(.,12,1)='b']">
1225                                 <digitalOrigin>digitized microfilm</digitalOrigin>
1226                         </xsl:if>
1227                         <xsl:if test="$typeOf008='CF' and marc:controlfield[@tag=007][substring(.,12,1)='d']">
1228                                 <digitalOrigin>digitized other analog</digitalOrigin>
1229                         </xsl:if>
1230                         <xsl:variable name="controlField008-23" select="substring($controlField008,24,1)"></xsl:variable>
1231                         <xsl:variable name="controlField008-29" select="substring($controlField008,30,1)"></xsl:variable>
1232                         <xsl:variable name="check008-23">
1233                                 <xsl:if test="$typeOf008='BK' or $typeOf008='MU' or $typeOf008='SE' or $typeOf008='MM'">
1234                                         <xsl:value-of select="true()"></xsl:value-of>
1235                                 </xsl:if>
1236                         </xsl:variable>
1237                         <xsl:variable name="check008-29">
1238                                 <xsl:if test="$typeOf008='MP' or $typeOf008='VM'">
1239                                         <xsl:value-of select="true()"></xsl:value-of>
1240                                 </xsl:if>
1241                         </xsl:variable>
1242                         <xsl:choose>
1243                                 <xsl:when test="($check008-23 and $controlField008-23='f') or ($check008-29 and $controlField008-29='f')">
1244                                         <form authority="marcform">braille</form>
1245                                 </xsl:when>
1246                                 <xsl:when test="($controlField008-23=' ' and ($leader6='c' or $leader6='d')) or (($typeOf008='BK' or $typeOf008='SE') and ($controlField008-23=' ' or $controlField008='r'))">
1247                                         <form authority="marcform">print</form>
1248                                 </xsl:when>
1249                                 <xsl:when test="$leader6 = 'm' or ($check008-23 and $controlField008-23='s') or ($check008-29 and $controlField008-29='s')">
1250                                         <form authority="marcform">electronic</form>
1251                                 </xsl:when>
1252                                 <xsl:when test="($check008-23 and $controlField008-23='b') or ($check008-29 and $controlField008-29='b')">
1253                                         <form authority="marcform">microfiche</form>
1254                                 </xsl:when>
1255                                 <xsl:when test="($check008-23 and $controlField008-23='a') or ($check008-29 and $controlField008-29='a')">
1256                                         <form authority="marcform">microfilm</form>
1257                                 </xsl:when>
1258                         </xsl:choose>
1259                         <!-- 1/04 fix -->
1260                         <xsl:if test="marc:datafield[@tag=130]/marc:subfield[@code='h']">
1261                                 <form authority="gmd">
1262                                         <xsl:call-template name="chopBrackets">
1263                                                 <xsl:with-param name="chopString">
1264                                                         <xsl:value-of select="marc:datafield[@tag=130]/marc:subfield[@code='h']"></xsl:value-of>
1265                                                 </xsl:with-param>
1266                                         </xsl:call-template>
1267                                 </form>
1268                         </xsl:if>
1269                         <xsl:if test="marc:datafield[@tag=240]/marc:subfield[@code='h']">
1270                                 <form authority="gmd">
1271                                         <xsl:call-template name="chopBrackets">
1272                                                 <xsl:with-param name="chopString">
1273                                                         <xsl:value-of select="marc:datafield[@tag=240]/marc:subfield[@code='h']"></xsl:value-of>
1274                                                 </xsl:with-param>
1275                                         </xsl:call-template>
1276                                 </form>
1277                         </xsl:if>
1278                         <xsl:if test="marc:datafield[@tag=242]/marc:subfield[@code='h']">
1279                                 <form authority="gmd">
1280                                         <xsl:call-template name="chopBrackets">
1281                                                 <xsl:with-param name="chopString">
1282                                                         <xsl:value-of select="marc:datafield[@tag=242]/marc:subfield[@code='h']"></xsl:value-of>
1283                                                 </xsl:with-param>
1284                                         </xsl:call-template>
1285                                 </form>
1286                         </xsl:if>
1287                         <xsl:if test="marc:datafield[@tag=245]/marc:subfield[@code='h']">
1288                                 <form authority="gmd">
1289                                         <xsl:call-template name="chopBrackets">
1290                                                 <xsl:with-param name="chopString">
1291                                                         <xsl:value-of select="marc:datafield[@tag=245]/marc:subfield[@code='h']"></xsl:value-of>
1292                                                 </xsl:with-param>
1293                                         </xsl:call-template>
1294                                 </form>
1295                         </xsl:if>
1296                         <xsl:if test="marc:datafield[@tag=246]/marc:subfield[@code='h']">
1297                                 <form authority="gmd">
1298                                         <xsl:call-template name="chopBrackets">
1299                                                 <xsl:with-param name="chopString">
1300                                                         <xsl:value-of select="marc:datafield[@tag=246]/marc:subfield[@code='h']"></xsl:value-of>
1301                                                 </xsl:with-param>
1302                                         </xsl:call-template>
1303                                 </form>
1304                         </xsl:if>
1305                         <xsl:if test="marc:datafield[@tag=730]/marc:subfield[@code='h']">
1306                                 <form authority="gmd">
1307                                         <xsl:call-template name="chopBrackets">
1308                                                 <xsl:with-param name="chopString">
1309                                                         <xsl:value-of select="marc:datafield[@tag=730]/marc:subfield[@code='h']"></xsl:value-of>
1310                                                 </xsl:with-param>
1311                                         </xsl:call-template>
1312                                 </form>
1313                         </xsl:if>
1314                         <xsl:for-each select="marc:datafield[@tag=256]/marc:subfield[@code='a']">
1315                                 <form>
1316                                         <xsl:value-of select="."></xsl:value-of>
1317                                 </form>
1318                         </xsl:for-each>
1319                         <xsl:for-each select="marc:controlfield[@tag=007][substring(text(),1,1)='c']">
1320                                 <xsl:choose>
1321                                         <xsl:when test="substring(text(),14,1)='a'">
1322                                                 <reformattingQuality>access</reformattingQuality>
1323                                         </xsl:when>
1324                                         <xsl:when test="substring(text(),14,1)='p'">
1325                                                 <reformattingQuality>preservation</reformattingQuality>
1326                                         </xsl:when>
1327                                         <xsl:when test="substring(text(),14,1)='r'">
1328                                                 <reformattingQuality>replacement</reformattingQuality>
1329                                         </xsl:when>
1330                                 </xsl:choose>
1331                         </xsl:for-each>
1332                         <!--3.2 change tmee 007/01 -->
1333                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='b']">
1334                                 <form authority="smd">chip cartridge</form>
1335                         </xsl:if>
1336                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='c']">
1337                                 <form authority="smd">computer optical disc cartridge</form>
1338                         </xsl:if>
1339                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='j']">
1340                                 <form authority="smd">magnetic disc</form>
1341                         </xsl:if>
1342                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='m']">
1343                                 <form authority="smd">magneto-optical disc</form>
1344                         </xsl:if>
1345                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='o']">
1346                                 <form authority="smd">optical disc</form>
1347                         </xsl:if>
1348                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='r']">
1349                                 <form authority="smd">remote</form>
1350                         </xsl:if>
1351                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='a']">
1352                                 <form authority="smd">tape cartridge</form>
1353                         </xsl:if>
1354                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='f']">
1355                                 <form authority="smd">tape cassette</form>
1356                         </xsl:if>
1357                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='h']">
1358                                 <form authority="smd">tape reel</form>
1359                         </xsl:if>
1360                         
1361                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='d'][substring(text(),2,1)='a']">
1362                                 <form authority="smd">celestial globe</form>
1363                         </xsl:if>
1364                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='d'][substring(text(),2,1)='e']">
1365                                 <form authority="smd">earth moon globe</form>
1366                         </xsl:if>
1367                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='d'][substring(text(),2,1)='b']">
1368                                 <form authority="smd">planetary or lunar globe</form>
1369                         </xsl:if>
1370                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='d'][substring(text(),2,1)='c']">
1371                                 <form authority="smd">terrestrial globe</form>
1372                         </xsl:if>
1373                         
1374                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='o'][substring(text(),2,1)='o']">
1375                                 <form authority="smd">kit</form>
1376                         </xsl:if>
1377                         
1378                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='d']">
1379                                 <form authority="smd">atlas</form>
1380                         </xsl:if>
1381                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='g']">
1382                                 <form authority="smd">diagram</form>
1383                         </xsl:if>
1384                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='j']">
1385                                 <form authority="smd">map</form>
1386                         </xsl:if>
1387                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='q']">
1388                                 <form authority="smd">model</form>
1389                         </xsl:if>
1390                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='k']">
1391                                 <form authority="smd">profile</form>
1392                         </xsl:if>
1393                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='r']">
1394                                 <form authority="smd">remote-sensing image</form>
1395                         </xsl:if>
1396                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='s']">
1397                                 <form authority="smd">section</form>
1398                         </xsl:if>
1399                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='y']">
1400                                 <form authority="smd">view</form>
1401                         </xsl:if>
1402                         
1403                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='a']">
1404                                 <form authority="smd">aperture card</form>
1405                         </xsl:if>
1406                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='e']">
1407                                 <form authority="smd">microfiche</form>
1408                         </xsl:if>
1409                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='f']">
1410                                 <form authority="smd">microfiche cassette</form>
1411                         </xsl:if>
1412                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='b']">
1413                                 <form authority="smd">microfilm cartridge</form>
1414                         </xsl:if>
1415                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='c']">
1416                                 <form authority="smd">microfilm cassette</form>
1417                         </xsl:if>
1418                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='d']">
1419                                 <form authority="smd">microfilm reel</form>
1420                         </xsl:if>
1421                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='g']">
1422                                 <form authority="smd">microopaque</form>
1423                         </xsl:if>
1424                         
1425                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='m'][substring(text(),2,1)='c']">
1426                                 <form authority="smd">film cartridge</form>
1427                         </xsl:if>
1428                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='m'][substring(text(),2,1)='f']">
1429                                 <form authority="smd">film cassette</form>
1430                         </xsl:if>
1431                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='m'][substring(text(),2,1)='r']">
1432                                 <form authority="smd">film reel</form>
1433                         </xsl:if>
1434                         
1435                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='n']">
1436                                 <form authority="smd">chart</form>
1437                         </xsl:if>
1438                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='c']">
1439                                 <form authority="smd">collage</form>
1440                         </xsl:if>
1441                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='d']">
1442                                 <form authority="smd">drawing</form>
1443                         </xsl:if>
1444                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='o']">
1445                                 <form authority="smd">flash card</form>
1446                         </xsl:if>
1447                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='e']">
1448                                 <form authority="smd">painting</form>
1449                         </xsl:if>
1450                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='f']">
1451                                 <form authority="smd">photomechanical print</form>
1452                         </xsl:if>
1453                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='g']">
1454                                 <form authority="smd">photonegative</form>
1455                         </xsl:if>
1456                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='h']">
1457                                 <form authority="smd">photoprint</form>
1458                         </xsl:if>
1459                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='i']">
1460                                 <form authority="smd">picture</form>
1461                         </xsl:if>
1462                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='j']">
1463                                 <form authority="smd">print</form>
1464                         </xsl:if>
1465                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='l']">
1466                                 <form authority="smd">technical drawing</form>
1467                         </xsl:if>
1468                         
1469                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='q'][substring(text(),2,1)='q']">
1470                                 <form authority="smd">notated music</form>
1471                         </xsl:if>
1472                         
1473                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='d']">
1474                                 <form authority="smd">filmslip</form>
1475                         </xsl:if>
1476                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='c']">
1477                                 <form authority="smd">filmstrip cartridge</form>
1478                         </xsl:if>
1479                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='o']">
1480                                 <form authority="smd">filmstrip roll</form>
1481                         </xsl:if>
1482                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='f']">
1483                                 <form authority="smd">other filmstrip type</form>
1484                         </xsl:if>
1485                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='s']">
1486                                 <form authority="smd">slide</form>
1487                         </xsl:if>
1488                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='t']">
1489                                 <form authority="smd">transparency</form>
1490                         </xsl:if>
1491                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='r'][substring(text(),2,1)='r']">
1492                                 <form authority="smd">remote-sensing image</form>
1493                         </xsl:if>
1494                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='e']">
1495                                 <form authority="smd">cylinder</form>
1496                         </xsl:if>
1497                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='q']">
1498                                 <form authority="smd">roll</form>
1499                         </xsl:if>
1500                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='g']">
1501                                 <form authority="smd">sound cartridge</form>
1502                         </xsl:if>
1503                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='s']">
1504                                 <form authority="smd">sound cassette</form>
1505                         </xsl:if>
1506                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='d']">
1507                                 <form authority="smd">sound disc</form>
1508                         </xsl:if>
1509                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='t']">
1510                                 <form authority="smd">sound-tape reel</form>
1511                         </xsl:if>
1512                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='i']">
1513                                 <form authority="smd">sound-track film</form>
1514                         </xsl:if>
1515                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='w']">
1516                                 <form authority="smd">wire recording</form>
1517                         </xsl:if>
1518                         
1519                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='f'][substring(text(),2,1)='c']">
1520                                 <form authority="smd">braille</form>
1521                         </xsl:if>
1522                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='f'][substring(text(),2,1)='b']">
1523                                 <form authority="smd">combination</form>
1524                         </xsl:if>
1525                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='f'][substring(text(),2,1)='a']">
1526                                 <form authority="smd">moon</form>
1527                         </xsl:if>
1528                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='f'][substring(text(),2,1)='d']">
1529                                 <form authority="smd">tactile, with no writing system</form>
1530                         </xsl:if>
1531                         
1532                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='t'][substring(text(),2,1)='c']">
1533                                 <form authority="smd">braille</form>
1534                         </xsl:if>
1535                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='t'][substring(text(),2,1)='b']">
1536                                 <form authority="smd">large print</form>
1537                         </xsl:if>
1538                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='t'][substring(text(),2,1)='a']">
1539                                 <form authority="smd">regular print</form>
1540                         </xsl:if>
1541                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='t'][substring(text(),2,1)='d']">
1542                                 <form authority="smd">text in looseleaf binder</form>
1543                         </xsl:if>
1544                         
1545                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='v'][substring(text(),2,1)='c']">
1546                                 <form authority="smd">videocartridge</form>
1547                         </xsl:if>
1548                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='v'][substring(text(),2,1)='f']">
1549                                 <form authority="smd">videocassette</form>
1550                         </xsl:if>
1551                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='v'][substring(text(),2,1)='d']">
1552                                 <form authority="smd">videodisc</form>
1553                         </xsl:if>
1554                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='v'][substring(text(),2,1)='r']">
1555                                 <form authority="smd">videoreel</form>
1556                         </xsl:if>
1557                         
1558                         <xsl:for-each select="marc:datafield[@tag=856]/marc:subfield[@code='q'][string-length(.)>1]">
1559                                 <internetMediaType>
1560                                         <xsl:value-of select="."></xsl:value-of>
1561                                 </internetMediaType>
1562                         </xsl:for-each>
1563                         <xsl:for-each select="marc:datafield[@tag=300]">
1564                                 <extent>
1565                                         <xsl:call-template name="subfieldSelect">
1566                                                 <xsl:with-param name="codes">abce</xsl:with-param>
1567                                         </xsl:call-template>
1568                                 </extent>
1569                         </xsl:for-each>
1570                 </xsl:variable>
1571                 <xsl:if test="string-length(normalize-space($physicalDescription))">
1572                         <physicalDescription>
1573                                 <xsl:copy-of select="$physicalDescription"></xsl:copy-of>
1574                         </physicalDescription>
1575                 </xsl:if>
1576                 <xsl:for-each select="marc:datafield[@tag=520]">
1577                         <abstract>
1578                                 <xsl:call-template name="uri"></xsl:call-template>
1579                                 <xsl:call-template name="subfieldSelect">
1580                                         <xsl:with-param name="codes">ab</xsl:with-param>
1581                                 </xsl:call-template>
1582                         </abstract>
1583                 </xsl:for-each>
1584                 <xsl:for-each select="marc:datafield[@tag=505]">
1585                         <tableOfContents>
1586                                 <xsl:call-template name="uri"></xsl:call-template>
1587                                 <xsl:call-template name="subfieldSelect">
1588                                         <xsl:with-param name="codes">agrt</xsl:with-param>
1589                                 </xsl:call-template>
1590                         </tableOfContents>
1591                 </xsl:for-each>
1592                 <xsl:for-each select="marc:datafield[@tag=521]">
1593                         <targetAudience>
1594                                 <xsl:call-template name="subfieldSelect">
1595                                         <xsl:with-param name="codes">ab</xsl:with-param>
1596                                 </xsl:call-template>
1597                         </targetAudience>
1598                 </xsl:for-each>
1599                 <xsl:if test="$typeOf008='BK' or $typeOf008='CF' or $typeOf008='MU' or $typeOf008='VM'">
1600                         <xsl:variable name="controlField008-22" select="substring($controlField008,23,1)"></xsl:variable>
1601                         <xsl:choose>
1602                                 <!-- 01/04 fix -->
1603                                 <xsl:when test="$controlField008-22='d'">
1604                                         <targetAudience authority="marctarget">adolescent</targetAudience>
1605                                 </xsl:when>
1606                                 <xsl:when test="$controlField008-22='e'">
1607                                         <targetAudience authority="marctarget">adult</targetAudience>
1608                                 </xsl:when>
1609                                 <xsl:when test="$controlField008-22='g'">
1610                                         <targetAudience authority="marctarget">general</targetAudience>
1611                                 </xsl:when>
1612                                 <xsl:when test="$controlField008-22='b' or $controlField008-22='c' or $controlField008-22='j'">
1613                                         <targetAudience authority="marctarget">juvenile</targetAudience>
1614                                 </xsl:when>
1615                                 <xsl:when test="$controlField008-22='a'">
1616                                         <targetAudience authority="marctarget">preschool</targetAudience>
1617                                 </xsl:when>
1618                                 <xsl:when test="$controlField008-22='f'">
1619                                         <targetAudience authority="marctarget">specialized</targetAudience>
1620                                 </xsl:when>
1621                         </xsl:choose>
1622                 </xsl:if>
1623                 <xsl:for-each select="marc:datafield[@tag=245]/marc:subfield[@code='c']">
1624                         <note type="statement of responsibility">
1625                                 <xsl:value-of select="."></xsl:value-of>
1626                         </note>
1627                 </xsl:for-each>
1628                 <xsl:for-each select="marc:datafield[@tag=500]">
1629                         <note>
1630                                 <xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
1631                                 <xsl:call-template name="uri"></xsl:call-template>
1632                         </note>
1633                 </xsl:for-each>
1634                 
1635                 <!--3.2 change tmee additional note fields-->
1636                 
1637                 <xsl:for-each select="marc:datafield[@tag=506]">
1638                         <note type="restrictions">
1639                                 <xsl:call-template name="uri"></xsl:call-template>
1640                                 <xsl:variable name="str">
1641                                         <xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
1642                                                 <xsl:value-of select="."></xsl:value-of>
1643                                                 <xsl:text> </xsl:text>
1644                                         </xsl:for-each>
1645                                 </xsl:variable>
1646                                 <xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
1647                         </note>
1648                 </xsl:for-each>
1649                 
1650                 <xsl:for-each select="marc:datafield[@tag=510]">
1651                         <note  type="citation/reference">
1652                                 <xsl:call-template name="uri"></xsl:call-template>
1653                                 <xsl:variable name="str">
1654                                         <xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
1655                                                 <xsl:value-of select="."></xsl:value-of>
1656                                                 <xsl:text> </xsl:text>
1657                                         </xsl:for-each>
1658                                 </xsl:variable>
1659                                 <xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
1660                         </note>
1661                 </xsl:for-each>
1662                 
1663                         
1664                 <xsl:for-each select="marc:datafield[@tag=511]">
1665                         <note type="performers">
1666                                 <xsl:call-template name="uri"></xsl:call-template>
1667                                 <xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
1668                         </note>
1669                 </xsl:for-each>
1670                 <xsl:for-each select="marc:datafield[@tag=518]">
1671                         <note type="venue">
1672                                 <xsl:call-template name="uri"></xsl:call-template>
1673                                 <xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
1674                         </note>
1675                 </xsl:for-each>
1676                 
1677                 <xsl:for-each select="marc:datafield[@tag=530]">
1678                         <note  type="additional physical form">
1679                                 <xsl:call-template name="uri"></xsl:call-template>
1680                                 <xsl:variable name="str">
1681                                         <xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
1682                                                 <xsl:value-of select="."></xsl:value-of>
1683                                                 <xsl:text> </xsl:text>
1684                                         </xsl:for-each>
1685                                 </xsl:variable>
1686                                 <xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
1687                         </note>
1688                 </xsl:for-each>
1689                 
1690                 <xsl:for-each select="marc:datafield[@tag=533]">
1691                         <note  type="reproduction">
1692                                 <xsl:call-template name="uri"></xsl:call-template>
1693                                 <xsl:variable name="str">
1694                                         <xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
1695                                                 <xsl:value-of select="."></xsl:value-of>
1696                                                 <xsl:text> </xsl:text>
1697                                         </xsl:for-each>
1698                                 </xsl:variable>
1699                                 <xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
1700                         </note>
1701                 </xsl:for-each>
1702                 
1703                 <xsl:for-each select="marc:datafield[@tag=534]">
1704                         <note  type="original version">
1705                                 <xsl:call-template name="uri"></xsl:call-template>
1706                                 <xsl:variable name="str">
1707                                         <xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
1708                                                 <xsl:value-of select="."></xsl:value-of>
1709                                                 <xsl:text> </xsl:text>
1710                                         </xsl:for-each>
1711                                 </xsl:variable>
1712                                 <xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
1713                         </note>
1714                 </xsl:for-each>
1715                 
1716                 <xsl:for-each select="marc:datafield[@tag=538]">
1717                         <note  type="system details">
1718                                 <xsl:call-template name="uri"></xsl:call-template>
1719                                 <xsl:variable name="str">
1720                                         <xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
1721                                                 <xsl:value-of select="."></xsl:value-of>
1722                                                 <xsl:text> </xsl:text>
1723                                         </xsl:for-each>
1724                                 </xsl:variable>
1725                                 <xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
1726                         </note>
1727                 </xsl:for-each>
1728                 
1729                 <xsl:for-each select="marc:datafield[@tag=583]">
1730                         <note type="action">
1731                                 <xsl:call-template name="uri"></xsl:call-template>
1732                                 <xsl:variable name="str">
1733                                         <xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
1734                                                 <xsl:value-of select="."></xsl:value-of>
1735                                                 <xsl:text> </xsl:text>
1736                                         </xsl:for-each>
1737                                 </xsl:variable>
1738                                 <xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
1739                         </note>
1740                 </xsl:for-each>
1741                 
1742
1743                 
1744                 
1745                 
1746                 <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]">
1747                         <note>
1748                                 <xsl:call-template name="uri"></xsl:call-template>
1749                                 <xsl:variable name="str">
1750                                         <xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
1751                                                 <xsl:value-of select="."></xsl:value-of>
1752                                                 <xsl:text> </xsl:text>
1753                                         </xsl:for-each>
1754                                 </xsl:variable>
1755                                 <xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
1756                         </note>
1757                 </xsl:for-each>
1758                 <xsl:for-each select="marc:datafield[@tag=034][marc:subfield[@code='d' or @code='e' or @code='f' or @code='g']]">
1759                         <subject>
1760                                 <cartographics>
1761                                         <coordinates>
1762                                                 <xsl:call-template name="subfieldSelect">
1763                                                         <xsl:with-param name="codes">defg</xsl:with-param>
1764                                                 </xsl:call-template>
1765                                         </coordinates>
1766                                 </cartographics>
1767                         </subject>
1768                 </xsl:for-each>
1769                 <xsl:for-each select="marc:datafield[@tag=043]">
1770                         <subject>
1771                                 <xsl:for-each select="marc:subfield[@code='a' or @code='b' or @code='c']">
1772                                         <geographicCode>
1773                                                 <xsl:attribute name="authority">
1774                                                         <xsl:if test="@code='a'">
1775                                                                 <xsl:text>marcgac</xsl:text>
1776                                                         </xsl:if>
1777                                                         <xsl:if test="@code='b'">
1778                                                                 <xsl:value-of select="following-sibling::marc:subfield[@code=2]"></xsl:value-of>
1779                                                         </xsl:if>
1780                                                         <xsl:if test="@code='c'">
1781                                                                 <xsl:text>iso3166</xsl:text>
1782                                                         </xsl:if>
1783                                                 </xsl:attribute>
1784                                                 <xsl:value-of select="self::marc:subfield"></xsl:value-of>
1785                                         </geographicCode>
1786                                 </xsl:for-each>
1787                         </subject>
1788                 </xsl:for-each>
1789                 <!-- tmee 2006/11/27 -->
1790                 <xsl:for-each select="marc:datafield[@tag=255]">
1791                         <subject>
1792                                 <xsl:for-each select="marc:subfield[@code='a' or @code='b' or @code='c']">
1793                                 <cartographics>
1794                                         <xsl:if test="@code='a'">
1795                                                 <scale>
1796                                                         <xsl:value-of select="."></xsl:value-of>
1797                                                 </scale>
1798                                         </xsl:if>
1799                                         <xsl:if test="@code='b'">
1800                                                 <projection>
1801                                                         <xsl:value-of select="."></xsl:value-of>
1802                                                 </projection>
1803                                         </xsl:if>
1804                                         <xsl:if test="@code='c'">
1805                                                 <coordinates>
1806                                                         <xsl:value-of select="."></xsl:value-of>
1807                                                 </coordinates>
1808                                         </xsl:if>
1809                                 </cartographics>
1810                                 </xsl:for-each>
1811                         </subject>
1812                 </xsl:for-each>
1813                                 
1814                 <xsl:apply-templates select="marc:datafield[653 >= @tag and @tag >= 600]"></xsl:apply-templates>
1815                 <xsl:apply-templates select="marc:datafield[@tag=656]"></xsl:apply-templates>
1816                 <xsl:for-each select="marc:datafield[@tag=752]">
1817                         <subject>
1818                                 <hierarchicalGeographic>
1819                                         <xsl:for-each select="marc:subfield[@code='a']">
1820                                                 <country>
1821                                                         <xsl:call-template name="chopPunctuation">
1822                                                                 <xsl:with-param name="chopString" select="."></xsl:with-param>
1823                                                         </xsl:call-template>
1824                                                 </country>
1825                                         </xsl:for-each>
1826                                         <xsl:for-each select="marc:subfield[@code='b']">
1827                                                 <state>
1828                                                         <xsl:call-template name="chopPunctuation">
1829                                                                 <xsl:with-param name="chopString" select="."></xsl:with-param>
1830                                                         </xsl:call-template>
1831                                                 </state>
1832                                         </xsl:for-each>
1833                                         <xsl:for-each select="marc:subfield[@code='c']">
1834                                                 <county>
1835                                                         <xsl:call-template name="chopPunctuation">
1836                                                                 <xsl:with-param name="chopString" select="."></xsl:with-param>
1837                                                         </xsl:call-template>
1838                                                 </county>
1839                                         </xsl:for-each>
1840                                         <xsl:for-each select="marc:subfield[@code='d']">
1841                                                 <city>
1842                                                         <xsl:call-template name="chopPunctuation">
1843                                                                 <xsl:with-param name="chopString" select="."></xsl:with-param>
1844                                                         </xsl:call-template>
1845                                                 </city>
1846                                         </xsl:for-each>
1847                                 </hierarchicalGeographic>
1848                         </subject>
1849                 </xsl:for-each>
1850                 <xsl:for-each select="marc:datafield[@tag=045][marc:subfield[@code='b']]">
1851                         <subject>
1852                                 <xsl:choose>
1853                                         <xsl:when test="@ind1=2">
1854                                                 <temporal encoding="iso8601" point="start">
1855                                                         <xsl:call-template name="chopPunctuation">
1856                                                                 <xsl:with-param name="chopString">
1857                                                                         <xsl:value-of select="marc:subfield[@code='b'][1]"></xsl:value-of>
1858                                                                 </xsl:with-param>
1859                                                         </xsl:call-template>
1860                                                 </temporal>
1861                                                 <temporal encoding="iso8601" point="end">
1862                                                         <xsl:call-template name="chopPunctuation">
1863                                                                 <xsl:with-param name="chopString">
1864                                                                         <xsl:value-of select="marc:subfield[@code='b'][2]"></xsl:value-of>
1865                                                                 </xsl:with-param>
1866                                                         </xsl:call-template>
1867                                                 </temporal>
1868                                         </xsl:when>
1869                                         <xsl:otherwise>
1870                                                 <xsl:for-each select="marc:subfield[@code='b']">
1871                                                         <temporal encoding="iso8601">
1872                                                                 <xsl:call-template name="chopPunctuation">
1873                                                                         <xsl:with-param name="chopString" select="."></xsl:with-param>
1874                                                                 </xsl:call-template>
1875                                                         </temporal>
1876                                                 </xsl:for-each>
1877                                         </xsl:otherwise>
1878                                 </xsl:choose>
1879                         </subject>
1880                 </xsl:for-each>
1881                 <xsl:for-each select="marc:datafield[@tag=050]">
1882                         <xsl:for-each select="marc:subfield[@code='b']">
1883                                 <classification authority="lcc">
1884                                         <xsl:if test="../marc:subfield[@code='3']">
1885                                                 <xsl:attribute name="displayLabel">
1886                                                         <xsl:value-of select="../marc:subfield[@code='3']"></xsl:value-of>
1887                                                 </xsl:attribute>
1888                                         </xsl:if>
1889                                         <xsl:value-of select="preceding-sibling::marc:subfield[@code='a'][1]"></xsl:value-of>
1890                                         <xsl:text> </xsl:text>
1891                                         <xsl:value-of select="text()"></xsl:value-of>
1892                                 </classification>
1893                         </xsl:for-each>
1894                         <xsl:for-each select="marc:subfield[@code='a'][not(following-sibling::marc:subfield[@code='b'])]">
1895                                 <classification authority="lcc">
1896                                         <xsl:if test="../marc:subfield[@code='3']">
1897                                                 <xsl:attribute name="displayLabel">
1898                                                         <xsl:value-of select="../marc:subfield[@code='3']"></xsl:value-of>
1899                                                 </xsl:attribute>
1900                                         </xsl:if>
1901                                         <xsl:value-of select="text()"></xsl:value-of>
1902                                 </classification>
1903                         </xsl:for-each>
1904                 </xsl:for-each>
1905                 <xsl:for-each select="marc:datafield[@tag=082]">
1906                         <classification authority="ddc">
1907                                 <xsl:if test="marc:subfield[@code='2']">
1908                                         <xsl:attribute name="edition">
1909                                                 <xsl:value-of select="marc:subfield[@code='2']"></xsl:value-of>
1910                                         </xsl:attribute>
1911                                 </xsl:if>
1912                                 <xsl:call-template name="subfieldSelect">
1913                                         <xsl:with-param name="codes">ab</xsl:with-param>
1914                                 </xsl:call-template>
1915                         </classification>
1916                 </xsl:for-each>
1917                 <xsl:for-each select="marc:datafield[@tag=080]">
1918                         <classification authority="udc">
1919                                 <xsl:call-template name="subfieldSelect">
1920                                         <xsl:with-param name="codes">abx</xsl:with-param>
1921                                 </xsl:call-template>
1922                         </classification>
1923                 </xsl:for-each>
1924                 <xsl:for-each select="marc:datafield[@tag=060]">
1925                         <classification authority="nlm">
1926                                 <xsl:call-template name="subfieldSelect">
1927                                         <xsl:with-param name="codes">ab</xsl:with-param>
1928                                 </xsl:call-template>
1929                         </classification>
1930                 </xsl:for-each>
1931                 <xsl:for-each select="marc:datafield[@tag=086][@ind1=0]">
1932                         <classification authority="sudocs">
1933                                 <xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
1934                         </classification>
1935                 </xsl:for-each>
1936                 <xsl:for-each select="marc:datafield[@tag=086][@ind1=1]">
1937                         <classification authority="candoc">
1938                                 <xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
1939                         </classification>
1940                 </xsl:for-each>
1941                 <xsl:for-each select="marc:datafield[@tag=086]">
1942                         <classification>
1943                                 <xsl:attribute name="authority">
1944                                         <xsl:value-of select="marc:subfield[@code='2']"></xsl:value-of>
1945                                 </xsl:attribute>
1946                                 <xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
1947                         </classification>
1948                 </xsl:for-each>
1949                 <xsl:for-each select="marc:datafield[@tag=084]">
1950                         <classification>
1951                                 <xsl:attribute name="authority">
1952                                         <xsl:value-of select="marc:subfield[@code='2']"></xsl:value-of>
1953                                 </xsl:attribute>
1954                                 <xsl:call-template name="subfieldSelect">
1955                                         <xsl:with-param name="codes">ab</xsl:with-param>
1956                                 </xsl:call-template>
1957                         </classification>
1958                 </xsl:for-each>
1959                 <xsl:for-each select="marc:datafield[@tag=440]">
1960                         <relatedItem type="series">
1961                                 <xsl:variable name="titleChop">
1962                                         <xsl:call-template name="chopPunctuation">
1963                                                 <xsl:with-param name="chopString">
1964                                                         <xsl:call-template name="subfieldSelect">
1965                                                                 <xsl:with-param name="codes">av</xsl:with-param>
1966                                                         </xsl:call-template>
1967                                                 </xsl:with-param>
1968                                         </xsl:call-template>
1969                                 </xsl:variable>
1970                                 <titleInfo>
1971                                         <title>
1972                                                 <xsl:value-of select="$titleChop" />
1973                                         </title>
1974                                         <xsl:call-template name="part"></xsl:call-template>
1975                                 </titleInfo>
1976                                 <titleInfo type="nfi">
1977                                         <xsl:choose>
1978                                                 <xsl:when test="@ind2>0">
1979                                                         <nonSort>
1980                                                                 <xsl:value-of select="substring($titleChop,1,@ind2)"/>
1981                                                         </nonSort>
1982                                                         <title>
1983                                                                 <xsl:value-of select="substring($titleChop,@ind2+1)"/>
1984                                                         </title>
1985                                                         <xsl:call-template name="part"/>
1986                                                 </xsl:when>
1987                                                 <xsl:otherwise>
1988                                                         <title>
1989                                                                 <xsl:value-of select="$titleChop" />
1990                                                         </title>
1991                                                 </xsl:otherwise>
1992                                         </xsl:choose>
1993                                         <xsl:call-template name="part"></xsl:call-template>
1994                                 </titleInfo>
1995                         </relatedItem>
1996                 </xsl:for-each>
1997                 <xsl:for-each select="marc:datafield[@tag=490][@ind1=0]">
1998                         <relatedItem type="series">
1999                                 <titleInfo>
2000                                         <title>
2001                                                 <xsl:call-template name="chopPunctuation">
2002                                                         <xsl:with-param name="chopString">
2003                                                                 <xsl:call-template name="subfieldSelect">
2004                                                                         <xsl:with-param name="codes">av</xsl:with-param>
2005                                                                 </xsl:call-template>
2006                                                         </xsl:with-param>
2007                                                 </xsl:call-template>
2008                                         </title>
2009                                         <xsl:call-template name="part"></xsl:call-template>
2010                                 </titleInfo>
2011                         </relatedItem>
2012                 </xsl:for-each>
2013                 <xsl:for-each select="marc:datafield[@tag=510]">
2014                         <relatedItem type="isReferencedBy">
2015                                 <note>
2016                                         <xsl:call-template name="subfieldSelect">
2017                                                 <xsl:with-param name="codes">abcx3</xsl:with-param>
2018                                         </xsl:call-template>
2019                                 </note>
2020                         </relatedItem>
2021                 </xsl:for-each>
2022                 <xsl:for-each select="marc:datafield[@tag=534]">
2023                         <relatedItem type="original">
2024                                 <xsl:call-template name="relatedTitle"></xsl:call-template>
2025                                 <xsl:call-template name="relatedName"></xsl:call-template>
2026                                 <xsl:if test="marc:subfield[@code='b' or @code='c']">
2027                                         <originInfo>
2028                                                 <xsl:for-each select="marc:subfield[@code='c']">
2029                                                         <publisher>
2030                                                                 <xsl:value-of select="."></xsl:value-of>
2031                                                         </publisher>
2032                                                 </xsl:for-each>
2033                                                 <xsl:for-each select="marc:subfield[@code='b']">
2034                                                         <edition>
2035                                                                 <xsl:value-of select="."></xsl:value-of>
2036                                                         </edition>
2037                                                 </xsl:for-each>
2038                                         </originInfo>
2039                                 </xsl:if>
2040                                 <xsl:call-template name="relatedIdentifierISSN"></xsl:call-template>
2041                                 <xsl:for-each select="marc:subfield[@code='z']">
2042                                         <identifier type="isbn">
2043                                                 <xsl:value-of select="."></xsl:value-of>
2044                                         </identifier>
2045                                 </xsl:for-each>
2046                                 <xsl:call-template name="relatedNote"></xsl:call-template>
2047                         </relatedItem>
2048                 </xsl:for-each>
2049                 <xsl:for-each select="marc:datafield[@tag=700][marc:subfield[@code='t']]">
2050                         <relatedItem>
2051                                 <xsl:call-template name="constituentOrRelatedType"></xsl:call-template>
2052                                 <titleInfo>
2053                                         <title>
2054                                                 <xsl:call-template name="chopPunctuation">
2055                                                         <xsl:with-param name="chopString">
2056                                                                 <xsl:call-template name="specialSubfieldSelect">
2057                                                                         <xsl:with-param name="anyCodes">tfklmorsv</xsl:with-param>
2058                                                                         <xsl:with-param name="axis">t</xsl:with-param>
2059                                                                         <xsl:with-param name="afterCodes">g</xsl:with-param>
2060                                                                 </xsl:call-template>
2061                                                         </xsl:with-param>
2062                                                 </xsl:call-template>
2063                                         </title>
2064                                         <xsl:call-template name="part"></xsl:call-template>
2065                                 </titleInfo>
2066                                 <name type="personal">
2067                                         <namePart>
2068                                                 <xsl:call-template name="specialSubfieldSelect">
2069                                                         <xsl:with-param name="anyCodes">aq</xsl:with-param>
2070                                                         <xsl:with-param name="axis">t</xsl:with-param>
2071                                                         <xsl:with-param name="beforeCodes">g</xsl:with-param>
2072                                                 </xsl:call-template>
2073                                         </namePart>
2074                                         <xsl:call-template name="termsOfAddress"></xsl:call-template>
2075                                         <xsl:call-template name="nameDate"></xsl:call-template>
2076                                         <xsl:call-template name="role"></xsl:call-template>
2077                                 </name>
2078                                 <xsl:call-template name="relatedForm"></xsl:call-template>
2079                                 <xsl:call-template name="relatedIdentifierISSN"></xsl:call-template>
2080                         </relatedItem>
2081                 </xsl:for-each>
2082                 <xsl:for-each select="marc:datafield[@tag=710][marc:subfield[@code='t']]">
2083                         <relatedItem>
2084                                 <xsl:call-template name="constituentOrRelatedType"></xsl:call-template>
2085                                 <titleInfo>
2086                                         <title>
2087                                                 <xsl:call-template name="chopPunctuation">
2088                                                         <xsl:with-param name="chopString">
2089                                                                 <xsl:call-template name="specialSubfieldSelect">
2090                                                                         <xsl:with-param name="anyCodes">tfklmorsv</xsl:with-param>
2091                                                                         <xsl:with-param name="axis">t</xsl:with-param>
2092                                                                         <xsl:with-param name="afterCodes">dg</xsl:with-param>
2093                                                                 </xsl:call-template>
2094                                                         </xsl:with-param>
2095                                                 </xsl:call-template>
2096                                         </title>
2097                                         <xsl:call-template name="relatedPartNumName"></xsl:call-template>
2098                                 </titleInfo>
2099                                 <name type="corporate">
2100                                         <xsl:for-each select="marc:subfield[@code='a']">
2101                                                 <namePart>
2102                                                         <xsl:value-of select="."></xsl:value-of>
2103                                                 </namePart>
2104                                         </xsl:for-each>
2105                                         <xsl:for-each select="marc:subfield[@code='b']">
2106                                                 <namePart>
2107                                                         <xsl:value-of select="."></xsl:value-of>
2108                                                 </namePart>
2109                                         </xsl:for-each>
2110                                         <xsl:variable name="tempNamePart">
2111                                                 <xsl:call-template name="specialSubfieldSelect">
2112                                                         <xsl:with-param name="anyCodes">c</xsl:with-param>
2113                                                         <xsl:with-param name="axis">t</xsl:with-param>
2114                                                         <xsl:with-param name="beforeCodes">dgn</xsl:with-param>
2115                                                 </xsl:call-template>
2116                                         </xsl:variable>
2117                                         <xsl:if test="normalize-space($tempNamePart)">
2118                                                 <namePart>
2119                                                         <xsl:value-of select="$tempNamePart"></xsl:value-of>
2120                                                 </namePart>
2121                                         </xsl:if>
2122                                         <xsl:call-template name="role"></xsl:call-template>
2123                                 </name>
2124                                 <xsl:call-template name="relatedForm"></xsl:call-template>
2125                                 <xsl:call-template name="relatedIdentifierISSN"></xsl:call-template>
2126                         </relatedItem>
2127                 </xsl:for-each>
2128                 <xsl:for-each select="marc:datafield[@tag=711][marc:subfield[@code='t']]">
2129                         <relatedItem>
2130                                 <xsl:call-template name="constituentOrRelatedType"></xsl:call-template>
2131                                 <titleInfo>
2132                                         <title>
2133                                                 <xsl:call-template name="chopPunctuation">
2134                                                         <xsl:with-param name="chopString">
2135                                                                 <xsl:call-template name="specialSubfieldSelect">
2136                                                                         <xsl:with-param name="anyCodes">tfklsv</xsl:with-param>
2137                                                                         <xsl:with-param name="axis">t</xsl:with-param>
2138                                                                         <xsl:with-param name="afterCodes">g</xsl:with-param>
2139                                                                 </xsl:call-template>
2140                                                         </xsl:with-param>
2141                                                 </xsl:call-template>
2142                                         </title>
2143                                         <xsl:call-template name="relatedPartNumName"></xsl:call-template>
2144                                 </titleInfo>
2145                                 <name type="conference">
2146                                         <namePart>
2147                                                 <xsl:call-template name="specialSubfieldSelect">
2148                                                         <xsl:with-param name="anyCodes">aqdc</xsl:with-param>
2149                                                         <xsl:with-param name="axis">t</xsl:with-param>
2150                                                         <xsl:with-param name="beforeCodes">gn</xsl:with-param>
2151                                                 </xsl:call-template>
2152                                         </namePart>
2153                                 </name>
2154                                 <xsl:call-template name="relatedForm"></xsl:call-template>
2155                                 <xsl:call-template name="relatedIdentifierISSN"></xsl:call-template>
2156                         </relatedItem>
2157                 </xsl:for-each>
2158                 <xsl:for-each select="marc:datafield[@tag=730][@ind2=2]">
2159                         <relatedItem>
2160                                 <xsl:call-template name="constituentOrRelatedType"></xsl:call-template>
2161                                 <titleInfo>
2162                                         <title>
2163                                                 <xsl:call-template name="chopPunctuation">
2164                                                         <xsl:with-param name="chopString">
2165                                                                 <xsl:call-template name="subfieldSelect">
2166                                                                         <xsl:with-param name="codes">adfgklmorsv</xsl:with-param>
2167                                                                 </xsl:call-template>
2168                                                         </xsl:with-param>
2169                                                 </xsl:call-template>
2170                                         </title>
2171                                         <xsl:call-template name="part"></xsl:call-template>
2172                                 </titleInfo>
2173                                 <xsl:call-template name="relatedForm"></xsl:call-template>
2174                                 <xsl:call-template name="relatedIdentifierISSN"></xsl:call-template>
2175                         </relatedItem>
2176                 </xsl:for-each>
2177                 <xsl:for-each select="marc:datafield[@tag=740][@ind2=2]">
2178                         <relatedItem>
2179                                 <xsl:call-template name="constituentOrRelatedType"></xsl:call-template>
2180                                 <xsl:variable name="titleChop">
2181                                         <xsl:call-template name="chopPunctuation">
2182                                                 <xsl:with-param name="chopString">
2183                                                         <xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
2184                                                 </xsl:with-param>
2185                                         </xsl:call-template>
2186                                 </xsl:variable>
2187                                 <titleInfo>
2188                                         <title>
2189                                                 <xsl:value-of select="$titleChop" />
2190                                         </title>
2191                                         <xsl:call-template name="part"></xsl:call-template>
2192                                 </titleInfo>
2193                                 <titleInfo type="nfi">
2194                                         <xsl:choose>
2195                                                 <xsl:when test="@ind1>0">
2196                                                         <nonSort>
2197                                                                 <xsl:value-of select="substring($titleChop,1,@ind1)"/>
2198                                                         </nonSort>
2199                                                         <title>
2200                                                                 <xsl:value-of select="substring($titleChop,@ind1+1)"/>
2201                                                         </title>
2202                                                 </xsl:when>
2203                                                 <xsl:otherwise>
2204                                                         <title>
2205                                                                 <xsl:value-of select="$titleChop" />
2206                                                         </title>
2207                                                 </xsl:otherwise>
2208                                         </xsl:choose>
2209                                         <xsl:call-template name="part"></xsl:call-template>
2210                                 </titleInfo>
2211                                 <xsl:call-template name="relatedForm"></xsl:call-template>
2212                         </relatedItem>
2213                 </xsl:for-each>
2214                 <xsl:for-each select="marc:datafield[@tag=760]|marc:datafield[@tag=762]">
2215                         <relatedItem type="series">
2216                                 <xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
2217                         </relatedItem>
2218                 </xsl:for-each>
2219                 <xsl:for-each select="marc:datafield[@tag=765]|marc:datafield[@tag=767]|marc:datafield[@tag=777]|marc:datafield[@tag=787]">
2220                         <relatedItem>
2221                                 <xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
2222                         </relatedItem>
2223                 </xsl:for-each>
2224                 <xsl:for-each select="marc:datafield[@tag=775]">
2225                         <relatedItem type="otherVersion">
2226                                 <xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
2227                         </relatedItem>
2228                 </xsl:for-each>
2229                 <xsl:for-each select="marc:datafield[@tag=770]|marc:datafield[@tag=774]">
2230                         <relatedItem type="constituent">
2231                                 <xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
2232                         </relatedItem>
2233                 </xsl:for-each>
2234                 <xsl:for-each select="marc:datafield[@tag=772]|marc:datafield[@tag=773]">
2235                         <relatedItem type="host">
2236                                 <xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
2237                         </relatedItem>
2238                 </xsl:for-each>
2239                 <xsl:for-each select="marc:datafield[@tag=776]">
2240                         <relatedItem type="otherFormat">
2241                                 <xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
2242                         </relatedItem>
2243                 </xsl:for-each>
2244                 <xsl:for-each select="marc:datafield[@tag=780]">
2245                         <relatedItem type="preceding">
2246                                 <xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
2247                         </relatedItem>
2248                 </xsl:for-each>
2249                 <xsl:for-each select="marc:datafield[@tag=785]">
2250                         <relatedItem type="succeeding">
2251                                 <xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
2252                         </relatedItem>
2253                 </xsl:for-each>
2254                 <xsl:for-each select="marc:datafield[@tag=786]">
2255                         <relatedItem type="original">
2256                                 <xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
2257                         </relatedItem>
2258                 </xsl:for-each>
2259                 <xsl:for-each select="marc:datafield[@tag=800]">
2260                         <relatedItem type="series">
2261                                 <titleInfo>
2262                                         <title>
2263                                                 <xsl:call-template name="chopPunctuation">
2264                                                         <xsl:with-param name="chopString">
2265                                                                 <xsl:call-template name="specialSubfieldSelect">
2266                                                                         <xsl:with-param name="anyCodes">tfklmorsv</xsl:with-param>
2267                                                                         <xsl:with-param name="axis">t</xsl:with-param>
2268                                                                         <xsl:with-param name="afterCodes">g</xsl:with-param>
2269                                                                 </xsl:call-template>
2270                                                         </xsl:with-param>
2271                                                 </xsl:call-template>
2272                                         </title>
2273                                         <xsl:call-template name="part"></xsl:call-template>
2274                                 </titleInfo>
2275                                 <name type="personal">
2276                                         <namePart>
2277                                                 <xsl:call-template name="chopPunctuation">
2278                                                         <xsl:with-param name="chopString">
2279                                                                 <xsl:call-template name="specialSubfieldSelect">
2280                                                                         <xsl:with-param name="anyCodes">aq</xsl:with-param>
2281                                                                         <xsl:with-param name="axis">t</xsl:with-param>
2282                                                                         <xsl:with-param name="beforeCodes">g</xsl:with-param>
2283                                                                 </xsl:call-template>
2284                                                         </xsl:with-param>
2285                                                 </xsl:call-template>
2286                                         </namePart>
2287                                         <xsl:call-template name="termsOfAddress"></xsl:call-template>
2288                                         <xsl:call-template name="nameDate"></xsl:call-template>
2289                                         <xsl:call-template name="role"></xsl:call-template>
2290                                 </name>
2291                                 <xsl:call-template name="relatedForm"></xsl:call-template>
2292                         </relatedItem>
2293                 </xsl:for-each>
2294                 <xsl:for-each select="marc:datafield[@tag=810]">
2295                         <relatedItem type="series">
2296                                 <titleInfo>
2297                                         <title>
2298                                                 <xsl:call-template name="chopPunctuation">
2299                                                         <xsl:with-param name="chopString">
2300                                                                 <xsl:call-template name="specialSubfieldSelect">
2301                                                                         <xsl:with-param name="anyCodes">tfklmorsv</xsl:with-param>
2302                                                                         <xsl:with-param name="axis">t</xsl:with-param>
2303                                                                         <xsl:with-param name="afterCodes">dg</xsl:with-param>
2304                                                                 </xsl:call-template>
2305                                                         </xsl:with-param>
2306                                                 </xsl:call-template>
2307                                         </title>
2308                                         <xsl:call-template name="relatedPartNumName"></xsl:call-template>
2309                                 </titleInfo>
2310                                 <name type="corporate">
2311                                         <xsl:for-each select="marc:subfield[@code='a']">
2312                                                 <namePart>
2313                                                         <xsl:value-of select="."></xsl:value-of>
2314                                                 </namePart>
2315                                         </xsl:for-each>
2316                                         <xsl:for-each select="marc:subfield[@code='b']">
2317                                                 <namePart>
2318                                                         <xsl:value-of select="."></xsl:value-of>
2319                                                 </namePart>
2320                                         </xsl:for-each>
2321                                         <namePart>
2322                                                 <xsl:call-template name="specialSubfieldSelect">
2323                                                         <xsl:with-param name="anyCodes">c</xsl:with-param>
2324                                                         <xsl:with-param name="axis">t</xsl:with-param>
2325                                                         <xsl:with-param name="beforeCodes">dgn</xsl:with-param>
2326                                                 </xsl:call-template>
2327                                         </namePart>
2328                                         <xsl:call-template name="role"></xsl:call-template>
2329                                 </name>
2330                                 <xsl:call-template name="relatedForm"></xsl:call-template>
2331                         </relatedItem>
2332                 </xsl:for-each>
2333                 <xsl:for-each select="marc:datafield[@tag=811]">
2334                         <relatedItem type="series">
2335                                 <titleInfo>
2336                                         <title>
2337                                                 <xsl:call-template name="chopPunctuation">
2338                                                         <xsl:with-param name="chopString">
2339                                                                 <xsl:call-template name="specialSubfieldSelect">
2340                                                                         <xsl:with-param name="anyCodes">tfklsv</xsl:with-param>
2341                                                                         <xsl:with-param name="axis">t</xsl:with-param>
2342                                                                         <xsl:with-param name="afterCodes">g</xsl:with-param>
2343                                                                 </xsl:call-template>
2344                                                         </xsl:with-param>
2345                                                 </xsl:call-template>
2346                                         </title>
2347                                         <xsl:call-template name="relatedPartNumName"/>
2348                                 </titleInfo>
2349                                 <name type="conference">
2350                                         <namePart>
2351                                                 <xsl:call-template name="specialSubfieldSelect">
2352                                                         <xsl:with-param name="anyCodes">aqdc</xsl:with-param>
2353                                                         <xsl:with-param name="axis">t</xsl:with-param>
2354                                                         <xsl:with-param name="beforeCodes">gn</xsl:with-param>
2355                                                 </xsl:call-template>
2356                                         </namePart>
2357                                         <xsl:call-template name="role"/>
2358                                 </name>
2359                                 <xsl:call-template name="relatedForm"/>
2360                         </relatedItem>
2361                 </xsl:for-each>
2362                 <xsl:for-each select="marc:datafield[@tag='830']">
2363                         <relatedItem type="series">
2364                                 <xsl:variable name="titleChop">
2365                                         <xsl:call-template name="chopPunctuation">
2366                                                 <xsl:with-param name="chopString">
2367                                                         <xsl:call-template name="subfieldSelect">
2368                                                                 <xsl:with-param name="codes">adfgklmorsv</xsl:with-param>
2369                                                         </xsl:call-template>
2370                                                 </xsl:with-param>
2371                                         </xsl:call-template>
2372                                 </xsl:variable>
2373                                 <titleInfo>
2374                                         <title>
2375                                                 <xsl:value-of select="$titleChop" />
2376                                         </title>
2377                                         <xsl:call-template name="part"/>
2378                                 </titleInfo>
2379                                 <titleInfo type="nfi">
2380                                         <xsl:choose>
2381                                                 <xsl:when test="@ind2>0">
2382                                                         <nonSort>
2383                                                                 <xsl:value-of select="substring($titleChop,1,@ind2)"/>
2384                                                         </nonSort>
2385                                                         <title>
2386                                                                 <xsl:value-of select="substring($titleChop,@ind2+1)"/>
2387                                                         </title>
2388                                                 </xsl:when>
2389                                                 <xsl:otherwise>
2390                                                         <title>
2391                                                                 <xsl:value-of select="$titleChop" />
2392                                                         </title>
2393                                                 </xsl:otherwise>
2394                                         </xsl:choose>
2395                                         <xsl:call-template name="part"/>
2396                                 </titleInfo>
2397                                 <xsl:call-template name="relatedForm"/>
2398                         </relatedItem>
2399                 </xsl:for-each>
2400                 <xsl:for-each select="marc:datafield[@tag='856'][@ind2='2']/marc:subfield[@code='q']">
2401                         <relatedItem>
2402                                 <internetMediaType>
2403                                         <xsl:value-of select="."/>
2404                                 </internetMediaType>
2405                         </relatedItem>
2406                 </xsl:for-each>
2407                 <xsl:for-each select="marc:datafield[@tag='020']">
2408                         <xsl:call-template name="isInvalid">
2409                                 <xsl:with-param name="type">isbn</xsl:with-param>
2410                         </xsl:call-template>
2411                         <xsl:if test="marc:subfield[@code='a']">
2412                                 <identifier type="isbn">
2413                                         <xsl:value-of select="marc:subfield[@code='a']"/>
2414                                 </identifier>
2415                         </xsl:if>
2416                 </xsl:for-each>
2417                 <xsl:for-each select="marc:datafield[@tag='024'][@ind1='0']">
2418                         <xsl:call-template name="isInvalid">
2419                                 <xsl:with-param name="type">isrc</xsl:with-param>
2420                         </xsl:call-template>
2421                         <xsl:if test="marc:subfield[@code='a']">
2422                                 <identifier type="isrc">
2423                                         <xsl:value-of select="marc:subfield[@code='a']"/>
2424                                 </identifier>
2425                         </xsl:if>
2426                 </xsl:for-each>
2427                 <xsl:for-each select="marc:datafield[@tag='024'][@ind1='2']">
2428                         <xsl:call-template name="isInvalid">
2429                                 <xsl:with-param name="type">ismn</xsl:with-param>
2430                         </xsl:call-template>
2431                         <xsl:if test="marc:subfield[@code='a']">
2432                                 <identifier type="ismn">
2433                                         <xsl:value-of select="marc:subfield[@code='a']"/>
2434                                 </identifier>
2435                         </xsl:if>
2436                 </xsl:for-each>
2437                 <xsl:for-each select="marc:datafield[@tag='024'][@ind1='4']">
2438                         <xsl:call-template name="isInvalid">
2439                                 <xsl:with-param name="type">sici</xsl:with-param>
2440                         </xsl:call-template>
2441                         <identifier type="sici">
2442                                 <xsl:call-template name="subfieldSelect">
2443                                         <xsl:with-param name="codes">ab</xsl:with-param>
2444                                 </xsl:call-template>
2445                         </identifier>
2446                 </xsl:for-each>
2447                 <xsl:for-each select="marc:datafield[@tag='022']">
2448                         <xsl:call-template name="isInvalid">
2449                                 <xsl:with-param name="type">issn</xsl:with-param>
2450                         </xsl:call-template>
2451                         <identifier type="issn">
2452                                 <xsl:value-of select="marc:subfield[@code='a']"/>
2453                         </identifier>
2454                 </xsl:for-each>
2455                 <xsl:for-each select="marc:datafield[@tag='010']">
2456                         <xsl:call-template name="isInvalid">
2457                                 <xsl:with-param name="type">lccn</xsl:with-param>
2458                         </xsl:call-template>
2459                         <identifier type="lccn">
2460                                 <xsl:value-of select="normalize-space(marc:subfield[@code='a'])"/>
2461                         </identifier>
2462                 </xsl:for-each>
2463                 <xsl:for-each select="marc:datafield[@tag='028']">
2464                         <identifier>
2465                                 <xsl:attribute name="type">
2466                                         <xsl:choose>
2467                                                 <xsl:when test="@ind1='0'">issue number</xsl:when>
2468                                                 <xsl:when test="@ind1='1'">matrix number</xsl:when>
2469                                                 <xsl:when test="@ind1='2'">music plate</xsl:when>
2470                                                 <xsl:when test="@ind1='3'">music publisher</xsl:when>
2471                                                 <xsl:when test="@ind1='4'">videorecording identifier</xsl:when>
2472                                         </xsl:choose>
2473                                 </xsl:attribute>
2474                                 <!--<xsl:call-template name="isInvalid"/>--> <!-- no $z in 028 -->
2475                                 <xsl:call-template name="subfieldSelect">
2476                                         <xsl:with-param name="codes">
2477                                                 <xsl:choose>
2478                                                         <xsl:when test="@ind1='0'">ba</xsl:when>
2479                                                         <xsl:otherwise>ab</xsl:otherwise>
2480                                                 </xsl:choose>
2481                                         </xsl:with-param>
2482                                 </xsl:call-template>
2483                         </identifier>
2484                 </xsl:for-each>
2485                 <xsl:for-each select="marc:datafield[@tag='037']">
2486                         <identifier type="stock number">
2487                                 <!--<xsl:call-template name="isInvalid"/>--> <!-- no $z in 037 -->
2488                                 <xsl:call-template name="subfieldSelect">
2489                                         <xsl:with-param name="codes">ab</xsl:with-param>
2490                                 </xsl:call-template>
2491                         </identifier>
2492                 </xsl:for-each>
2493                 <xsl:for-each select="marc:datafield[@tag='856'][marc:subfield[@code='u']]">
2494                         <identifier>
2495                                 <xsl:attribute name="type">
2496                                         <xsl:choose>
2497                                                 <xsl:when test="starts-with(marc:subfield[@code='u'],'urn:doi') or starts-with(marc:subfield[@code='u'],'doi')">doi</xsl:when>
2498                                                 <xsl:when test="starts-with(marc:subfield[@code='u'],'urn:hdl') or starts-with(marc:subfield[@code='u'],'hdl') or starts-with(marc:subfield[@code='u'],'http://hdl.loc.gov')">hdl</xsl:when>
2499                                                 <xsl:otherwise>uri</xsl:otherwise>
2500                                         </xsl:choose>
2501                                 </xsl:attribute>
2502                                 <xsl:choose>
2503                                         <xsl:when test="starts-with(marc:subfield[@code='u'],'urn:hdl') or starts-with(marc:subfield[@code='u'],'hdl') or starts-with(marc:subfield[@code='u'],'http://hdl.loc.gov') ">
2504                                                 <xsl:value-of select="concat('hdl:',substring-after(marc:subfield[@code='u'],'http://hdl.loc.gov/'))"></xsl:value-of>
2505                                         </xsl:when>
2506                                         <xsl:otherwise>
2507                                                 <xsl:value-of select="marc:subfield[@code='u']"></xsl:value-of>
2508                                         </xsl:otherwise>
2509                                 </xsl:choose>
2510                         </identifier>
2511                         <xsl:if test="starts-with(marc:subfield[@code='u'],'urn:hdl') or starts-with(marc:subfield[@code='u'],'hdl')">
2512                                 <identifier type="hdl">
2513                                         <xsl:if test="marc:subfield[@code='y' or @code='3' or @code='z']">
2514                                                 <xsl:attribute name="displayLabel">
2515                                                         <xsl:call-template name="subfieldSelect">
2516                                                                 <xsl:with-param name="codes">y3z</xsl:with-param>
2517                                                         </xsl:call-template>
2518                                                 </xsl:attribute>
2519                                         </xsl:if>
2520                                         <xsl:value-of select="concat('hdl:',substring-after(marc:subfield[@code='u'],'http://hdl.loc.gov/'))"></xsl:value-of>
2521                                 </identifier>
2522                         </xsl:if>
2523                 </xsl:for-each>
2524                 <xsl:for-each select="marc:datafield[@tag=024][@ind1=1]">
2525                         <identifier type="upc">
2526                                 <xsl:call-template name="isInvalid"/>
2527                                 <xsl:value-of select="marc:subfield[@code='a']"/>
2528                         </identifier>
2529                 </xsl:for-each>
2530                 <!-- 1/04 fix added $y -->
2531                 <xsl:for-each select="marc:datafield[@tag=856][marc:subfield[@code='u']]">
2532                         <location>
2533                                 <url>
2534                                         <xsl:if test="marc:subfield[@code='y' or @code='3']">
2535                                                 <xsl:attribute name="displayLabel">
2536                                                         <xsl:call-template name="subfieldSelect">
2537                                                                 <xsl:with-param name="codes">y3</xsl:with-param>
2538                                                         </xsl:call-template>
2539                                                 </xsl:attribute>
2540                                         </xsl:if>
2541                                         <xsl:if test="marc:subfield[@code='z' ]">
2542                                                 <xsl:attribute name="note">
2543                                                         <xsl:call-template name="subfieldSelect">
2544                                                                 <xsl:with-param name="codes">z</xsl:with-param>
2545                                                         </xsl:call-template>
2546                                                 </xsl:attribute>
2547                                         </xsl:if>
2548                                         <xsl:value-of select="marc:subfield[@code='u']"></xsl:value-of>
2549
2550                                 </url>
2551                         </location>
2552                 </xsl:for-each>
2553                         
2554                         <!-- 3.2 change tmee 856z  -->
2555
2556                 
2557                 <xsl:for-each select="marc:datafield[@tag=852]">
2558                         <location>
2559                                 <physicalLocation>
2560                                         <xsl:call-template name="displayLabel"></xsl:call-template>
2561                                         <xsl:call-template name="subfieldSelect">
2562                                                 <xsl:with-param name="codes">abje</xsl:with-param>
2563                                         </xsl:call-template>
2564                                 </physicalLocation>
2565                         </location>
2566                 </xsl:for-each>
2567                 <xsl:for-each select="marc:datafield[@tag=506]">
2568                         <accessCondition type="restrictionOnAccess">
2569                                 <xsl:call-template name="subfieldSelect">
2570                                         <xsl:with-param name="codes">abcd35</xsl:with-param>
2571                                 </xsl:call-template>
2572                         </accessCondition>
2573                 </xsl:for-each>
2574                 <xsl:for-each select="marc:datafield[@tag=540]">
2575                         <accessCondition type="useAndReproduction">
2576                                 <xsl:call-template name="subfieldSelect">
2577                                         <xsl:with-param name="codes">abcde35</xsl:with-param>
2578                                 </xsl:call-template>
2579                         </accessCondition>
2580                 </xsl:for-each>
2581                 <recordInfo>
2582                         <xsl:for-each select="marc:datafield[@tag=040]">
2583                                 <recordContentSource authority="marcorg">
2584                                         <xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
2585                                 </recordContentSource>
2586                         </xsl:for-each>
2587                         <xsl:for-each select="marc:controlfield[@tag=008]">
2588                                 <recordCreationDate encoding="marc">
2589                                         <xsl:value-of select="substring(.,1,6)"></xsl:value-of>
2590                                 </recordCreationDate>
2591                         </xsl:for-each>
2592                         <xsl:for-each select="marc:controlfield[@tag=005]">
2593                                 <recordChangeDate encoding="iso8601">
2594                                         <xsl:value-of select="."></xsl:value-of>
2595                                 </recordChangeDate>
2596                         </xsl:for-each>
2597                         <xsl:for-each select="marc:controlfield[@tag=001]">
2598                                 <recordIdentifier>
2599                                         <xsl:if test="../marc:controlfield[@tag=003]">
2600                                                 <xsl:attribute name="source">
2601                                                         <xsl:value-of select="../marc:controlfield[@tag=003]"></xsl:value-of>
2602                                                 </xsl:attribute>
2603                                         </xsl:if>
2604                                         <xsl:value-of select="."></xsl:value-of>
2605                                 </recordIdentifier>
2606                         </xsl:for-each>
2607                         <xsl:for-each select="marc:datafield[@tag=040]/marc:subfield[@code='b']">
2608                                 <languageOfCataloging>
2609                                         <languageTerm authority="iso639-2b" type="code">
2610                                                 <xsl:value-of select="."></xsl:value-of>
2611                                         </languageTerm>
2612                                 </languageOfCataloging>
2613                         </xsl:for-each>
2614                 </recordInfo>
2615         </xsl:template>
2616         <xsl:template name="displayForm">
2617                 <xsl:for-each select="marc:subfield[@code='c']">
2618                         <displayForm>
2619                                 <xsl:value-of select="."></xsl:value-of>
2620                         </displayForm>
2621                 </xsl:for-each>
2622         </xsl:template>
2623         <xsl:template name="affiliation">
2624                 <xsl:for-each select="marc:subfield[@code='u']">
2625                         <affiliation>
2626                                 <xsl:value-of select="."></xsl:value-of>
2627                         </affiliation>
2628                 </xsl:for-each>
2629         </xsl:template>
2630         <xsl:template name="uri">
2631                 <xsl:for-each select="marc:subfield[@code='u']">
2632                         <xsl:attribute name="xlink:href">
2633                                 <xsl:value-of select="."></xsl:value-of>
2634                         </xsl:attribute>
2635                 </xsl:for-each>
2636                 <xsl:for-each select="marc:subfield[@code='0']">
2637                         <xsl:choose>
2638                                 <xsl:when test="contains(text(), ')')">
2639                                         <xsl:attribute name="xlink:href">
2640                                                 <xsl:value-of select="substring-after(text(), ')')"></xsl:value-of>
2641                                         </xsl:attribute>
2642                                 </xsl:when>
2643                                 <xsl:otherwise>
2644                                         <xsl:attribute name="xlink:href">
2645                                                 <xsl:value-of select="."></xsl:value-of>
2646                                         </xsl:attribute>
2647                                 </xsl:otherwise>
2648                         </xsl:choose>
2649                 </xsl:for-each>
2650         </xsl:template>
2651         <xsl:template name="role">
2652                 <xsl:for-each select="marc:subfield[@code='e']">
2653                         <role>
2654                                 <roleTerm type="text">
2655                                         <xsl:value-of select="."></xsl:value-of>
2656                                 </roleTerm>
2657                         </role>
2658                 </xsl:for-each>
2659                 <xsl:for-each select="marc:subfield[@code='4']">
2660                         <role>
2661                                 <roleTerm authority="marcrelator" type="code">
2662                                         <xsl:value-of select="."></xsl:value-of>
2663                                 </roleTerm>
2664                         </role>
2665                 </xsl:for-each>
2666         </xsl:template>
2667         <xsl:template name="part">
2668                 <xsl:variable name="partNumber">
2669                         <xsl:call-template name="specialSubfieldSelect">
2670                                 <xsl:with-param name="axis">n</xsl:with-param>
2671                                 <xsl:with-param name="anyCodes">n</xsl:with-param>
2672                                 <xsl:with-param name="afterCodes">fgkdlmor</xsl:with-param>
2673                         </xsl:call-template>
2674                 </xsl:variable>
2675                 <xsl:variable name="partName">
2676                         <xsl:call-template name="specialSubfieldSelect">
2677                                 <xsl:with-param name="axis">p</xsl:with-param>
2678                                 <xsl:with-param name="anyCodes">p</xsl:with-param>
2679                                 <xsl:with-param name="afterCodes">fgkdlmor</xsl:with-param>
2680                         </xsl:call-template>
2681                 </xsl:variable>
2682                 <xsl:if test="string-length(normalize-space($partNumber))">
2683                         <partNumber>
2684                                 <xsl:call-template name="chopPunctuation">
2685                                         <xsl:with-param name="chopString" select="$partNumber"></xsl:with-param>
2686                                 </xsl:call-template>
2687                         </partNumber>
2688                 </xsl:if>
2689                 <xsl:if test="string-length(normalize-space($partName))">
2690                         <partName>
2691                                 <xsl:call-template name="chopPunctuation">
2692                                         <xsl:with-param name="chopString" select="$partName"></xsl:with-param>
2693                                 </xsl:call-template>
2694                         </partName>
2695                 </xsl:if>
2696         </xsl:template>
2697         <xsl:template name="relatedPart">
2698                 <xsl:if test="@tag=773">
2699                         <xsl:for-each select="marc:subfield[@code='g']">
2700                                 <part>
2701                                         <text>
2702                                                 <xsl:value-of select="."></xsl:value-of>
2703                                         </text>
2704                                 </part>
2705                         </xsl:for-each>
2706                         <xsl:for-each select="marc:subfield[@code='q']">
2707                                 <part>
2708                                         <xsl:call-template name="parsePart"></xsl:call-template>
2709                                 </part>
2710                         </xsl:for-each>
2711                 </xsl:if>
2712         </xsl:template>
2713         <xsl:template name="relatedPartNumName">
2714                 <xsl:variable name="partNumber">
2715                         <xsl:call-template name="specialSubfieldSelect">
2716                                 <xsl:with-param name="axis">g</xsl:with-param>
2717                                 <xsl:with-param name="anyCodes">g</xsl:with-param>
2718                                 <xsl:with-param name="afterCodes">pst</xsl:with-param>
2719                         </xsl:call-template>
2720                 </xsl:variable>
2721                 <xsl:variable name="partName">
2722                         <xsl:call-template name="specialSubfieldSelect">
2723                                 <xsl:with-param name="axis">p</xsl:with-param>
2724                                 <xsl:with-param name="anyCodes">p</xsl:with-param>
2725                                 <xsl:with-param name="afterCodes">fgkdlmor</xsl:with-param>
2726                         </xsl:call-template>
2727                 </xsl:variable>
2728                 <xsl:if test="string-length(normalize-space($partNumber))">
2729                         <partNumber>
2730                                 <xsl:value-of select="$partNumber"></xsl:value-of>
2731                         </partNumber>
2732                 </xsl:if>
2733                 <xsl:if test="string-length(normalize-space($partName))">
2734                         <partName>
2735                                 <xsl:value-of select="$partName"></xsl:value-of>
2736                         </partName>
2737                 </xsl:if>
2738         </xsl:template>
2739         <xsl:template name="relatedName">
2740                 <xsl:for-each select="marc:subfield[@code='a']">
2741                         <name>
2742                                 <namePart>
2743                                         <xsl:value-of select="."></xsl:value-of>
2744                                 </namePart>
2745                         </name>
2746                 </xsl:for-each>
2747         </xsl:template>
2748         <xsl:template name="relatedForm">
2749                 <xsl:for-each select="marc:subfield[@code='h']">
2750                         <physicalDescription>
2751                                 <form>
2752                                         <xsl:value-of select="."></xsl:value-of>
2753                                 </form>
2754                         </physicalDescription>
2755                 </xsl:for-each>
2756         </xsl:template>
2757         <xsl:template name="relatedExtent">
2758                 <xsl:for-each select="marc:subfield[@code='h']">
2759                         <physicalDescription>
2760                                 <extent>
2761                                         <xsl:value-of select="."></xsl:value-of>
2762                                 </extent>
2763                         </physicalDescription>
2764                 </xsl:for-each>
2765         </xsl:template>
2766         <xsl:template name="relatedNote">
2767                 <xsl:for-each select="marc:subfield[@code='n']">
2768                         <note>
2769                                 <xsl:value-of select="."></xsl:value-of>
2770                         </note>
2771                 </xsl:for-each>
2772         </xsl:template>
2773         <xsl:template name="relatedSubject">
2774                 <xsl:for-each select="marc:subfield[@code='j']">
2775                         <subject>
2776                                 <temporal encoding="iso8601">
2777                                         <xsl:call-template name="chopPunctuation">
2778                                                 <xsl:with-param name="chopString" select="."></xsl:with-param>
2779                                         </xsl:call-template>
2780                                 </temporal>
2781                         </subject>
2782                 </xsl:for-each>
2783         </xsl:template>
2784         <xsl:template name="relatedIdentifierISSN">
2785                 <xsl:for-each select="marc:subfield[@code='x']">
2786                         <identifier type="issn">
2787                                 <xsl:value-of select="."></xsl:value-of>
2788                         </identifier>
2789                 </xsl:for-each>
2790         </xsl:template>
2791         <xsl:template name="relatedIdentifierLocal">
2792                 <xsl:for-each select="marc:subfield[@code='w']">
2793                         <identifier type="local">
2794                                 <xsl:value-of select="."></xsl:value-of>
2795                         </identifier>
2796                 </xsl:for-each>
2797         </xsl:template>
2798         <xsl:template name="relatedIdentifier">
2799                 <xsl:for-each select="marc:subfield[@code='o']">
2800                         <identifier>
2801                                 <xsl:value-of select="."></xsl:value-of>
2802                         </identifier>
2803                 </xsl:for-each>
2804         </xsl:template>
2805         <xsl:template name="relatedItem76X-78X">
2806                 <xsl:call-template name="displayLabel"></xsl:call-template>
2807                 <xsl:call-template name="relatedTitle76X-78X"></xsl:call-template>
2808                 <xsl:call-template name="relatedName"></xsl:call-template>
2809                 <xsl:call-template name="relatedOriginInfo"></xsl:call-template>
2810                 <xsl:call-template name="relatedLanguage"></xsl:call-template>
2811                 <xsl:call-template name="relatedExtent"></xsl:call-template>
2812                 <xsl:call-template name="relatedNote"></xsl:call-template>
2813                 <xsl:call-template name="relatedSubject"></xsl:call-template>
2814                 <xsl:call-template name="relatedIdentifier"></xsl:call-template>
2815                 <xsl:call-template name="relatedIdentifierISSN"></xsl:call-template>
2816                 <xsl:call-template name="relatedIdentifierLocal"></xsl:call-template>
2817                 <xsl:call-template name="relatedPart"></xsl:call-template>
2818         </xsl:template>
2819         <xsl:template name="subjectGeographicZ">
2820                 <geographic>
2821                         <xsl:call-template name="chopPunctuation">
2822                                 <xsl:with-param name="chopString" select="."></xsl:with-param>
2823                         </xsl:call-template>
2824                 </geographic>
2825         </xsl:template>
2826         <xsl:template name="subjectTemporalY">
2827                 <temporal>
2828                         <xsl:call-template name="chopPunctuation">
2829                                 <xsl:with-param name="chopString" select="."></xsl:with-param>
2830                         </xsl:call-template>
2831                 </temporal>
2832         </xsl:template>
2833         <xsl:template name="subjectTopic">
2834                 <topic>
2835                         <xsl:call-template name="chopPunctuation">
2836                                 <xsl:with-param name="chopString" select="."></xsl:with-param>
2837                         </xsl:call-template>
2838                 </topic>
2839         </xsl:template> 
2840         <!-- 3.2 change tmee 6xx $v genre -->
2841         <xsl:template name="subjectGenre">
2842                 <genre>
2843                         <xsl:call-template name="chopPunctuation">
2844                                 <xsl:with-param name="chopString" select="."></xsl:with-param>
2845                         </xsl:call-template>
2846                 </genre>
2847         </xsl:template>
2848         
2849         <xsl:template name="nameABCDN">
2850                 <xsl:for-each select="marc:subfield[@code='a']">
2851                         <namePart>
2852                                 <xsl:call-template name="chopPunctuation">
2853                                         <xsl:with-param name="chopString" select="."></xsl:with-param>
2854                                 </xsl:call-template>
2855                         </namePart>
2856                 </xsl:for-each>
2857                 <xsl:for-each select="marc:subfield[@code='b']">
2858                         <namePart>
2859                                 <xsl:value-of select="."></xsl:value-of>
2860                         </namePart>
2861                 </xsl:for-each>
2862                 <xsl:if test="marc:subfield[@code='c'] or marc:subfield[@code='d'] or marc:subfield[@code='n']">
2863                         <namePart>
2864                                 <xsl:call-template name="subfieldSelect">
2865                                         <xsl:with-param name="codes">cdn</xsl:with-param>
2866                                 </xsl:call-template>
2867                         </namePart>
2868                 </xsl:if>
2869         </xsl:template>
2870         <xsl:template name="nameABCDQ">
2871                 <namePart>
2872                         <xsl:call-template name="chopPunctuation">
2873                                 <xsl:with-param name="chopString">
2874                                         <xsl:call-template name="subfieldSelect">
2875                                                 <xsl:with-param name="codes">aq</xsl:with-param>
2876                                         </xsl:call-template>
2877                                 </xsl:with-param>
2878                                 <xsl:with-param name="punctuation">
2879                                         <xsl:text>:,;/ </xsl:text>
2880                                 </xsl:with-param>
2881                         </xsl:call-template>
2882                 </namePart>
2883                 <xsl:call-template name="termsOfAddress"></xsl:call-template>
2884                 <xsl:call-template name="nameDate"></xsl:call-template>
2885         </xsl:template>
2886         <xsl:template name="nameACDEQ">
2887                 <namePart>
2888                         <xsl:call-template name="subfieldSelect">
2889                                 <xsl:with-param name="codes">acdeq</xsl:with-param>
2890                         </xsl:call-template>
2891                 </namePart>
2892         </xsl:template>
2893         <xsl:template name="constituentOrRelatedType">
2894                 <xsl:if test="@ind2=2">
2895                         <xsl:attribute name="type">constituent</xsl:attribute>
2896                 </xsl:if>
2897         </xsl:template>
2898         <xsl:template name="relatedTitle">
2899                 <xsl:for-each select="marc:subfield[@code='t']">
2900                         <titleInfo>
2901                                 <title>
2902                                         <xsl:call-template name="chopPunctuation">
2903                                                 <xsl:with-param name="chopString">
2904                                                         <xsl:value-of select="."></xsl:value-of>
2905                                                 </xsl:with-param>
2906                                         </xsl:call-template>
2907                                 </title>
2908                         </titleInfo>
2909                 </xsl:for-each>
2910         </xsl:template>
2911         <xsl:template name="relatedTitle76X-78X">
2912                 <xsl:for-each select="marc:subfield[@code='t']">
2913                         <titleInfo>
2914                                 <title>
2915                                         <xsl:call-template name="chopPunctuation">
2916                                                 <xsl:with-param name="chopString">
2917                                                         <xsl:value-of select="."></xsl:value-of>
2918                                                 </xsl:with-param>
2919                                         </xsl:call-template>
2920                                 </title>
2921                                 <xsl:if test="marc:datafield[@tag!=773]and marc:subfield[@code='g']">
2922                                         <xsl:call-template name="relatedPartNumName"></xsl:call-template>
2923                                 </xsl:if>
2924                         </titleInfo>
2925                 </xsl:for-each>
2926                 <xsl:for-each select="marc:subfield[@code='p']">
2927                         <titleInfo type="abbreviated">
2928                                 <title>
2929                                         <xsl:call-template name="chopPunctuation">
2930                                                 <xsl:with-param name="chopString">
2931                                                         <xsl:value-of select="."></xsl:value-of>
2932                                                 </xsl:with-param>
2933                                         </xsl:call-template>
2934                                 </title>
2935                                 <xsl:if test="marc:datafield[@tag!=773]and marc:subfield[@code='g']">
2936                                         <xsl:call-template name="relatedPartNumName"></xsl:call-template>
2937                                 </xsl:if>
2938                         </titleInfo>
2939                 </xsl:for-each>
2940                 <xsl:for-each select="marc:subfield[@code='s']">
2941                         <titleInfo type="uniform">
2942                                 <title>
2943                                         <xsl:call-template name="chopPunctuation">
2944                                                 <xsl:with-param name="chopString">
2945                                                         <xsl:value-of select="."></xsl:value-of>
2946                                                 </xsl:with-param>
2947                                         </xsl:call-template>
2948                                 </title>
2949                                 <xsl:if test="marc:datafield[@tag!=773]and marc:subfield[@code='g']">
2950                                         <xsl:call-template name="relatedPartNumName"></xsl:call-template>
2951                                 </xsl:if>
2952                         </titleInfo>
2953                 </xsl:for-each>
2954         </xsl:template>
2955         <xsl:template name="relatedOriginInfo">
2956                 <xsl:if test="marc:subfield[@code='b' or @code='d'] or marc:subfield[@code='f']">
2957                         <originInfo>
2958                                 <xsl:if test="@tag=775">
2959                                         <xsl:for-each select="marc:subfield[@code='f']">
2960                                                 <place>
2961                                                         <placeTerm>
2962                                                                 <xsl:attribute name="type">code</xsl:attribute>
2963                                                                 <xsl:attribute name="authority">marcgac</xsl:attribute>
2964                                                                 <xsl:value-of select="."></xsl:value-of>
2965                                                         </placeTerm>
2966                                                 </place>
2967                                         </xsl:for-each>
2968                                 </xsl:if>
2969                                 <xsl:for-each select="marc:subfield[@code='d']">
2970                                         <publisher>
2971                                                 <xsl:value-of select="."></xsl:value-of>
2972                                         </publisher>
2973                                 </xsl:for-each>
2974                                 <xsl:for-each select="marc:subfield[@code='b']">
2975                                         <edition>
2976                                                 <xsl:value-of select="."></xsl:value-of>
2977                                         </edition>
2978                                 </xsl:for-each>
2979                         </originInfo>
2980                 </xsl:if>
2981         </xsl:template>
2982         <xsl:template name="relatedLanguage">
2983                 <xsl:for-each select="marc:subfield[@code='e']">
2984                         <xsl:call-template name="getLanguage">
2985                                 <xsl:with-param name="langString">
2986                                         <xsl:value-of select="."></xsl:value-of>
2987                                 </xsl:with-param>
2988                         </xsl:call-template>
2989                 </xsl:for-each>
2990         </xsl:template>
2991         <xsl:template name="nameDate">
2992                 <xsl:for-each select="marc:subfield[@code='d']">
2993                         <namePart type="date">
2994                                 <xsl:call-template name="chopPunctuation">
2995                                         <xsl:with-param name="chopString" select="."></xsl:with-param>
2996                                 </xsl:call-template>
2997                         </namePart>
2998                 </xsl:for-each>
2999         </xsl:template>
3000         <xsl:template name="subjectAuthority">
3001                 <xsl:if test="@ind2!=4">
3002                         <xsl:if test="@ind2!=' '">
3003                                 <xsl:if test="@ind2!=8">
3004                                         <xsl:if test="@ind2!=9">
3005                                                 <xsl:attribute name="authority">
3006                                                         <xsl:choose>
3007                                                                 <xsl:when test="@ind2=0">lcsh</xsl:when>
3008                                                                 <xsl:when test="@ind2=1">lcshac</xsl:when>
3009                                                                 <xsl:when test="@ind2=2">mesh</xsl:when>
3010                                                                 <!-- 1/04 fix -->
3011                                                                 <xsl:when test="@ind2=3">nal</xsl:when>
3012                                                                 <xsl:when test="@ind2=5">csh</xsl:when>
3013                                                                 <xsl:when test="@ind2=6">rvm</xsl:when>
3014                                                                 <xsl:when test="@ind2=7">
3015                                                                         <xsl:value-of select="marc:subfield[@code='2']"></xsl:value-of>
3016                                                                 </xsl:when>
3017                                                         </xsl:choose>
3018                                                 </xsl:attribute>
3019                                         </xsl:if>
3020                                 </xsl:if>
3021                         </xsl:if>
3022                 </xsl:if>
3023         </xsl:template>
3024         <xsl:template name="subjectAnyOrder">
3025                 <xsl:for-each select="marc:subfield[@code='v' or @code='x' or @code='y' or @code='z']">
3026                         <xsl:choose>
3027                                 <xsl:when test="@code='v'">
3028                                         <xsl:call-template name="subjectGenre"></xsl:call-template>
3029                                 </xsl:when>
3030                                 <xsl:when test="@code='x'">
3031                                         <xsl:call-template name="subjectTopic"></xsl:call-template>
3032                                 </xsl:when>
3033                                 <xsl:when test="@code='y'">
3034                                         <xsl:call-template name="subjectTemporalY"></xsl:call-template>
3035                                 </xsl:when>
3036                                 <xsl:when test="@code='z'">
3037                                         <xsl:call-template name="subjectGeographicZ"></xsl:call-template>
3038                                 </xsl:when>
3039                         </xsl:choose>
3040                 </xsl:for-each>
3041         </xsl:template>
3042         <xsl:template name="specialSubfieldSelect">
3043                 <xsl:param name="anyCodes"></xsl:param>
3044                 <xsl:param name="axis"></xsl:param>
3045                 <xsl:param name="beforeCodes"></xsl:param>
3046                 <xsl:param name="afterCodes"></xsl:param>
3047                 <xsl:variable name="str">
3048                         <xsl:for-each select="marc:subfield">
3049                                 <xsl:if test="contains($anyCodes, @code)      or (contains($beforeCodes,@code) and following-sibling::marc:subfield[@code=$axis])      or (contains($afterCodes,@code) and preceding-sibling::marc:subfield[@code=$axis])">
3050                                         <xsl:value-of select="text()"></xsl:value-of>
3051                                         <xsl:text> </xsl:text>
3052                                 </xsl:if>
3053                         </xsl:for-each>
3054                 </xsl:variable>
3055                 <xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
3056         </xsl:template>
3057         
3058         <!-- 3.2 change tmee 6xx $v genre -->
3059         <xsl:template match="marc:datafield[@tag=600]">
3060                 <subject>
3061                         <xsl:call-template name="subjectAuthority"></xsl:call-template>
3062                         <name type="personal">
3063                                 <xsl:call-template name="uri" />
3064                                 <xsl:call-template name="termsOfAddress"></xsl:call-template>
3065                                 <namePart>
3066                                         <xsl:call-template name="chopPunctuation">
3067                                                 <xsl:with-param name="chopString">
3068                                                         <xsl:call-template name="subfieldSelect">
3069                                                                 <xsl:with-param name="codes">aq</xsl:with-param>
3070                                                         </xsl:call-template>
3071                                                 </xsl:with-param>
3072                                         </xsl:call-template>
3073                                 </namePart>
3074                                 <xsl:call-template name="nameDate"></xsl:call-template>
3075                                 <xsl:call-template name="affiliation"></xsl:call-template>
3076                                 <xsl:call-template name="role"></xsl:call-template>
3077                         </name>
3078                         <xsl:call-template name="subjectAnyOrder"></xsl:call-template>
3079                 </subject>
3080         </xsl:template>
3081         <xsl:template match="marc:datafield[@tag=610]">
3082                 <subject>
3083                         <xsl:call-template name="subjectAuthority"></xsl:call-template>
3084                         <name type="corporate">
3085                                 <xsl:call-template name="uri" />
3086                                 <xsl:for-each select="marc:subfield[@code='a']">
3087                                         <namePart>
3088                                                 <xsl:value-of select="."></xsl:value-of>
3089                                         </namePart>
3090                                 </xsl:for-each>
3091                                 <xsl:for-each select="marc:subfield[@code='b']">
3092                                         <namePart>
3093                                                 <xsl:value-of select="."></xsl:value-of>
3094                                         </namePart>
3095                                 </xsl:for-each>
3096                                 <xsl:if test="marc:subfield[@code='c' or @code='d' or @code='n' or @code='p']">
3097                                         <namePart>
3098                                                 <xsl:call-template name="subfieldSelect">
3099                                                         <xsl:with-param name="codes">cdnp</xsl:with-param>
3100                                                 </xsl:call-template>
3101                                         </namePart>
3102                                 </xsl:if>
3103                                 <xsl:call-template name="role"></xsl:call-template>
3104                         </name>
3105                         <xsl:call-template name="subjectAnyOrder"></xsl:call-template>
3106                 </subject>
3107         </xsl:template>
3108         <xsl:template match="marc:datafield[@tag=611]">
3109                 <subject>
3110                         <xsl:call-template name="subjectAuthority"></xsl:call-template>
3111                         <name type="conference">
3112                                 <xsl:call-template name="uri" />
3113                                 <namePart>
3114                                         <xsl:call-template name="subfieldSelect">
3115                                                 <xsl:with-param name="codes">abcdeqnp</xsl:with-param>
3116                                         </xsl:call-template>
3117                                 </namePart>
3118                                 <xsl:for-each select="marc:subfield[@code='4']">
3119                                         <role>
3120                                                 <roleTerm authority="marcrelator" type="code">
3121                                                         <xsl:value-of select="."></xsl:value-of>
3122                                                 </roleTerm>
3123                                         </role>
3124                                 </xsl:for-each>
3125                         </name>
3126                         <xsl:call-template name="subjectAnyOrder"></xsl:call-template>
3127                 </subject>
3128         </xsl:template>
3129         <xsl:template match="marc:datafield[@tag=630]">
3130                 <subject>
3131                         <xsl:call-template name="subjectAuthority"></xsl:call-template>
3132                         <xsl:variable name="titleChop">
3133                                 <xsl:call-template name="chopPunctuation">
3134                                         <xsl:with-param name="chopString">
3135                                                 <xsl:call-template name="subfieldSelect">
3136                                                         <xsl:with-param name="codes">adfhklor</xsl:with-param>
3137                                                 </xsl:call-template>
3138                                         </xsl:with-param>
3139                                 </xsl:call-template>
3140                         </xsl:variable>
3141                         <titleInfo>
3142                                 <title>
3143                                         <xsl:value-of select="$titleChop" />
3144                                 </title>
3145                                 <xsl:call-template name="part"></xsl:call-template>
3146                         </titleInfo>
3147                         <titleInfo type="nfi">
3148                                 <xsl:choose>
3149                                         <xsl:when test="@ind1>0">
3150                                                 <nonSort>
3151                                                         <xsl:value-of select="substring($titleChop,1,@ind1)"/>
3152                                                 </nonSort>
3153                                                 <title>
3154                                                         <xsl:value-of select="substring($titleChop,@ind1+1)"/>
3155                                                 </title>
3156                                                 <xsl:call-template name="part"/>
3157                                         </xsl:when>
3158                                         <xsl:otherwise>
3159                                                 <title>
3160                                                         <xsl:value-of select="$titleChop" />
3161                                                 </title>
3162                                         </xsl:otherwise>
3163                                 </xsl:choose>
3164                                 <xsl:call-template name="part"></xsl:call-template>
3165                         </titleInfo>
3166                         <xsl:call-template name="subjectAnyOrder"></xsl:call-template>
3167                 </subject>
3168         </xsl:template>
3169         <xsl:template match="marc:datafield[@tag=650]">
3170                 <subject>
3171                         <xsl:call-template name="subjectAuthority"></xsl:call-template>
3172                         <topic>
3173                                 <xsl:call-template name="uri" />
3174                                 <xsl:call-template name="chopPunctuation">
3175                                         <xsl:with-param name="chopString">
3176                                                 <xsl:call-template name="subfieldSelect">
3177                                                         <xsl:with-param name="codes">abcd</xsl:with-param>
3178                                                 </xsl:call-template>
3179                                         </xsl:with-param>
3180                                 </xsl:call-template>
3181                         </topic>
3182                         <xsl:call-template name="subjectAnyOrder"></xsl:call-template>
3183                 </subject>
3184         </xsl:template>
3185         <xsl:template match="marc:datafield[@tag=651]">
3186                 <subject>
3187                         <xsl:call-template name="subjectAuthority"></xsl:call-template>
3188                         <xsl:for-each select="marc:subfield[@code='a']">
3189                                 <geographic>
3190                                         <xsl:call-template name="uri" />
3191                                         <xsl:call-template name="chopPunctuation">
3192                                                 <xsl:with-param name="chopString" select="."></xsl:with-param>
3193                                         </xsl:call-template>
3194                                 </geographic>
3195                         </xsl:for-each>
3196                         <xsl:call-template name="subjectAnyOrder"></xsl:call-template>
3197                 </subject>
3198         </xsl:template>
3199         <xsl:template match="marc:datafield[@tag=653]">
3200                 <subject>
3201                         <xsl:for-each select="marc:subfield[@code='a']">
3202                                 <topic>
3203                                         <xsl:call-template name="uri" />
3204                                         <xsl:value-of select="."></xsl:value-of>
3205                                 </topic>
3206                         </xsl:for-each>
3207                 </subject>
3208         </xsl:template>
3209         <xsl:template match="marc:datafield[@tag=656]">
3210                 <subject>
3211                         <xsl:if test="marc:subfield[@code=2]">
3212                                 <xsl:attribute name="authority">
3213                                         <xsl:value-of select="marc:subfield[@code=2]"></xsl:value-of>
3214                                 </xsl:attribute>
3215                         </xsl:if>
3216                         <occupation>
3217                                 <xsl:call-template name="uri" />
3218                                 <xsl:call-template name="chopPunctuation">
3219                                         <xsl:with-param name="chopString">
3220                                                 <xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
3221                                         </xsl:with-param>
3222                                 </xsl:call-template>
3223                         </occupation>
3224                 </subject>
3225         </xsl:template>
3226         <xsl:template name="termsOfAddress">
3227                 <xsl:if test="marc:subfield[@code='b' or @code='c']">
3228                         <namePart type="termsOfAddress">
3229                                 <xsl:call-template name="chopPunctuation">
3230                                         <xsl:with-param name="chopString">
3231                                                 <xsl:call-template name="subfieldSelect">
3232                                                         <xsl:with-param name="codes">bc</xsl:with-param>
3233                                                 </xsl:call-template>
3234                                         </xsl:with-param>
3235                                 </xsl:call-template>
3236                         </namePart>
3237                 </xsl:if>
3238         </xsl:template>
3239         <xsl:template name="displayLabel">
3240                 <xsl:if test="marc:subfield[@code='i']">
3241                         <xsl:attribute name="displayLabel">
3242                                 <xsl:value-of select="marc:subfield[@code='i']"></xsl:value-of>
3243                         </xsl:attribute>
3244                 </xsl:if>
3245                 <xsl:if test="marc:subfield[@code='3']">
3246                         <xsl:attribute name="displayLabel">
3247                                 <xsl:value-of select="marc:subfield[@code='3']"></xsl:value-of>
3248                         </xsl:attribute>
3249                 </xsl:if>
3250         </xsl:template>
3251         <xsl:template name="isInvalid">
3252                 <xsl:param name="type"/>
3253                 <xsl:if test="marc:subfield[@code='z'] or marc:subfield[@code='y']">
3254                         <identifier>
3255                                 <xsl:attribute name="type">
3256                                         <xsl:value-of select="$type"/>
3257                                 </xsl:attribute>
3258                                 <xsl:attribute name="invalid">
3259                                         <xsl:text>yes</xsl:text>
3260                                 </xsl:attribute>
3261                                 <xsl:if test="marc:subfield[@code='z']">
3262                                         <xsl:value-of select="marc:subfield[@code='z']"/>
3263                                 </xsl:if>
3264                                 <xsl:if test="marc:subfield[@code='y']">
3265                                         <xsl:value-of select="marc:subfield[@code='y']"/>
3266                                 </xsl:if>
3267                         </identifier>
3268                 </xsl:if>
3269         </xsl:template>
3270         <xsl:template name="subtitle">
3271                 <xsl:if test="marc:subfield[@code='b']">
3272                         <subTitle>
3273                                 <xsl:call-template name="chopPunctuation">
3274                                         <xsl:with-param name="chopString">
3275                                                 <xsl:value-of select="marc:subfield[@code='b']"/>
3276                                                 <!--<xsl:call-template name="subfieldSelect">
3277                                                         <xsl:with-param name="codes">b</xsl:with-param>                                                                 
3278                                                 </xsl:call-template>-->
3279                                         </xsl:with-param>
3280                                 </xsl:call-template>
3281                         </subTitle>
3282                 </xsl:if>
3283         </xsl:template>
3284         <xsl:template name="script">
3285                 <xsl:param name="scriptCode"></xsl:param>
3286                 <xsl:attribute name="script">
3287                         <xsl:choose>
3288                                 <xsl:when test="$scriptCode='(3'">Arabic</xsl:when>
3289                                 <xsl:when test="$scriptCode='(B'">Latin</xsl:when>
3290                                 <xsl:when test="$scriptCode='$1'">Chinese, Japanese, Korean</xsl:when>
3291                                 <xsl:when test="$scriptCode='(N'">Cyrillic</xsl:when>
3292                                 <xsl:when test="$scriptCode='(2'">Hebrew</xsl:when>
3293                                 <xsl:when test="$scriptCode='(S'">Greek</xsl:when>
3294                         </xsl:choose>
3295                 </xsl:attribute>
3296         </xsl:template>
3297         <xsl:template name="parsePart">
3298                 <!-- assumes 773$q= 1:2:3<4
3299                      with up to 3 levels and one optional start page
3300                 -->
3301                 <xsl:variable name="level1">
3302                         <xsl:choose>
3303                                 <xsl:when test="contains(text(),':')">
3304                                         <!-- 1:2 -->
3305                                         <xsl:value-of select="substring-before(text(),':')"></xsl:value-of>
3306                                 </xsl:when>
3307                                 <xsl:when test="not(contains(text(),':'))">
3308                                         <!-- 1 or 1<3 -->
3309                                         <xsl:if test="contains(text(),'&lt;')">
3310                                                 <!-- 1<3 -->
3311                                                 <xsl:value-of select="substring-before(text(),'&lt;')"></xsl:value-of>
3312                                         </xsl:if>
3313                                         <xsl:if test="not(contains(text(),'&lt;'))">
3314                                                 <!-- 1 -->
3315                                                 <xsl:value-of select="text()"></xsl:value-of>
3316                                         </xsl:if>
3317                                 </xsl:when>
3318                         </xsl:choose>
3319                 </xsl:variable>
3320                 <xsl:variable name="sici2">
3321                         <xsl:choose>
3322                                 <xsl:when test="starts-with(substring-after(text(),$level1),':')">
3323                                         <xsl:value-of select="substring(substring-after(text(),$level1),2)"></xsl:value-of>
3324                                 </xsl:when>
3325                                 <xsl:otherwise>
3326                                         <xsl:value-of select="substring-after(text(),$level1)"></xsl:value-of>
3327                                 </xsl:otherwise>
3328                         </xsl:choose>
3329                 </xsl:variable>
3330                 <xsl:variable name="level2">
3331                         <xsl:choose>
3332                                 <xsl:when test="contains($sici2,':')">
3333                                         <!--  2:3<4  -->
3334                                         <xsl:value-of select="substring-before($sici2,':')"></xsl:value-of>
3335                                 </xsl:when>
3336                                 <xsl:when test="contains($sici2,'&lt;')">
3337                                         <!-- 1: 2<4 -->
3338                                         <xsl:value-of select="substring-before($sici2,'&lt;')"></xsl:value-of>
3339                                 </xsl:when>
3340                                 <xsl:otherwise>
3341                                         <xsl:value-of select="$sici2"></xsl:value-of>
3342                                         <!-- 1:2 -->
3343                                 </xsl:otherwise>
3344                         </xsl:choose>
3345                 </xsl:variable>
3346                 <xsl:variable name="sici3">
3347                         <xsl:choose>
3348                                 <xsl:when test="starts-with(substring-after($sici2,$level2),':')">
3349                                         <xsl:value-of select="substring(substring-after($sici2,$level2),2)"></xsl:value-of>
3350                                 </xsl:when>
3351                                 <xsl:otherwise>
3352                                         <xsl:value-of select="substring-after($sici2,$level2)"></xsl:value-of>
3353                                 </xsl:otherwise>
3354                         </xsl:choose>
3355                 </xsl:variable>
3356                 <xsl:variable name="level3">
3357                         <xsl:choose>
3358                                 <xsl:when test="contains($sici3,'&lt;')">
3359                                         <!-- 2<4 -->
3360                                         <xsl:value-of select="substring-before($sici3,'&lt;')"></xsl:value-of>
3361                                 </xsl:when>
3362                                 <xsl:otherwise>
3363                                         <xsl:value-of select="$sici3"></xsl:value-of>
3364                                         <!-- 3 -->
3365                                 </xsl:otherwise>
3366                         </xsl:choose>
3367                 </xsl:variable>
3368                 <xsl:variable name="page">
3369                         <xsl:if test="contains(text(),'&lt;')">
3370                                 <xsl:value-of select="substring-after(text(),'&lt;')"></xsl:value-of>
3371                         </xsl:if>
3372                 </xsl:variable>
3373                 <xsl:if test="$level1">
3374                         <detail level="1">
3375                                 <number>
3376                                         <xsl:value-of select="$level1"></xsl:value-of>
3377                                 </number>
3378                         </detail>
3379                 </xsl:if>
3380                 <xsl:if test="$level2">
3381                         <detail level="2">
3382                                 <number>
3383                                         <xsl:value-of select="$level2"></xsl:value-of>
3384                                 </number>
3385                         </detail>
3386                 </xsl:if>
3387                 <xsl:if test="$level3">
3388                         <detail level="3">
3389                                 <number>
3390                                         <xsl:value-of select="$level3"></xsl:value-of>
3391                                 </number>
3392                         </detail>
3393                 </xsl:if>
3394                 <xsl:if test="$page">
3395                         <extent unit="page">
3396                                 <start>
3397                                         <xsl:value-of select="$page"></xsl:value-of>
3398                                 </start>
3399                         </extent>
3400                 </xsl:if>
3401         </xsl:template>
3402         <xsl:template name="getLanguage">
3403                 <xsl:param name="langString"></xsl:param>
3404                 <xsl:param name="controlField008-35-37"></xsl:param>
3405                 <xsl:variable name="length" select="string-length($langString)"></xsl:variable>
3406                 <xsl:choose>
3407                         <xsl:when test="$length=0"></xsl:when>
3408                         <xsl:when test="$controlField008-35-37=substring($langString,1,3)">
3409                                 <xsl:call-template name="getLanguage">
3410                                         <xsl:with-param name="langString" select="substring($langString,4,$length)"></xsl:with-param>
3411                                         <xsl:with-param name="controlField008-35-37" select="$controlField008-35-37"></xsl:with-param>
3412                                 </xsl:call-template>
3413                         </xsl:when>
3414                         <xsl:otherwise>
3415                                 <language>
3416                                         <languageTerm authority="iso639-2b" type="code">
3417                                                 <xsl:value-of select="substring($langString,1,3)"></xsl:value-of>
3418                                         </languageTerm>
3419                                 </language>
3420                                 <xsl:call-template name="getLanguage">
3421                                         <xsl:with-param name="langString" select="substring($langString,4,$length)"></xsl:with-param>
3422                                         <xsl:with-param name="controlField008-35-37" select="$controlField008-35-37"></xsl:with-param>
3423                                 </xsl:call-template>
3424                         </xsl:otherwise>
3425                 </xsl:choose>
3426         </xsl:template>
3427         <xsl:template name="isoLanguage">
3428                 <xsl:param name="currentLanguage"></xsl:param>
3429                 <xsl:param name="usedLanguages"></xsl:param>
3430                 <xsl:param name="remainingLanguages"></xsl:param>
3431                 <xsl:choose>
3432                         <xsl:when test="string-length($currentLanguage)=0"></xsl:when>
3433                         <xsl:when test="not(contains($usedLanguages, $currentLanguage))">
3434                                 <language>
3435                                         <xsl:if test="@code!='a'">
3436                                                 <xsl:attribute name="objectPart">
3437                                                         <xsl:choose>
3438                                                                 <xsl:when test="@code='b'">summary or subtitle</xsl:when>
3439                                                                 <xsl:when test="@code='d'">sung or spoken text</xsl:when>
3440                                                                 <xsl:when test="@code='e'">libretto</xsl:when>
3441                                                                 <xsl:when test="@code='f'">table of contents</xsl:when>
3442                                                                 <xsl:when test="@code='g'">accompanying material</xsl:when>
3443                                                                 <xsl:when test="@code='h'">translation</xsl:when>
3444                                                         </xsl:choose>
3445                                                 </xsl:attribute>
3446                                         </xsl:if>
3447                                         <languageTerm authority="iso639-2b" type="code">
3448                                                 <xsl:value-of select="$currentLanguage"></xsl:value-of>
3449                                         </languageTerm>
3450                                 </language>
3451                                 <xsl:call-template name="isoLanguage">
3452                                         <xsl:with-param name="currentLanguage">
3453                                                 <xsl:value-of select="substring($remainingLanguages,1,3)"></xsl:value-of>
3454                                         </xsl:with-param>
3455                                         <xsl:with-param name="usedLanguages">
3456                                                 <xsl:value-of select="concat($usedLanguages,$currentLanguage)"></xsl:value-of>
3457                                         </xsl:with-param>
3458                                         <xsl:with-param name="remainingLanguages">
3459                                                 <xsl:value-of select="substring($remainingLanguages,4,string-length($remainingLanguages))"></xsl:value-of>
3460                                         </xsl:with-param>
3461                                 </xsl:call-template>
3462                         </xsl:when>
3463                         <xsl:otherwise>
3464                                 <xsl:call-template name="isoLanguage">
3465                                         <xsl:with-param name="currentLanguage">
3466                                                 <xsl:value-of select="substring($remainingLanguages,1,3)"></xsl:value-of>
3467                                         </xsl:with-param>
3468                                         <xsl:with-param name="usedLanguages">
3469                                                 <xsl:value-of select="concat($usedLanguages,$currentLanguage)"></xsl:value-of>
3470                                         </xsl:with-param>
3471                                         <xsl:with-param name="remainingLanguages">
3472                                                 <xsl:value-of select="substring($remainingLanguages,4,string-length($remainingLanguages))"></xsl:value-of>
3473                                         </xsl:with-param>
3474                                 </xsl:call-template>
3475                         </xsl:otherwise>
3476                 </xsl:choose>
3477         </xsl:template>
3478         <xsl:template name="chopBrackets">
3479                 <xsl:param name="chopString"></xsl:param>
3480                 <xsl:variable name="string">
3481                         <xsl:call-template name="chopPunctuation">
3482                                 <xsl:with-param name="chopString" select="$chopString"></xsl:with-param>
3483                         </xsl:call-template>
3484                 </xsl:variable>
3485                 <xsl:if test="substring($string, 1,1)='['">
3486                         <xsl:value-of select="substring($string,2, string-length($string)-2)"></xsl:value-of>
3487                 </xsl:if>
3488                 <xsl:if test="substring($string, 1,1)!='['">
3489                         <xsl:value-of select="$string"></xsl:value-of>
3490                 </xsl:if>
3491         </xsl:template>
3492         <xsl:template name="rfcLanguages">
3493                 <xsl:param name="nodeNum"></xsl:param>
3494                 <xsl:param name="usedLanguages"></xsl:param>
3495                 <xsl:param name="controlField008-35-37"></xsl:param>
3496                 <xsl:variable name="currentLanguage" select="."></xsl:variable>
3497                 <xsl:choose>
3498                         <xsl:when test="not($currentLanguage)"></xsl:when>
3499                         <xsl:when test="$currentLanguage!=$controlField008-35-37 and $currentLanguage!='rfc3066'">
3500                                 <xsl:if test="not(contains($usedLanguages,$currentLanguage))">
3501                                         <language>
3502                                                 <xsl:if test="@code!='a'">
3503                                                         <xsl:attribute name="objectPart">
3504                                                                 <xsl:choose>
3505                                                                         <xsl:when test="@code='b'">summary or subtitle</xsl:when>
3506                                                                         <xsl:when test="@code='d'">sung or spoken text</xsl:when>
3507                                                                         <xsl:when test="@code='e'">libretto</xsl:when>
3508                                                                         <xsl:when test="@code='f'">table of contents</xsl:when>
3509                                                                         <xsl:when test="@code='g'">accompanying material</xsl:when>
3510                                                                         <xsl:when test="@code='h'">translation</xsl:when>
3511                                                                 </xsl:choose>
3512                                                         </xsl:attribute>
3513                                                 </xsl:if>
3514                                                 <languageTerm authority="rfc3066" type="code">
3515                                                         <xsl:value-of select="$currentLanguage"/>
3516                                                 </languageTerm>
3517                                         </language>
3518                                 </xsl:if>
3519                         </xsl:when>
3520                         <xsl:otherwise>
3521                         </xsl:otherwise>
3522                 </xsl:choose>
3523         </xsl:template>
3524         <xsl:template name="datafield">
3525                 <xsl:param name="tag"/>
3526                 <xsl:param name="ind1"><xsl:text> </xsl:text></xsl:param>
3527                 <xsl:param name="ind2"><xsl:text> </xsl:text></xsl:param>
3528                 <xsl:param name="subfields"/>
3529                 <xsl:element name="marc:datafield">
3530                         <xsl:attribute name="tag">
3531                                 <xsl:value-of select="$tag"/>
3532                         </xsl:attribute>
3533                         <xsl:attribute name="ind1">
3534                                 <xsl:value-of select="$ind1"/>
3535                         </xsl:attribute>
3536                         <xsl:attribute name="ind2">
3537                                 <xsl:value-of select="$ind2"/>
3538                         </xsl:attribute>
3539                         <xsl:copy-of select="$subfields"/>
3540                 </xsl:element>
3541         </xsl:template>
3542
3543         <xsl:template name="subfieldSelect">
3544                 <xsl:param name="codes"/>
3545                 <xsl:param name="delimeter"><xsl:text> </xsl:text></xsl:param>
3546                 <xsl:variable name="str">
3547                         <xsl:for-each select="marc:subfield">
3548                                 <xsl:if test="contains($codes, @code)">
3549                                         <xsl:value-of select="text()"/><xsl:value-of select="$delimeter"/>
3550                                 </xsl:if>
3551                         </xsl:for-each>
3552                 </xsl:variable>
3553                 <xsl:value-of select="substring($str,1,string-length($str)-string-length($delimeter))"/>
3554         </xsl:template>
3555
3556         <xsl:template name="buildSpaces">
3557                 <xsl:param name="spaces"/>
3558                 <xsl:param name="char"><xsl:text> </xsl:text></xsl:param>
3559                 <xsl:if test="$spaces>0">
3560                         <xsl:value-of select="$char"/>
3561                         <xsl:call-template name="buildSpaces">
3562                                 <xsl:with-param name="spaces" select="$spaces - 1"/>
3563                                 <xsl:with-param name="char" select="$char"/>
3564                         </xsl:call-template>
3565                 </xsl:if>
3566         </xsl:template>
3567
3568         <xsl:template name="chopPunctuation">
3569                 <xsl:param name="chopString"/>
3570                 <xsl:param name="punctuation"><xsl:text>.:,;/ </xsl:text></xsl:param>
3571                 <xsl:variable name="length" select="string-length($chopString)"/>
3572                 <xsl:choose>
3573                         <xsl:when test="$length=0"/>
3574                         <xsl:when test="contains($punctuation, substring($chopString,$length,1))">
3575                                 <xsl:call-template name="chopPunctuation">
3576                                         <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
3577                                         <xsl:with-param name="punctuation" select="$punctuation"/>
3578                                 </xsl:call-template>
3579                         </xsl:when>
3580                         <xsl:when test="not($chopString)"/>
3581                         <xsl:otherwise><xsl:value-of select="$chopString"/></xsl:otherwise>
3582                 </xsl:choose>
3583         </xsl:template>
3584
3585         <xsl:template name="chopPunctuationFront">
3586                 <xsl:param name="chopString"/>
3587                 <xsl:variable name="length" select="string-length($chopString)"/>
3588                 <xsl:choose>
3589                         <xsl:when test="$length=0"/>
3590                         <xsl:when test="contains('.:,;/[ ', substring($chopString,1,1))">
3591                                 <xsl:call-template name="chopPunctuationFront">
3592                                         <xsl:with-param name="chopString" select="substring($chopString,2,$length - 1)"/>
3593                                 </xsl:call-template>
3594                         </xsl:when>
3595                         <xsl:when test="not($chopString)"/>
3596                         <xsl:otherwise><xsl:value-of select="$chopString"/></xsl:otherwise>
3597                 </xsl:choose>
3598         </xsl:template>
3599 </xsl:stylesheet>$$ WHERE name = 'mods32';
3600
3601
3602 -- 954.data.MODS33-xsl.sql
3603 UPDATE config.xml_transform SET xslt=$$<xsl:stylesheet xmlns="http://www.loc.gov/mods/v3" xmlns:marc="http://www.loc.gov/MARC21/slim"
3604         xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3605         exclude-result-prefixes="xlink marc" version="1.0">
3606         <xsl:output encoding="UTF-8" indent="yes" method="xml"/>
3607
3608         <xsl:variable name="ascii">
3609                 <xsl:text> !"#$%&amp;'()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~</xsl:text>
3610         </xsl:variable>
3611
3612         <xsl:variable name="latin1">
3613                 <xsl:text> ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ</xsl:text>
3614         </xsl:variable>
3615         <!-- Characters that usually don't need to be escaped -->
3616         <xsl:variable name="safe">
3617                 <xsl:text>!'()*-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~</xsl:text>
3618         </xsl:variable>
3619
3620         <xsl:variable name="hex">0123456789ABCDEF</xsl:variable>
3621
3622     <!-- Evergreen specific: revert Revision 1.23, so we can have those authority xlink attributes back. -->
3623
3624         <!--MARC21slim2MODS3-3.xsl
3625 Revision 1.27 - Mapped 648 to <subject> 2009/03/13 tmee
3626 Revision 1.26 - Added subfield $s mapping for 130/240/730  2008/10/16 tmee
3627 Revision 1.25 - Mapped 040e to <descriptiveStandard> and Leader/18 to <descriptive standard>aacr2  2008/09/18 tmee
3628 Revision 1.24 - Mapped 852 subfields $h, $i, $j, $k, $l, $m, $t to <shelfLocation> and 852 subfield $u to <physicalLocation> with @xlink 2008/09/17 tmee
3629 Revision 1.23 - Commented out xlink/uri for subfield 0 for 130/240/730, 100/700, 110/710, 111/711 as these are currently unactionable  2008/09/17  tmee
3630 Revision 1.22 - Mapped 022 subfield $l to type "issn-l" subfield $m to output identifier element with corresponding @type and @invalid eq 'yes'2008/09/17  tmee
3631 Revision 1.21 - Mapped 856 ind2=1 or ind2=2 to <relatedItem><location><url>  2008/07/03  tmee
3632 Revision 1.20 - Added genre w/@auth="contents of 2" and type= "musical composition"  2008/07/01  tmee
3633 Revision 1.19 - Added genre offprint for 008/24+ BK code 2  2008/07/01  tmee
3634 Revision 1.18 - Added xlink/uri for subfield 0 for 130/240/730, 100/700, 110/710, 111/711  2008/06/26  tmee
3635 Revision 1.17 - Added mapping of 662 2008/05/14 tmee    
3636 Revision 1.16 - Changed @authority from "marc" to "marcgt" for 007 and 008 codes mapped to a term in <genre> 2007/07/10  tmee
3637 Revision 1.15 - For field 630, moved call to part template outside title element  2007/07/10  tmee
3638 Revision 1.14 - Fixed template isValid and fields 010, 020, 022, 024, 028, and 037 to output additional identifier elements 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
3639 Revision 1.13 - Changed order of output under cartographics to reflect schema  2006/11/28  tmee
3640 Revision 1.12 - Updated to reflect MODS 3.2 Mapping  2006/10/11  tmee
3641 Revision 1.11 - The attribute objectPart moved from <languageTerm> to <language>  2006/04/08  jrad
3642 Revision 1.10 - MODS 3.1 revisions to language and classification elements  (plus ability to find marc:collection embedded in wrapper elements such as SRU zs: wrappers)  2006/02/06  ggar
3643 Revision 1.9 - Subfield $y was added to field 242 2004/09/02 10:57 jrad
3644 Revision 1.8 - Subject chopPunctuation expanded and attribute fixes 2004/08/12 jrad
3645 Revision 1.7 - 2004/03/25 08:29 jrad
3646 Revision 1.6 - Various validation fixes 2004/02/20 ntra
3647 Revision 1.5 - MODS2 to MODS3 updates, language unstacking and de-duping, chopPunctuation expanded  2003/10/02 16:18:58  ntra
3648 Revision 1.3 - Additional Changes not related to MODS Version 2.0 by ntra
3649 Revision 1.2 - Added Log Comment  2003/03/24 19:37:42  ckeith
3650 -->
3651         <xsl:template match="/">
3652                 <xsl:choose>
3653                         <xsl:when test="//marc:collection">
3654                                 <modsCollection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3655                                         xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-2.xsd">
3656                                         <xsl:for-each select="//marc:collection/marc:record">
3657                                                 <mods version="3.3">
3658                                                         <xsl:call-template name="marcRecord"/>
3659                                                 </mods>
3660                                         </xsl:for-each>
3661                                 </modsCollection>
3662                         </xsl:when>
3663                         <xsl:otherwise>
3664                                 <mods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.3"
3665                                         xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-2.xsd">
3666                                         <xsl:for-each select="//marc:record">
3667                                                 <xsl:call-template name="marcRecord"/>
3668                                         </xsl:for-each>
3669                                 </mods>
3670                         </xsl:otherwise>
3671                 </xsl:choose>
3672         </xsl:template>
3673         <xsl:template name="marcRecord">
3674                 <xsl:variable name="leader" select="marc:leader"/>
3675                 <xsl:variable name="leader6" select="substring($leader,7,1)"/>
3676                 <xsl:variable name="leader7" select="substring($leader,8,1)"/>
3677                 <xsl:variable name="controlField008" select="marc:controlfield[@tag='008']"/>
3678                 <xsl:variable name="typeOf008">
3679                         <xsl:choose>
3680                                 <xsl:when test="$leader6='a'">
3681                                         <xsl:choose>
3682                                                 <xsl:when
3683                                                         test="$leader7='a' or $leader7='c' or $leader7='d' or $leader7='m'">BK</xsl:when>
3684                                                 <xsl:when test="$leader7='b' or $leader7='i' or $leader7='s'">SE</xsl:when>
3685                                         </xsl:choose>
3686                                 </xsl:when>
3687                                 <xsl:when test="$leader6='t'">BK</xsl:when>
3688                                 <xsl:when test="$leader6='p'">MM</xsl:when>
3689                                 <xsl:when test="$leader6='m'">CF</xsl:when>
3690                                 <xsl:when test="$leader6='e' or $leader6='f'">MP</xsl:when>
3691                                 <xsl:when test="$leader6='g' or $leader6='k' or $leader6='o' or $leader6='r'">VM</xsl:when>
3692                                 <xsl:when test="$leader6='c' or $leader6='d' or $leader6='i' or $leader6='j'"
3693                                 >MU</xsl:when>
3694                         </xsl:choose>
3695                 </xsl:variable>
3696                 <xsl:for-each select="marc:datafield[@tag='245']">
3697                         <titleInfo>
3698                                 <xsl:variable name="title">
3699                                         <xsl:choose>
3700                                                 <xsl:when test="marc:subfield[@code='b']">
3701                                                         <xsl:call-template name="specialSubfieldSelect">
3702                                                                 <xsl:with-param name="axis">b</xsl:with-param>
3703                                                                 <xsl:with-param name="beforeCodes">afgk</xsl:with-param>
3704                                                         </xsl:call-template>
3705                                                 </xsl:when>
3706                                                 <xsl:otherwise>
3707                                                         <xsl:call-template name="subfieldSelect">
3708                                                                 <xsl:with-param name="codes">abfgk</xsl:with-param>
3709                                                         </xsl:call-template>
3710                                                 </xsl:otherwise>
3711                                         </xsl:choose>
3712                                 </xsl:variable>
3713                                 <xsl:variable name="titleChop">
3714                                         <xsl:call-template name="chopPunctuation">
3715                                                 <xsl:with-param name="chopString">
3716                                                         <xsl:value-of select="$title"/>
3717                                                 </xsl:with-param>
3718                                         </xsl:call-template>
3719                                 </xsl:variable>
3720                                 <xsl:choose>
3721                                         <xsl:when test="@ind2&gt;0">
3722                                                 <nonSort>
3723                                                         <xsl:value-of select="substring($titleChop,1,@ind2)"/>
3724                                                 </nonSort>
3725                                                 <title>
3726                                                         <xsl:value-of select="substring($titleChop,@ind2+1)"/>
3727                                                 </title>
3728                                         </xsl:when>
3729                                         <xsl:otherwise>
3730                                                 <title>
3731                                                         <xsl:value-of select="$titleChop"/>
3732                                                 </title>
3733                                         </xsl:otherwise>
3734                                 </xsl:choose>
3735                                 <xsl:if test="marc:subfield[@code='b']">
3736                                         <subTitle>
3737                                                 <xsl:call-template name="chopPunctuation">
3738                                                         <xsl:with-param name="chopString">
3739                                                                 <xsl:call-template name="specialSubfieldSelect">
3740                                                                         <xsl:with-param name="axis">b</xsl:with-param>
3741                                                                         <xsl:with-param name="anyCodes">b</xsl:with-param>
3742                                                                         <xsl:with-param name="afterCodes">afgk</xsl:with-param>
3743                                                                 </xsl:call-template>
3744                                                         </xsl:with-param>
3745                                                 </xsl:call-template>
3746                                         </subTitle>
3747                                 </xsl:if>
3748                                 <xsl:call-template name="part"/>
3749                         </titleInfo>
3750                 </xsl:for-each>
3751                 <xsl:for-each select="marc:datafield[@tag='210']">
3752                         <titleInfo type="abbreviated">
3753                                 <title>
3754                                         <xsl:call-template name="chopPunctuation">
3755                                                 <xsl:with-param name="chopString">
3756                                                         <xsl:call-template name="subfieldSelect">
3757                                                                 <xsl:with-param name="codes">a</xsl:with-param>
3758                                                         </xsl:call-template>
3759                                                 </xsl:with-param>
3760                                         </xsl:call-template>
3761                                 </title>
3762                                 <xsl:call-template name="subtitle"/>
3763                         </titleInfo>
3764                 </xsl:for-each>
3765                 <xsl:for-each select="marc:datafield[@tag='242']">
3766                         <titleInfo type="translated">
3767                                 <!--09/01/04 Added subfield $y-->
3768                                 <xsl:for-each select="marc:subfield[@code='y']">
3769                                         <xsl:attribute name="lang">
3770                                                 <xsl:value-of select="text()"/>
3771                                         </xsl:attribute>
3772                                 </xsl:for-each>
3773                                 <xsl:for-each select="marc:subfield[@code='i']">
3774                                         <xsl:attribute name="displayLabel">
3775                                                 <xsl:value-of select="text()"/>
3776                                         </xsl:attribute>
3777                                 </xsl:for-each>
3778                                 <title>
3779                                         <xsl:call-template name="chopPunctuation">
3780                                                 <xsl:with-param name="chopString">
3781                                                         <xsl:call-template name="subfieldSelect">
3782                                                                 <!-- 1/04 removed $h, b -->
3783                                                                 <xsl:with-param name="codes">a</xsl:with-param>
3784                                                         </xsl:call-template>
3785                                                 </xsl:with-param>
3786                                         </xsl:call-template>
3787                                 </title>
3788                                 <!-- 1/04 fix -->
3789                                 <xsl:call-template name="subtitle"/>
3790                                 <xsl:call-template name="part"/>
3791                         </titleInfo>
3792                 </xsl:for-each>
3793                 <xsl:for-each select="marc:datafield[@tag='246']">
3794                         <titleInfo type="alternative">
3795                                 <xsl:for-each select="marc:subfield[@code='i']">
3796                                         <xsl:attribute name="displayLabel">
3797                                                 <xsl:value-of select="text()"/>
3798                                         </xsl:attribute>
3799                                 </xsl:for-each>
3800                                 <title>
3801                                         <xsl:call-template name="chopPunctuation">
3802                                                 <xsl:with-param name="chopString">
3803                                                         <xsl:call-template name="subfieldSelect">
3804                                                                 <!-- 1/04 removed $h, $b -->
3805                                                                 <xsl:with-param name="codes">af</xsl:with-param>
3806                                                         </xsl:call-template>
3807                                                 </xsl:with-param>
3808                                         </xsl:call-template>
3809                                 </title>
3810                                 <xsl:call-template name="subtitle"/>
3811                                 <xsl:call-template name="part"/>
3812                         </titleInfo>
3813                 </xsl:for-each>
3814                 <xsl:for-each
3815                         select="marc:datafield[@tag='130']|marc:datafield[@tag='240']|marc:datafield[@tag='730'][@ind2!='2']">
3816                         <titleInfo type="uniform">
3817                                 <title>
3818                                                 <xsl:call-template name="uri"/>
3819
3820                                         <xsl:variable name="str">
3821                                                 <xsl:for-each select="marc:subfield">
3822                                                         <xsl:if
3823                                                                 test="(contains('adfklmors',@code) and (not(../marc:subfield[@code='n' or @code='p']) or (following-sibling::marc:subfield[@code='n' or @code='p'])))">
3824                                                                 <xsl:value-of select="text()"/>
3825                                                                 <xsl:text> </xsl:text>
3826                                                         </xsl:if>
3827                                                 </xsl:for-each>
3828                                         </xsl:variable>
3829                                         <xsl:call-template name="chopPunctuation">
3830                                                 <xsl:with-param name="chopString">
3831                                                         <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
3832                                                 </xsl:with-param>
3833                                         </xsl:call-template>
3834                                 </title>
3835                                 <xsl:call-template name="part"/>
3836                         </titleInfo>
3837                 </xsl:for-each>
3838                 <xsl:for-each select="marc:datafield[@tag='740'][@ind2!='2']">
3839                         <titleInfo type="alternative">
3840                                 <title>
3841                                         <xsl:call-template name="chopPunctuation">
3842                                                 <xsl:with-param name="chopString">
3843                                                         <xsl:call-template name="subfieldSelect">
3844                                                                 <xsl:with-param name="codes">ah</xsl:with-param>
3845                                                         </xsl:call-template>
3846                                                 </xsl:with-param>
3847                                         </xsl:call-template>
3848                                 </title>
3849                                 <xsl:call-template name="part"/>
3850                         </titleInfo>
3851                 </xsl:for-each>
3852                 <xsl:for-each select="marc:datafield[@tag='100']">
3853                         <name type="personal">
3854
3855                                 <xsl:call-template name="uri"/>
3856
3857                                 <xsl:call-template name="nameABCDQ"/>
3858                                 <xsl:call-template name="affiliation"/>
3859                                 <role>
3860                                         <roleTerm authority="marcrelator" type="text">creator</roleTerm>
3861                                 </role>
3862                                 <xsl:call-template name="role"/>
3863                         </name>
3864                 </xsl:for-each>
3865                 <xsl:for-each select="marc:datafield[@tag='110']">
3866                         <name type="corporate">
3867
3868                                         <xsl:call-template name="uri"/>
3869
3870                                 <xsl:call-template name="nameABCDN"/>
3871                                 <role>
3872                                         <roleTerm authority="marcrelator" type="text">creator</roleTerm>
3873                                 </role>
3874                                 <xsl:call-template name="role"/>
3875                         </name>
3876                 </xsl:for-each>
3877                 <xsl:for-each select="marc:datafield[@tag='111']">
3878                         <name type="conference">
3879
3880                                         <xsl:call-template name="uri"/>
3881
3882                                 <xsl:call-template name="nameACDEQ"/>
3883                                 <role>
3884                                         <roleTerm authority="marcrelator" type="text">creator</roleTerm>
3885                                 </role>
3886                                 <xsl:call-template name="role"/>
3887                         </name>
3888                 </xsl:for-each>
3889                 <xsl:for-each select="marc:datafield[@tag='700'][not(marc:subfield[@code='t'])]">
3890                         <name type="personal">
3891
3892                                         <xsl:call-template name="uri"/>
3893
3894                                 <xsl:call-template name="nameABCDQ"/>
3895                                 <xsl:call-template name="affiliation"/>
3896                                 <xsl:call-template name="role"/>
3897                         </name>
3898                 </xsl:for-each>
3899                 <xsl:for-each select="marc:datafield[@tag='710'][not(marc:subfield[@code='t'])]">
3900                         <name type="corporate">
3901
3902                                         <xsl:call-template name="uri"/>
3903
3904                                 <xsl:call-template name="nameABCDN"/>
3905                                 <xsl:call-template name="role"/>
3906                         </name>
3907                 </xsl:for-each>
3908                 <xsl:for-each select="marc:datafield[@tag='711'][not(marc:subfield[@code='t'])]">
3909                         <name type="conference">
3910
3911                                         <xsl:call-template name="uri"/>
3912
3913                                 <xsl:call-template name="nameACDEQ"/>
3914                                 <xsl:call-template name="role"/>
3915                         </name>
3916                 </xsl:for-each>
3917                 <xsl:for-each select="marc:datafield[@tag='720'][not(marc:subfield[@code='t'])]">
3918                         <name>
3919                                 <xsl:if test="@ind1=1">
3920                                         <xsl:attribute name="type">
3921                                                 <xsl:text>personal</xsl:text>
3922                                         </xsl:attribute>
3923                                 </xsl:if>
3924                                 <namePart>
3925                                         <xsl:value-of select="marc:subfield[@code='a']"/>
3926                                 </namePart>
3927                                 <xsl:call-template name="role"/>
3928                         </name>
3929                 </xsl:for-each>
3930                 <typeOfResource>
3931                         <xsl:if test="$leader7='c'">
3932                                 <xsl:attribute name="collection">yes</xsl:attribute>
3933                         </xsl:if>
3934                         <xsl:if test="$leader6='d' or $leader6='f' or $leader6='p' or $leader6='t'">
3935                                 <xsl:attribute name="manuscript">yes</xsl:attribute>
3936                         </xsl:if>
3937                         <xsl:choose>
3938                                 <xsl:when test="$leader6='a' or $leader6='t'">text</xsl:when>
3939                                 <xsl:when test="$leader6='e' or $leader6='f'">cartographic</xsl:when>
3940                                 <xsl:when test="$leader6='c' or $leader6='d'">notated music</xsl:when>
3941                                 <xsl:when test="$leader6='i'">sound recording-nonmusical</xsl:when>
3942                                 <xsl:when test="$leader6='j'">sound recording-musical</xsl:when>
3943                                 <xsl:when test="$leader6='k'">still image</xsl:when>
3944                                 <xsl:when test="$leader6='g'">moving image</xsl:when>
3945                                 <xsl:when test="$leader6='r'">three dimensional object</xsl:when>
3946                                 <xsl:when test="$leader6='m'">software, multimedia</xsl:when>
3947                                 <xsl:when test="$leader6='p'">mixed material</xsl:when>
3948                         </xsl:choose>
3949                 </typeOfResource>
3950                 <xsl:if test="substring($controlField008,26,1)='d'">
3951                         <genre authority="marcgt">globe</genre>
3952                 </xsl:if>
3953                 <xsl:if
3954                         test="marc:controlfield[@tag='007'][substring(text(),1,1)='a'][substring(text(),2,1)='r']">
3955                         <genre authority="marcgt">remote-sensing image</genre>
3956                 </xsl:if>
3957                 <xsl:if test="$typeOf008='MP'">
3958                         <xsl:variable name="controlField008-25" select="substring($controlField008,26,1)"/>
3959                         <xsl:choose>
3960                                 <xsl:when
3961                                         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']">
3962                                         <genre authority="marcgt">map</genre>
3963                                 </xsl:when>
3964                                 <xsl:when
3965                                         test="$controlField008-25='e' or marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='d']">
3966                                         <genre authority="marcgt">atlas</genre>
3967                                 </xsl:when>
3968                         </xsl:choose>
3969                 </xsl:if>
3970                 <xsl:if test="$typeOf008='SE'">
3971                         <xsl:variable name="controlField008-21" select="substring($controlField008,22,1)"/>
3972                         <xsl:choose>
3973                                 <xsl:when test="$controlField008-21='d'">
3974                                         <genre authority="marcgt">database</genre>
3975                                 </xsl:when>
3976                                 <xsl:when test="$controlField008-21='l'">
3977                                         <genre authority="marcgt">loose-leaf</genre>
3978                                 </xsl:when>
3979                                 <xsl:when test="$controlField008-21='m'">
3980                                         <genre authority="marcgt">series</genre>
3981                                 </xsl:when>
3982                                 <xsl:when test="$controlField008-21='n'">
3983                                         <genre authority="marcgt">newspaper</genre>
3984                                 </xsl:when>
3985                                 <xsl:when test="$controlField008-21='p'">
3986                                         <genre authority="marcgt">periodical</genre>
3987                                 </xsl:when>
3988                                 <xsl:when test="$controlField008-21='w'">
3989                                         <genre authority="marcgt">web site</genre>
3990                                 </xsl:when>
3991                         </xsl:choose>
3992                 </xsl:if>
3993                 <xsl:if test="$typeOf008='BK' or $typeOf008='SE'">
3994                         <xsl:variable name="controlField008-24" select="substring($controlField008,25,4)"/>
3995                         <xsl:choose>
3996                                 <xsl:when test="contains($controlField008-24,'a')">
3997                                         <genre authority="marcgt">abstract or summary</genre>
3998                                 </xsl:when>
3999                                 <xsl:when test="contains($controlField008-24,'b')">
4000                                         <genre authority="marcgt">bibliography</genre>
4001                                 </xsl:when>
4002                                 <xsl:when test="contains($controlField008-24,'c')">
4003                                         <genre authority="marcgt">catalog</genre>
4004                                 </xsl:when>
4005                                 <xsl:when test="contains($controlField008-24,'d')">
4006                                         <genre authority="marcgt">dictionary</genre>
4007                                 </xsl:when>
4008                                 <xsl:when test="contains($controlField008-24,'e')">
4009                                         <genre authority="marcgt">encyclopedia</genre>
4010                                 </xsl:when>
4011                                 <xsl:when test="contains($controlField008-24,'f')">
4012                                         <genre authority="marcgt">handbook</genre>
4013                                 </xsl:when>
4014                                 <xsl:when test="contains($controlField008-24,'g')">
4015                                         <genre authority="marcgt">legal article</genre>
4016                                 </xsl:when>
4017                                 <xsl:when test="contains($controlField008-24,'i')">
4018                                         <genre authority="marcgt">index</genre>
4019                                 </xsl:when>
4020                                 <xsl:when test="contains($controlField008-24,'k')">
4021                                         <genre authority="marcgt">discography</genre>
4022                                 </xsl:when>
4023                                 <xsl:when test="contains($controlField008-24,'l')">
4024                                         <genre authority="marcgt">legislation</genre>
4025                                 </xsl:when>
4026                                 <xsl:when test="contains($controlField008-24,'m')">
4027                                         <genre authority="marcgt">theses</genre>
4028                                 </xsl:when>
4029                                 <xsl:when test="contains($controlField008-24,'n')">
4030                                         <genre authority="marcgt">survey of literature</genre>
4031                                 </xsl:when>
4032                                 <xsl:when test="contains($controlField008-24,'o')">
4033                                         <genre authority="marcgt">review</genre>
4034                                 </xsl:when>
4035                                 <xsl:when test="contains($controlField008-24,'p')">
4036                                         <genre authority="marcgt">programmed text</genre>
4037                                 </xsl:when>
4038                                 <xsl:when test="contains($controlField008-24,'q')">
4039                                         <genre authority="marcgt">filmography</genre>
4040                                 </xsl:when>
4041                                 <xsl:when test="contains($controlField008-24,'r')">
4042                                         <genre authority="marcgt">directory</genre>
4043                                 </xsl:when>
4044                                 <xsl:when test="contains($controlField008-24,'s')">
4045                                         <genre authority="marcgt">statistics</genre>
4046                                 </xsl:when>
4047                                 <xsl:when test="contains($controlField008-24,'t')">
4048                                         <genre authority="marcgt">technical report</genre>
4049                                 </xsl:when>
4050                                 <xsl:when test="contains($controlField008-24,'v')">
4051                                         <genre authority="marcgt">legal case and case notes</genre>
4052                                 </xsl:when>
4053                                 <xsl:when test="contains($controlField008-24,'w')">
4054                                         <genre authority="marcgt">law report or digest</genre>
4055                                 </xsl:when>
4056                                 <xsl:when test="contains($controlField008-24,'z')">
4057                                         <genre authority="marcgt">treaty</genre>
4058                                 </xsl:when>
4059                         </xsl:choose>
4060                         <xsl:variable name="controlField008-29" select="substring($controlField008,30,1)"/>
4061                         <xsl:choose>
4062                                 <xsl:when test="$controlField008-29='1'">
4063                                         <genre authority="marcgt">conference publication</genre>
4064                                 </xsl:when>
4065                         </xsl:choose>
4066                 </xsl:if>
4067                 <xsl:if test="$typeOf008='CF'">
4068                         <xsl:variable name="controlField008-26" select="substring($controlField008,27,1)"/>
4069                         <xsl:choose>
4070                                 <xsl:when test="$controlField008-26='a'">
4071                                         <genre authority="marcgt">numeric data</genre>
4072                                 </xsl:when>
4073                                 <xsl:when test="$controlField008-26='e'">
4074                                         <genre authority="marcgt">database</genre>
4075                                 </xsl:when>
4076                                 <xsl:when test="$controlField008-26='f'">
4077                                         <genre authority="marcgt">font</genre>
4078                                 </xsl:when>
4079                                 <xsl:when test="$controlField008-26='g'">
4080                                         <genre authority="marcgt">game</genre>
4081                                 </xsl:when>
4082                         </xsl:choose>
4083                 </xsl:if>
4084                 <xsl:if test="$typeOf008='BK'">
4085                         <xsl:if test="substring($controlField008,25,1)='j'">
4086                                 <genre authority="marcgt">patent</genre>
4087                         </xsl:if>
4088                         <xsl:if test="substring($controlField008,25,1)='2'">
4089                                 <genre authority="marcgt">offprint</genre>
4090                         </xsl:if>
4091                         <xsl:if test="substring($controlField008,31,1)='1'">
4092                                 <genre authority="marcgt">festschrift</genre>
4093                         </xsl:if>
4094                         <xsl:variable name="controlField008-34" select="substring($controlField008,35,1)"/>
4095                         <xsl:if
4096                                 test="$controlField008-34='a' or $controlField008-34='b' or $controlField008-34='c' or $controlField008-34='d'">
4097                                 <genre authority="marcgt">biography</genre>
4098                         </xsl:if>
4099                         <xsl:variable name="controlField008-33" select="substring($controlField008,34,1)"/>
4100                         <xsl:choose>
4101                                 <xsl:when test="$controlField008-33='e'">
4102                                         <genre authority="marcgt">essay</genre>
4103                                 </xsl:when>
4104                                 <xsl:when test="$controlField008-33='d'">
4105                                         <genre authority="marcgt">drama</genre>
4106                                 </xsl:when>
4107                                 <xsl:when test="$controlField008-33='c'">
4108                                         <genre authority="marcgt">comic strip</genre>
4109                                 </xsl:when>
4110                                 <xsl:when test="$controlField008-33='l'">
4111                                         <genre authority="marcgt">fiction</genre>
4112                                 </xsl:when>
4113                                 <xsl:when test="$controlField008-33='h'">
4114                                         <genre authority="marcgt">humor, satire</genre>
4115                                 </xsl:when>
4116                                 <xsl:when test="$controlField008-33='i'">
4117                                         <genre authority="marcgt">letter</genre>
4118                                 </xsl:when>
4119                                 <xsl:when test="$controlField008-33='f'">
4120                                         <genre authority="marcgt">novel</genre>
4121                                 </xsl:when>
4122                                 <xsl:when test="$controlField008-33='j'">
4123                                         <genre authority="marcgt">short story</genre>
4124                                 </xsl:when>
4125                                 <xsl:when test="$controlField008-33='s'">
4126                                         <genre authority="marcgt">speech</genre>
4127                                 </xsl:when>
4128                         </xsl:choose>
4129                 </xsl:if>
4130                 <xsl:if test="$typeOf008='MU'">
4131                         <xsl:variable name="controlField008-30-31" select="substring($controlField008,31,2)"/>
4132                         <xsl:if test="contains($controlField008-30-31,'b')">
4133                                 <genre authority="marcgt">biography</genre>
4134                         </xsl:if>
4135                         <xsl:if test="contains($controlField008-30-31,'c')">
4136                                 <genre authority="marcgt">conference publication</genre>
4137                         </xsl:if>
4138                         <xsl:if test="contains($controlField008-30-31,'d')">
4139                                 <genre authority="marcgt">drama</genre>
4140                         </xsl:if>
4141                         <xsl:if test="contains($controlField008-30-31,'e')">
4142                                 <genre authority="marcgt">essay</genre>
4143                         </xsl:if>
4144                         <xsl:if test="contains($controlField008-30-31,'f')">
4145                                 <genre authority="marcgt">fiction</genre>
4146                         </xsl:if>
4147                         <xsl:if test="contains($controlField008-30-31,'o')">
4148                                 <genre authority="marcgt">folktale</genre>
4149                         </xsl:if>
4150                         <xsl:if test="contains($controlField008-30-31,'h')">
4151                                 <genre authority="marcgt">history</genre>
4152                         </xsl:if>
4153                         <xsl:if test="contains($controlField008-30-31,'k')">
4154                                 <genre authority="marcgt">humor, satire</genre>
4155                         </xsl:if>
4156                         <xsl:if test="contains($controlField008-30-31,'m')">
4157                                 <genre authority="marcgt">memoir</genre>
4158                         </xsl:if>
4159                         <xsl:if test="contains($controlField008-30-31,'p')">
4160                                 <genre authority="marcgt">poetry</genre>
4161                         </xsl:if>
4162                         <xsl:if test="contains($controlField008-30-31,'r')">
4163                                 <genre authority="marcgt">rehearsal</genre>
4164                         </xsl:if>
4165                         <xsl:if test="contains($controlField008-30-31,'g')">
4166                                 <genre authority="marcgt">reporting</genre>
4167                         </xsl:if>
4168                         <xsl:if test="contains($controlField008-30-31,'s')">
4169                                 <genre authority="marcgt">sound</genre>
4170                         </xsl:if>
4171                         <xsl:if test="contains($controlField008-30-31,'l')">
4172                                 <genre authority="marcgt">speech</genre>
4173                         </xsl:if>
4174                 </xsl:if>
4175                 <xsl:if test="$typeOf008='VM'">
4176                         <xsl:variable name="controlField008-33" select="substring($controlField008,34,1)"/>
4177                         <xsl:choose>
4178                                 <xsl:when test="$controlField008-33='a'">
4179                                         <genre authority="marcgt">art original</genre>
4180                                 </xsl:when>
4181                                 <xsl:when test="$controlField008-33='b'">
4182                                         <genre authority="marcgt">kit</genre>
4183                                 </xsl:when>
4184                                 <xsl:when test="$controlField008-33='c'">
4185                                         <genre authority="marcgt">art reproduction</genre>
4186                                 </xsl:when>
4187                                 <xsl:when test="$controlField008-33='d'">
4188                                         <genre authority="marcgt">diorama</genre>
4189                                 </xsl:when>
4190                                 <xsl:when test="$controlField008-33='f'">
4191                                         <genre authority="marcgt">filmstrip</genre>
4192                                 </xsl:when>
4193                                 <xsl:when test="$controlField008-33='g'">
4194                                         <genre authority="marcgt">legal article</genre>
4195                                 </xsl:when>
4196                                 <xsl:when test="$controlField008-33='i'">
4197                                         <genre authority="marcgt">picture</genre>
4198                                 </xsl:when>
4199                                 <xsl:when test="$controlField008-33='k'">
4200                                         <genre authority="marcgt">graphic</genre>
4201                                 </xsl:when>
4202                                 <xsl:when test="$controlField008-33='l'">
4203                                         <genre authority="marcgt">technical drawing</genre>
4204                                 </xsl:when>
4205                                 <xsl:when test="$controlField008-33='m'">
4206                                         <genre authority="marcgt">motion picture</genre>
4207                                 </xsl:when>
4208                                 <xsl:when test="$controlField008-33='n'">
4209                                         <genre authority="marcgt">chart</genre>
4210                                 </xsl:when>
4211                                 <xsl:when test="$controlField008-33='o'">
4212                                         <genre authority="marcgt">flash card</genre>
4213                                 </xsl:when>
4214                                 <xsl:when test="$controlField008-33='p'">
4215                                         <genre authority="marcgt">microscope slide</genre>
4216                                 </xsl:when>
4217                                 <xsl:when
4218                                         test="$controlField008-33='q' or marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='q']">
4219                                         <genre authority="marcgt">model</genre>
4220                                 </xsl:when>
4221                                 <xsl:when test="$controlField008-33='r'">
4222                                         <genre authority="marcgt">realia</genre>
4223                                 </xsl:when>
4224                                 <xsl:when test="$controlField008-33='s'">
4225                                         <genre authority="marcgt">slide</genre>
4226                                 </xsl:when>
4227                                 <xsl:when test="$controlField008-33='t'">
4228                                         <genre authority="marcgt">transparency</genre>
4229                                 </xsl:when>
4230                                 <xsl:when test="$controlField008-33='v'">
4231                                         <genre authority="marcgt">videorecording</genre>
4232                                 </xsl:when>
4233                                 <xsl:when test="$controlField008-33='w'">
4234                                         <genre authority="marcgt">toy</genre>
4235                                 </xsl:when>
4236                         </xsl:choose>
4237                 </xsl:if>
4238
4239                 <!-- 1.20 047 genre tmee-->
4240
4241                 <xsl:for-each select="marc:datafield[@tag=047]">
4242                         <genre authority="marcgt">
4243                                 <xsl:attribute name="authority">
4244                                         <xsl:value-of select="marc:subfield[@code='2']"/>
4245                                 </xsl:attribute>
4246                                 <xsl:call-template name="subfieldSelect">
4247                                         <xsl:with-param name="codes">abcdef</xsl:with-param>
4248                                         <xsl:with-param name="delimeter">-</xsl:with-param>
4249                                 </xsl:call-template>
4250                         </genre>
4251                 </xsl:for-each>
4252                 <xsl:for-each select="marc:datafield[@tag=655]">
4253                         <genre authority="marcgt">
4254                                 <xsl:attribute name="authority">
4255                                         <xsl:value-of select="marc:subfield[@code='2']"/>
4256                                 </xsl:attribute>
4257                                 <xsl:call-template name="subfieldSelect">
4258                                         <xsl:with-param name="codes">abvxyz</xsl:with-param>
4259                                         <xsl:with-param name="delimeter">-</xsl:with-param>
4260                                 </xsl:call-template>
4261                         </genre>
4262                 </xsl:for-each>
4263                 <originInfo>
4264                         <xsl:variable name="MARCpublicationCode"
4265                                 select="normalize-space(substring($controlField008,16,3))"/>
4266                         <xsl:if test="translate($MARCpublicationCode,'|','')">
4267                                 <place>
4268                                         <placeTerm>
4269                                                 <xsl:attribute name="type">code</xsl:attribute>
4270                                                 <xsl:attribute name="authority">marccountry</xsl:attribute>
4271                                                 <xsl:value-of select="$MARCpublicationCode"/>
4272                                         </placeTerm>
4273                                 </place>
4274                         </xsl:if>
4275                         <xsl:for-each select="marc:datafield[@tag=044]/marc:subfield[@code='c']">
4276                                 <place>
4277                                         <placeTerm>
4278                                                 <xsl:attribute name="type">code</xsl:attribute>
4279                                                 <xsl:attribute name="authority">iso3166</xsl:attribute>
4280                                                 <xsl:value-of select="."/>
4281                                         </placeTerm>
4282                                 </place>
4283                         </xsl:for-each>
4284                         <xsl:for-each select="marc:datafield[@tag=260]/marc:subfield[@code='a']">
4285                                 <place>
4286                                         <placeTerm>
4287                                                 <xsl:attribute name="type">text</xsl:attribute>
4288                                                 <xsl:call-template name="chopPunctuationFront">
4289                                                         <xsl:with-param name="chopString">
4290                                                                 <xsl:call-template name="chopPunctuation">
4291                                                                         <xsl:with-param name="chopString" select="."/>
4292                                                                 </xsl:call-template>
4293                                                         </xsl:with-param>
4294                                                 </xsl:call-template>
4295                                         </placeTerm>
4296                                 </place>
4297                         </xsl:for-each>
4298                         <xsl:for-each select="marc:datafield[@tag=046]/marc:subfield[@code='m']">
4299                                 <dateValid point="start">
4300                                         <xsl:value-of select="."/>
4301                                 </dateValid>
4302                         </xsl:for-each>
4303                         <xsl:for-each select="marc:datafield[@tag=046]/marc:subfield[@code='n']">
4304                                 <dateValid point="end">
4305                                         <xsl:value-of select="."/>
4306                                 </dateValid>
4307                         </xsl:for-each>
4308                         <xsl:for-each select="marc:datafield[@tag=046]/marc:subfield[@code='j']">
4309                                 <dateModified>
4310                                         <xsl:value-of select="."/>
4311                                 </dateModified>
4312                         </xsl:for-each>
4313                         <xsl:for-each
4314                                 select="marc:datafield[@tag=260]/marc:subfield[@code='b' or @code='c' or @code='g']">
4315                                 <xsl:choose>
4316                                         <xsl:when test="@code='b'">
4317                                                 <publisher>
4318                                                         <xsl:call-template name="chopPunctuation">
4319                                                                 <xsl:with-param name="chopString" select="."/>
4320                                                                 <xsl:with-param name="punctuation">
4321                                                                         <xsl:text>:,;/ </xsl:text>
4322                                                                 </xsl:with-param>
4323                                                         </xsl:call-template>
4324                                                 </publisher>
4325                                         </xsl:when>
4326                                         <xsl:when test="@code='c'">
4327                                                 <dateIssued>
4328                                                         <xsl:call-template name="chopPunctuation">
4329                                                                 <xsl:with-param name="chopString" select="."/>
4330                                                         </xsl:call-template>
4331                                                 </dateIssued>
4332                                         </xsl:when>
4333                                         <xsl:when test="@code='g'">
4334                                                 <dateCreated>
4335                                                         <xsl:value-of select="."/>
4336                                                 </dateCreated>
4337                                         </xsl:when>
4338                                 </xsl:choose>
4339                         </xsl:for-each>
4340                         <xsl:variable name="dataField260c">
4341                                 <xsl:call-template name="chopPunctuation">
4342                                         <xsl:with-param name="chopString"
4343                                                 select="marc:datafield[@tag=260]/marc:subfield[@code='c']"/>
4344                                 </xsl:call-template>
4345                         </xsl:variable>
4346                         <xsl:variable name="controlField008-7-10"
4347                                 select="normalize-space(substring($controlField008, 8, 4))"/>
4348                         <xsl:variable name="controlField008-11-14"
4349                                 select="normalize-space(substring($controlField008, 12, 4))"/>
4350                         <xsl:variable name="controlField008-6"
4351                                 select="normalize-space(substring($controlField008, 7, 1))"/>
4352                         <xsl:if
4353                                 test="$controlField008-6='e' or $controlField008-6='p' or $controlField008-6='r' or $controlField008-6='t' or $controlField008-6='s'">
4354                                 <xsl:if test="$controlField008-7-10 and ($controlField008-7-10 != $dataField260c)">
4355                                         <dateIssued encoding="marc">
4356                                                 <xsl:value-of select="$controlField008-7-10"/>
4357                                         </dateIssued>
4358                                 </xsl:if>
4359                         </xsl:if>
4360                         <xsl:if
4361                                 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'">
4362                                 <xsl:if test="$controlField008-7-10">
4363                                         <dateIssued encoding="marc" point="start">
4364                                                 <xsl:value-of select="$controlField008-7-10"/>
4365                                         </dateIssued>
4366                                 </xsl:if>
4367                         </xsl:if>
4368                         <xsl:if
4369                                 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'">
4370                                 <xsl:if test="$controlField008-11-14">
4371                                         <dateIssued encoding="marc" point="end">
4372                                                 <xsl:value-of select="$controlField008-11-14"/>
4373                                         </dateIssued>
4374                                 </xsl:if>
4375                         </xsl:if>
4376                         <xsl:if test="$controlField008-6='q'">
4377                                 <xsl:if test="$controlField008-7-10">
4378                                         <dateIssued encoding="marc" point="start" qualifier="questionable">
4379                                                 <xsl:value-of select="$controlField008-7-10"/>
4380                                         </dateIssued>
4381                                 </xsl:if>
4382                         </xsl:if>
4383                         <xsl:if test="$controlField008-6='q'">
4384                                 <xsl:if test="$controlField008-11-14">
4385                                         <dateIssued encoding="marc" point="end" qualifier="questionable">
4386                                                 <xsl:value-of select="$controlField008-11-14"/>
4387                                         </dateIssued>
4388                                 </xsl:if>
4389                         </xsl:if>
4390                         <xsl:if test="$controlField008-6='t'">
4391                                 <xsl:if test="$controlField008-11-14">
4392                                         <copyrightDate encoding="marc">
4393                                                 <xsl:value-of select="$controlField008-11-14"/>
4394                                         </copyrightDate>
4395                                 </xsl:if>
4396                         </xsl:if>
4397                         <xsl:for-each
4398                                 select="marc:datafield[@tag=033][@ind1=0 or @ind1=1]/marc:subfield[@code='a']">
4399                                 <dateCaptured encoding="iso8601">
4400                                         <xsl:value-of select="."/>
4401                                 </dateCaptured>
4402                         </xsl:for-each>
4403                         <xsl:for-each select="marc:datafield[@tag=033][@ind1=2]/marc:subfield[@code='a'][1]">
4404                                 <dateCaptured encoding="iso8601" point="start">
4405                                         <xsl:value-of select="."/>
4406                                 </dateCaptured>
4407                         </xsl:for-each>
4408                         <xsl:for-each select="marc:datafield[@tag=033][@ind1=2]/marc:subfield[@code='a'][2]">
4409                                 <dateCaptured encoding="iso8601" point="end">
4410                                         <xsl:value-of select="."/>
4411                                 </dateCaptured>
4412                         </xsl:for-each>
4413                         <xsl:for-each select="marc:datafield[@tag=250]/marc:subfield[@code='a']">
4414                                 <edition>
4415                                         <xsl:value-of select="."/>
4416                                 </edition>
4417                         </xsl:for-each>
4418                         <xsl:for-each select="marc:leader">
4419                                 <issuance>
4420                                         <xsl:choose>
4421                                                 <xsl:when
4422                                                         test="$leader7='a' or $leader7='c' or $leader7='d' or $leader7='m'"
4423                                                         >monographic</xsl:when>
4424                                                 <xsl:when test="$leader7='b' or $leader7='i' or $leader7='s'"
4425                                                 >continuing</xsl:when>
4426                                         </xsl:choose>
4427                                 </issuance>
4428                         </xsl:for-each>
4429                         <xsl:for-each select="marc:datafield[@tag=310]|marc:datafield[@tag=321]">
4430                                 <frequency>
4431                                         <xsl:call-template name="subfieldSelect">
4432                                                 <xsl:with-param name="codes">ab</xsl:with-param>
4433                                         </xsl:call-template>
4434                                 </frequency>
4435                         </xsl:for-each>
4436                 </originInfo>
4437                 <xsl:variable name="controlField008-35-37"
4438                         select="normalize-space(translate(substring($controlField008,36,3),'|#',''))"/>
4439                 <xsl:if test="$controlField008-35-37">
4440                         <language>
4441                                 <languageTerm authority="iso639-2b" type="code">
4442                                         <xsl:value-of select="substring($controlField008,36,3)"/>
4443                                 </languageTerm>
4444                         </language>
4445                 </xsl:if>
4446                 <xsl:for-each select="marc:datafield[@tag=041]">
4447                         <xsl:for-each
4448                                 select="marc:subfield[@code='a' or @code='b' or @code='d' or @code='e' or @code='f' or @code='g' or @code='h']">
4449                                 <xsl:variable name="langCodes" select="."/>
4450                                 <xsl:choose>
4451                                         <xsl:when test="../marc:subfield[@code='2']='rfc3066'">
4452                                                 <!-- not stacked but could be repeated -->
4453                                                 <xsl:call-template name="rfcLanguages">
4454                                                         <xsl:with-param name="nodeNum">
4455                                                                 <xsl:value-of select="1"/>
4456                                                         </xsl:with-param>
4457                                                         <xsl:with-param name="usedLanguages">
4458                                                                 <xsl:text/>
4459                                                         </xsl:with-param>
4460                                                         <xsl:with-param name="controlField008-35-37">
4461                                                                 <xsl:value-of select="$controlField008-35-37"/>
4462                                                         </xsl:with-param>
4463                                                 </xsl:call-template>
4464                                         </xsl:when>
4465                                         <xsl:otherwise>
4466                                                 <!-- iso -->
4467                                                 <xsl:variable name="allLanguages">
4468                                                         <xsl:copy-of select="$langCodes"/>
4469                                                 </xsl:variable>
4470                                                 <xsl:variable name="currentLanguage">
4471                                                         <xsl:value-of select="substring($allLanguages,1,3)"/>
4472                                                 </xsl:variable>
4473                                                 <xsl:call-template name="isoLanguage">
4474                                                         <xsl:with-param name="currentLanguage">
4475                                                                 <xsl:value-of select="substring($allLanguages,1,3)"/>
4476                                                         </xsl:with-param>
4477                                                         <xsl:with-param name="remainingLanguages">
4478                                                                 <xsl:value-of
4479                                                                         select="substring($allLanguages,4,string-length($allLanguages)-3)"
4480                                                                 />
4481                                                         </xsl:with-param>
4482                                                         <xsl:with-param name="usedLanguages">
4483                                                                 <xsl:if test="$controlField008-35-37">
4484                                                                         <xsl:value-of select="$controlField008-35-37"/>
4485                                                                 </xsl:if>
4486                                                         </xsl:with-param>
4487                                                 </xsl:call-template>
4488                                         </xsl:otherwise>
4489                                 </xsl:choose>
4490                         </xsl:for-each>
4491                 </xsl:for-each>
4492                 <xsl:variable name="physicalDescription">
4493                         <!--3.2 change tmee 007/11 -->
4494                         <xsl:if test="$typeOf008='CF' and marc:controlfield[@tag=007][substring(.,12,1)='a']">
4495                                 <digitalOrigin>reformatted digital</digitalOrigin>
4496                         </xsl:if>
4497                         <xsl:if test="$typeOf008='CF' and marc:controlfield[@tag=007][substring(.,12,1)='b']">
4498                                 <digitalOrigin>digitized microfilm</digitalOrigin>
4499                         </xsl:if>
4500                         <xsl:if test="$typeOf008='CF' and marc:controlfield[@tag=007][substring(.,12,1)='d']">
4501                                 <digitalOrigin>digitized other analog</digitalOrigin>
4502                         </xsl:if>
4503                         <xsl:variable name="controlField008-23" select="substring($controlField008,24,1)"/>
4504                         <xsl:variable name="controlField008-29" select="substring($controlField008,30,1)"/>
4505                         <xsl:variable name="check008-23">
4506                                 <xsl:if
4507                                         test="$typeOf008='BK' or $typeOf008='MU' or $typeOf008='SE' or $typeOf008='MM'">
4508                                         <xsl:value-of select="true()"/>
4509                                 </xsl:if>
4510                         </xsl:variable>
4511                         <xsl:variable name="check008-29">
4512                                 <xsl:if test="$typeOf008='MP' or $typeOf008='VM'">
4513                                         <xsl:value-of select="true()"/>
4514                                 </xsl:if>
4515                         </xsl:variable>
4516                         <xsl:choose>
4517                                 <xsl:when
4518                                         test="($check008-23 and $controlField008-23='f') or ($check008-29 and $controlField008-29='f')">
4519                                         <form authority="marcform">braille</form>
4520                                 </xsl:when>
4521                                 <xsl:when
4522                                         test="($controlField008-23=' ' and ($leader6='c' or $leader6='d')) or (($typeOf008='BK' or $typeOf008='SE') and ($controlField008-23=' ' or $controlField008='r'))">
4523                                         <form authority="marcform">print</form>
4524                                 </xsl:when>
4525                                 <xsl:when
4526                                         test="$leader6 = 'm' or ($check008-23 and $controlField008-23='s') or ($check008-29 and $controlField008-29='s')">
4527                                         <form authority="marcform">electronic</form>
4528                                 </xsl:when>
4529                                 <xsl:when
4530                                         test="($check008-23 and $controlField008-23='b') or ($check008-29 and $controlField008-29='b')">
4531                                         <form authority="marcform">microfiche</form>
4532                                 </xsl:when>
4533                                 <xsl:when
4534                                         test="($check008-23 and $controlField008-23='a') or ($check008-29 and $controlField008-29='a')">
4535                                         <form authority="marcform">microfilm</form>
4536                                 </xsl:when>
4537                         </xsl:choose>
4538                         <!-- 1/04 fix -->
4539                         <xsl:if test="marc:datafield[@tag=130]/marc:subfield[@code='h']">
4540                                 <form authority="gmd">
4541                                         <xsl:call-template name="chopBrackets">
4542                                                 <xsl:with-param name="chopString">
4543                                                         <xsl:value-of select="marc:datafield[@tag=130]/marc:subfield[@code='h']"
4544                                                         />
4545                                                 </xsl:with-param>
4546                                         </xsl:call-template>
4547                                 </form>
4548                         </xsl:if>
4549                         <xsl:if test="marc:datafield[@tag=240]/marc:subfield[@code='h']">
4550                                 <form authority="gmd">
4551                                         <xsl:call-template name="chopBrackets">
4552                                                 <xsl:with-param name="chopString">
4553                                                         <xsl:value-of select="marc:datafield[@tag=240]/marc:subfield[@code='h']"
4554                                                         />
4555                                                 </xsl:with-param>
4556                                         </xsl:call-template>
4557                                 </form>
4558                         </xsl:if>
4559                         <xsl:if test="marc:datafield[@tag=242]/marc:subfield[@code='h']">
4560                                 <form authority="gmd">
4561                                         <xsl:call-template name="chopBrackets">
4562                                                 <xsl:with-param name="chopString">
4563                                                         <xsl:value-of select="marc:datafield[@tag=242]/marc:subfield[@code='h']"
4564                                                         />
4565                                                 </xsl:with-param>
4566                                         </xsl:call-template>
4567                                 </form>
4568                         </xsl:if>
4569                         <xsl:if test="marc:datafield[@tag=245]/marc:subfield[@code='h']">
4570                                 <form authority="gmd">
4571                                         <xsl:call-template name="chopBrackets">
4572                                                 <xsl:with-param name="chopString">
4573                                                         <xsl:value-of select="marc:datafield[@tag=245]/marc:subfield[@code='h']"
4574                                                         />
4575                                                 </xsl:with-param>
4576                                         </xsl:call-template>
4577                                 </form>
4578                         </xsl:if>
4579                         <xsl:if test="marc:datafield[@tag=246]/marc:subfield[@code='h']">
4580                                 <form authority="gmd">
4581                                         <xsl:call-template name="chopBrackets">
4582                                                 <xsl:with-param name="chopString">
4583                                                         <xsl:value-of select="marc:datafield[@tag=246]/marc:subfield[@code='h']"
4584                                                         />
4585                                                 </xsl:with-param>
4586                                         </xsl:call-template>
4587                                 </form>
4588                         </xsl:if>
4589                         <xsl:if test="marc:datafield[@tag=730]/marc:subfield[@code='h']">
4590                                 <form authority="gmd">
4591                                         <xsl:call-template name="chopBrackets">
4592                                                 <xsl:with-param name="chopString">
4593                                                         <xsl:value-of select="marc:datafield[@tag=730]/marc:subfield[@code='h']"
4594                                                         />
4595                                                 </xsl:with-param>
4596                                         </xsl:call-template>
4597                                 </form>
4598                         </xsl:if>
4599                         <xsl:for-each select="marc:datafield[@tag=256]/marc:subfield[@code='a']">
4600                                 <form>
4601                                         <xsl:value-of select="."/>
4602                                 </form>
4603                         </xsl:for-each>
4604                         <xsl:for-each select="marc:controlfield[@tag=007][substring(text(),1,1)='c']">
4605                                 <xsl:choose>
4606                                         <xsl:when test="substring(text(),14,1)='a'">
4607                                                 <reformattingQuality>access</reformattingQuality>
4608                                         </xsl:when>
4609                                         <xsl:when test="substring(text(),14,1)='p'">
4610                                                 <reformattingQuality>preservation</reformattingQuality>
4611                                         </xsl:when>
4612                                         <xsl:when test="substring(text(),14,1)='r'">
4613                                                 <reformattingQuality>replacement</reformattingQuality>
4614                                         </xsl:when>
4615                                 </xsl:choose>
4616                         </xsl:for-each>
4617                         <!--3.2 change tmee 007/01 -->
4618                         <xsl:if
4619                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='b']">
4620                                 <form authority="smd">chip cartridge</form>
4621                         </xsl:if>
4622                         <xsl:if
4623                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='c']">
4624                                 <form authority="smd">computer optical disc cartridge</form>
4625                         </xsl:if>
4626                         <xsl:if
4627                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='j']">
4628                                 <form authority="smd">magnetic disc</form>
4629                         </xsl:if>
4630                         <xsl:if
4631                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='m']">
4632                                 <form authority="smd">magneto-optical disc</form>
4633                         </xsl:if>
4634                         <xsl:if
4635                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='o']">
4636                                 <form authority="smd">optical disc</form>
4637                         </xsl:if>
4638                         <xsl:if
4639                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='r']">
4640                                 <form authority="smd">remote</form>
4641                         </xsl:if>
4642                         <xsl:if
4643                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='a']">
4644                                 <form authority="smd">tape cartridge</form>
4645                         </xsl:if>
4646                         <xsl:if
4647                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='f']">
4648                                 <form authority="smd">tape cassette</form>
4649                         </xsl:if>
4650                         <xsl:if
4651                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='h']">
4652                                 <form authority="smd">tape reel</form>
4653                         </xsl:if>
4654
4655                         <xsl:if
4656                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='d'][substring(text(),2,1)='a']">
4657                                 <form authority="smd">celestial globe</form>
4658                         </xsl:if>
4659                         <xsl:if
4660                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='d'][substring(text(),2,1)='e']">
4661                                 <form authority="smd">earth moon globe</form>
4662                         </xsl:if>
4663                         <xsl:if
4664                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='d'][substring(text(),2,1)='b']">
4665                                 <form authority="smd">planetary or lunar globe</form>
4666                         </xsl:if>
4667                         <xsl:if
4668                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='d'][substring(text(),2,1)='c']">
4669                                 <form authority="smd">terrestrial globe</form>
4670                         </xsl:if>
4671
4672                         <xsl:if
4673                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='o'][substring(text(),2,1)='o']">
4674                                 <form authority="smd">kit</form>
4675                         </xsl:if>
4676
4677                         <xsl:if
4678                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='d']">
4679                                 <form authority="smd">atlas</form>
4680                         </xsl:if>
4681                         <xsl:if
4682                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='g']">
4683                                 <form authority="smd">diagram</form>
4684                         </xsl:if>
4685                         <xsl:if
4686                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='j']">
4687                                 <form authority="smd">map</form>
4688                         </xsl:if>
4689                         <xsl:if
4690                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='q']">
4691                                 <form authority="smd">model</form>
4692                         </xsl:if>
4693                         <xsl:if
4694                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='k']">
4695                                 <form authority="smd">profile</form>
4696                         </xsl:if>
4697                         <xsl:if
4698                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='r']">
4699                                 <form authority="smd">remote-sensing image</form>
4700                         </xsl:if>
4701                         <xsl:if
4702                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='s']">
4703                                 <form authority="smd">section</form>
4704                         </xsl:if>
4705                         <xsl:if
4706                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='y']">
4707                                 <form authority="smd">view</form>
4708                         </xsl:if>
4709
4710                         <xsl:if
4711                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='a']">
4712                                 <form authority="smd">aperture card</form>
4713                         </xsl:if>
4714                         <xsl:if
4715                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='e']">
4716                                 <form authority="smd">microfiche</form>
4717                         </xsl:if>
4718                         <xsl:if
4719                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='f']">
4720                                 <form authority="smd">microfiche cassette</form>
4721                         </xsl:if>
4722                         <xsl:if
4723                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='b']">
4724                                 <form authority="smd">microfilm cartridge</form>
4725                         </xsl:if>
4726                         <xsl:if
4727                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='c']">
4728                                 <form authority="smd">microfilm cassette</form>
4729                         </xsl:if>
4730                         <xsl:if
4731                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='d']">
4732                                 <form authority="smd">microfilm reel</form>
4733                         </xsl:if>
4734                         <xsl:if
4735                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='g']">
4736                                 <form authority="smd">microopaque</form>
4737                         </xsl:if>
4738
4739                         <xsl:if
4740                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='m'][substring(text(),2,1)='c']">
4741                                 <form authority="smd">film cartridge</form>
4742                         </xsl:if>
4743                         <xsl:if
4744                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='m'][substring(text(),2,1)='f']">
4745                                 <form authority="smd">film cassette</form>
4746                         </xsl:if>
4747                         <xsl:if
4748                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='m'][substring(text(),2,1)='r']">
4749                                 <form authority="smd">film reel</form>
4750                         </xsl:if>
4751
4752                         <xsl:if
4753                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='n']">
4754                                 <form authority="smd">chart</form>
4755                         </xsl:if>
4756                         <xsl:if
4757                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='c']">
4758                                 <form authority="smd">collage</form>
4759                         </xsl:if>
4760                         <xsl:if
4761                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='d']">
4762                                 <form authority="smd">drawing</form>
4763                         </xsl:if>
4764                         <xsl:if
4765                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='o']">
4766                                 <form authority="smd">flash card</form>
4767                         </xsl:if>
4768                         <xsl:if
4769                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='e']">
4770                                 <form authority="smd">painting</form>
4771                         </xsl:if>
4772                         <xsl:if
4773                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='f']">
4774                                 <form authority="smd">photomechanical print</form>
4775                         </xsl:if>
4776                         <xsl:if
4777                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='g']">
4778                                 <form authority="smd">photonegative</form>
4779                         </xsl:if>
4780                         <xsl:if
4781                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='h']">
4782                                 <form authority="smd">photoprint</form>
4783                         </xsl:if>
4784                         <xsl:if
4785                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='i']">
4786                                 <form authority="smd">picture</form>
4787                         </xsl:if>
4788                         <xsl:if
4789                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='j']">
4790                                 <form authority="smd">print</form>
4791                         </xsl:if>
4792                         <xsl:if
4793                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='l']">
4794                                 <form authority="smd">technical drawing</form>
4795                         </xsl:if>
4796
4797                         <xsl:if
4798                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='q'][substring(text(),2,1)='q']">
4799                                 <form authority="smd">notated music</form>
4800                         </xsl:if>
4801
4802                         <xsl:if
4803                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='d']">
4804                                 <form authority="smd">filmslip</form>
4805                         </xsl:if>
4806                         <xsl:if
4807                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='c']">
4808                                 <form authority="smd">filmstrip cartridge</form>
4809                         </xsl:if>
4810                         <xsl:if
4811                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='o']">
4812                                 <form authority="smd">filmstrip roll</form>
4813                         </xsl:if>
4814                         <xsl:if
4815                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='f']">
4816                                 <form authority="smd">other filmstrip type</form>
4817                         </xsl:if>
4818                         <xsl:if
4819                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='s']">
4820                                 <form authority="smd">slide</form>
4821                         </xsl:if>
4822                         <xsl:if
4823                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='t']">
4824                                 <form authority="smd">transparency</form>
4825                         </xsl:if>
4826                         <xsl:if
4827                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='r'][substring(text(),2,1)='r']">
4828                                 <form authority="smd">remote-sensing image</form>
4829                         </xsl:if>
4830                         <xsl:if
4831                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='e']">
4832                                 <form authority="smd">cylinder</form>
4833                         </xsl:if>
4834                         <xsl:if
4835                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='q']">
4836                                 <form authority="smd">roll</form>
4837                         </xsl:if>
4838                         <xsl:if
4839                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='g']">
4840                                 <form authority="smd">sound cartridge</form>
4841                         </xsl:if>
4842                         <xsl:if
4843                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='s']">
4844                                 <form authority="smd">sound cassette</form>
4845                         </xsl:if>
4846                         <xsl:if
4847                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='d']">
4848                                 <form authority="smd">sound disc</form>
4849                         </xsl:if>
4850                         <xsl:if
4851                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='t']">
4852                                 <form authority="smd">sound-tape reel</form>
4853                         </xsl:if>
4854                         <xsl:if
4855                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='i']">
4856                                 <form authority="smd">sound-track film</form>
4857                         </xsl:if>
4858                         <xsl:if
4859                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='w']">
4860                                 <form authority="smd">wire recording</form>
4861                         </xsl:if>
4862
4863                         <xsl:if
4864                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='f'][substring(text(),2,1)='c']">
4865                                 <form authority="smd">braille</form>
4866                         </xsl:if>
4867                         <xsl:if
4868                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='f'][substring(text(),2,1)='b']">
4869                                 <form authority="smd">combination</form>
4870                         </xsl:if>
4871                         <xsl:if
4872                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='f'][substring(text(),2,1)='a']">
4873                                 <form authority="smd">moon</form>
4874                         </xsl:if>
4875                         <xsl:if
4876                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='f'][substring(text(),2,1)='d']">
4877                                 <form authority="smd">tactile, with no writing system</form>
4878                         </xsl:if>
4879
4880                         <xsl:if
4881                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='t'][substring(text(),2,1)='c']">
4882                                 <form authority="smd">braille</form>
4883                         </xsl:if>
4884                         <xsl:if
4885                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='t'][substring(text(),2,1)='b']">
4886                                 <form authority="smd">large print</form>
4887                         </xsl:if>
4888                         <xsl:if
4889                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='t'][substring(text(),2,1)='a']">
4890                                 <form authority="smd">regular print</form>
4891                         </xsl:if>
4892                         <xsl:if
4893                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='t'][substring(text(),2,1)='d']">
4894                                 <form authority="smd">text in looseleaf binder</form>
4895                         </xsl:if>
4896
4897                         <xsl:if
4898                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='v'][substring(text(),2,1)='c']">
4899                                 <form authority="smd">videocartridge</form>
4900                         </xsl:if>
4901                         <xsl:if
4902                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='v'][substring(text(),2,1)='f']">
4903                                 <form authority="smd">videocassette</form>
4904                         </xsl:if>
4905                         <xsl:if
4906                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='v'][substring(text(),2,1)='d']">
4907                                 <form authority="smd">videodisc</form>
4908                         </xsl:if>
4909                         <xsl:if
4910                                 test="marc:controlfield[@tag=007][substring(text(),1,1)='v'][substring(text(),2,1)='r']">
4911                                 <form authority="smd">videoreel</form>
4912                         </xsl:if>
4913
4914                         <xsl:for-each
4915                                 select="marc:datafield[@tag=856]/marc:subfield[@code='q'][string-length(.)&gt;1]">
4916                                 <internetMediaType>
4917                                         <xsl:value-of select="."/>
4918                                 </internetMediaType>
4919                         </xsl:for-each>
4920                         <xsl:for-each select="marc:datafield[@tag=300]">
4921                                 <extent>
4922                                         <xsl:call-template name="subfieldSelect">
4923                                                 <xsl:with-param name="codes">abce</xsl:with-param>
4924                                         </xsl:call-template>
4925                                 </extent>
4926                         </xsl:for-each>
4927                 </xsl:variable>
4928                 <xsl:if test="string-length(normalize-space($physicalDescription))">
4929                         <physicalDescription>
4930                                 <xsl:copy-of select="$physicalDescription"/>
4931                         </physicalDescription>
4932                 </xsl:if>
4933                 <xsl:for-each select="marc:datafield[@tag=520]">
4934                         <abstract>
4935                                 <xsl:call-template name="uri"/>
4936                                 <xsl:call-template name="subfieldSelect">
4937                                         <xsl:with-param name="codes">ab</xsl:with-param>
4938                                 </xsl:call-template>
4939                         </abstract>
4940                 </xsl:for-each>
4941                 <xsl:for-each select="marc:datafield[@tag=505]">
4942                         <tableOfContents>
4943                                 <xsl:call-template name="uri"/>
4944                                 <xsl:call-template name="subfieldSelect">
4945                                         <xsl:with-param name="codes">agrt</xsl:with-param>
4946                                 </xsl:call-template>
4947                         </tableOfContents>
4948                 </xsl:for-each>
4949                 <xsl:for-each select="marc:datafield[@tag=521]">
4950                         <targetAudience>
4951                                 <xsl:call-template name="subfieldSelect">
4952                                         <xsl:with-param name="codes">ab</xsl:with-param>
4953                                 </xsl:call-template>
4954                         </targetAudience>
4955                 </xsl:for-each>
4956                 <xsl:if test="$typeOf008='BK' or $typeOf008='CF' or $typeOf008='MU' or $typeOf008='VM'">
4957                         <xsl:variable name="controlField008-22" select="substring($controlField008,23,1)"/>
4958                         <xsl:choose>
4959                                 <!-- 01/04 fix -->
4960                                 <xsl:when test="$controlField008-22='d'">
4961                                         <targetAudience authority="marctarget">adolescent</targetAudience>
4962                                 </xsl:when>
4963                                 <xsl:when test="$controlField008-22='e'">
4964                                         <targetAudience authority="marctarget">adult</targetAudience>
4965                                 </xsl:when>
4966                                 <xsl:when test="$controlField008-22='g'">
4967                                         <targetAudience authority="marctarget">general</targetAudience>
4968                                 </xsl:when>
4969                                 <xsl:when
4970                                         test="$controlField008-22='b' or $controlField008-22='c' or $controlField008-22='j'">
4971                                         <targetAudience authority="marctarget">juvenile</targetAudience>
4972                                 </xsl:when>
4973                                 <xsl:when test="$controlField008-22='a'">
4974                                         <targetAudience authority="marctarget">preschool</targetAudience>
4975                                 </xsl:when>
4976                                 <xsl:when test="$controlField008-22='f'">
4977                                         <targetAudience authority="marctarget">specialized</targetAudience>
4978                                 </xsl:when>
4979                         </xsl:choose>
4980                 </xsl:if>
4981                 <xsl:for-each select="marc:datafield[@tag=245]/marc:subfield[@code='c']">
4982                         <note type="statement of responsibility">
4983                                 <xsl:value-of select="."/>
4984                         </note>
4985                 </xsl:for-each>
4986                 <xsl:for-each select="marc:datafield[@tag=500]">
4987                         <note>
4988                                 <xsl:value-of select="marc:subfield[@code='a']"/>
4989                                 <xsl:call-template name="uri"/>
4990                         </note>
4991                 </xsl:for-each>
4992
4993                 <!--3.2 change tmee additional note fields-->
4994
4995                 <xsl:for-each select="marc:datafield[@tag=506]">
4996                         <note type="restrictions">
4997                                 <xsl:call-template name="uri"/>
4998                                 <xsl:variable name="str">
4999                                         <xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
5000                                                 <xsl:value-of select="."/>
5001                                                 <xsl:text> </xsl:text>
5002                                         </xsl:for-each>
5003                                 </xsl:variable>
5004                                 <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
5005                         </note>
5006                 </xsl:for-each>
5007
5008                 <xsl:for-each select="marc:datafield[@tag=510]">
5009                         <note type="citation/reference">
5010                                 <xsl:call-template name="uri"/>
5011                                 <xsl:variable name="str">
5012                                         <xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
5013                                                 <xsl:value-of select="."/>
5014                                                 <xsl:text> </xsl:text>
5015                                         </xsl:for-each>
5016                                 </xsl:variable>
5017                                 <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
5018                         </note>
5019                 </xsl:for-each>
5020
5021
5022                 <xsl:for-each select="marc:datafield[@tag=511]">
5023                         <note type="performers">
5024                                 <xsl:call-template name="uri"/>
5025                                 <xsl:value-of select="marc:subfield[@code='a']"/>
5026                         </note>
5027                 </xsl:for-each>
5028                 <xsl:for-each select="marc:datafield[@tag=518]">
5029                         <note type="venue">
5030                                 <xsl:call-template name="uri"/>
5031                                 <xsl:value-of select="marc:subfield[@code='a']"/>
5032                         </note>
5033                 </xsl:for-each>
5034
5035                 <xsl:for-each select="marc:datafield[@tag=530]">
5036                         <note type="additional physical form">
5037                                 <xsl:call-template name="uri"/>
5038                                 <xsl:variable name="str">
5039                                         <xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
5040                                                 <xsl:value-of select="."/>
5041                                                 <xsl:text> </xsl:text>
5042                                         </xsl:for-each>
5043                                 </xsl:variable>
5044                                 <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
5045                         </note>
5046                 </xsl:for-each>
5047
5048                 <xsl:for-each select="marc:datafield[@tag=533]">
5049                         <note type="reproduction">
5050                                 <xsl:call-template name="uri"/>
5051                                 <xsl:variable name="str">
5052                                         <xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
5053                                                 <xsl:value-of select="."/>
5054                                                 <xsl:text> </xsl:text>
5055                                         </xsl:for-each>
5056                                 </xsl:variable>
5057                                 <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
5058                         </note>
5059                 </xsl:for-each>
5060
5061                 <xsl:for-each select="marc:datafield[@tag=534]">
5062                         <note type="original version">
5063                                 <xsl:call-template name="uri"/>
5064                                 <xsl:variable name="str">
5065                                         <xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
5066                                                 <xsl:value-of select="."/>
5067                                                 <xsl:text> </xsl:text>
5068                                         </xsl:for-each>
5069                                 </xsl:variable>
5070                                 <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
5071                         </note>
5072                 </xsl:for-each>
5073
5074                 <xsl:for-each select="marc:datafield[@tag=538]">
5075                         <note type="system details">
5076                                 <xsl:call-template name="uri"/>
5077                                 <xsl:variable name="str">
5078                                         <xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
5079                                                 <xsl:value-of select="."/>
5080                                                 <xsl:text> </xsl:text>
5081                                         </xsl:for-each>
5082                                 </xsl:variable>
5083                                 <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
5084                         </note>
5085                 </xsl:for-each>
5086
5087                 <xsl:for-each select="marc:datafield[@tag=583]">
5088                         <note type="action">
5089                                 <xsl:call-template name="uri"/>
5090                                 <xsl:variable name="str">
5091                                         <xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
5092                                                 <xsl:value-of select="."/>
5093                                                 <xsl:text> </xsl:text>
5094                                         </xsl:for-each>
5095                                 </xsl:variable>
5096                                 <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
5097                         </note>
5098                 </xsl:for-each>
5099
5100                 <xsl:for-each
5101                         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]">
5102                         <note>
5103                                 <xsl:call-template name="uri"/>
5104                                 <xsl:variable name="str">
5105                                         <xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
5106                                                 <xsl:value-of select="."/>
5107                                                 <xsl:text> </xsl:text>
5108                                         </xsl:for-each>
5109                                 </xsl:variable>
5110                                 <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
5111                         </note>
5112                 </xsl:for-each>
5113                 <xsl:for-each
5114                         select="marc:datafield[@tag=034][marc:subfield[@code='d' or @code='e' or @code='f' or @code='g']]">
5115                         <subject>
5116                                 <cartographics>
5117                                         <coordinates>
5118                                                 <xsl:call-template name="subfieldSelect">
5119                                                         <xsl:with-param name="codes">defg</xsl:with-param>
5120                                                 </xsl:call-template>
5121                                         </coordinates>
5122                                 </cartographics>
5123                         </subject>
5124                 </xsl:for-each>
5125                 <xsl:for-each select="marc:datafield[@tag=043]">
5126                         <subject>
5127                                 <xsl:for-each select="marc:subfield[@code='a' or @code='b' or @code='c']">
5128                                         <geographicCode>
5129                                                 <xsl:attribute name="authority">
5130                                                         <xsl:if test="@code='a'">
5131                                                                 <xsl:text>marcgac</xsl:text>
5132                                                         </xsl:if>
5133                                                         <xsl:if test="@code='b'">
5134                                                                 <xsl:value-of select="following-sibling::marc:subfield[@code=2]"/>
5135                                                         </xsl:if>
5136                                                         <xsl:if test="@code='c'">
5137                                                                 <xsl:text>iso3166</xsl:text>
5138                                                         </xsl:if>
5139                                                 </xsl:attribute>
5140                                                 <xsl:value-of select="self::marc:subfield"/>
5141                                         </geographicCode>
5142                                 </xsl:for-each>
5143                         </subject>
5144                 </xsl:for-each>
5145                 <!-- tmee 2006/11/27 -->
5146                 <xsl:for-each select="marc:datafield[@tag=255]">
5147                         <subject>
5148                                 <xsl:for-each select="marc:subfield[@code='a' or @code='b' or @code='c']">
5149                                         <cartographics>
5150                                                 <xsl:if test="@code='a'">
5151                                                         <scale>
5152                                                                 <xsl:value-of select="."/>
5153                                                         </scale>
5154                                                 </xsl:if>
5155                                                 <xsl:if test="@code='b'">
5156                                                         <projection>
5157                                                                 <xsl:value-of select="."/>
5158                                                         </projection>
5159                                                 </xsl:if>
5160                                                 <xsl:if test="@code='c'">
5161                                                         <coordinates>
5162                                                                 <xsl:value-of select="."/>
5163                                                         </coordinates>
5164                                                 </xsl:if>
5165                                         </cartographics>
5166                                 </xsl:for-each>
5167                         </subject>
5168                 </xsl:for-each>
5169
5170                 <xsl:apply-templates select="marc:datafield[653 &gt;= @tag and @tag &gt;= 600]"/>
5171                 <xsl:apply-templates select="marc:datafield[@tag=656]"/>
5172                 <xsl:for-each select="marc:datafield[@tag=752 or @tag=662]">
5173                         <subject>
5174                                 <hierarchicalGeographic>
5175                                         <xsl:for-each select="marc:subfield[@code='a']">
5176                                                 <country>
5177                                                         <xsl:call-template name="chopPunctuation">
5178                                                                 <xsl:with-param name="chopString" select="."/>
5179                                                         </xsl:call-template>
5180                                                 </country>
5181                                         </xsl:for-each>
5182                                         <xsl:for-each select="marc:subfield[@code='b']">
5183                                                 <state>
5184                                                         <xsl:call-template name="chopPunctuation">
5185                                                                 <xsl:with-param name="chopString" select="."/>
5186                                                         </xsl:call-template>
5187                                                 </state>
5188                                         </xsl:for-each>
5189                                         <xsl:for-each select="marc:subfield[@code='c']">
5190                                                 <county>
5191                                                         <xsl:call-template name="chopPunctuation">
5192                                                                 <xsl:with-param name="chopString" select="."/>
5193                                                         </xsl:call-template>
5194                                                 </county>
5195                                         </xsl:for-each>
5196                                         <xsl:for-each select="marc:subfield[@code='d']">
5197                                                 <city>
5198                                                         <xsl:call-template name="chopPunctuation">
5199                                                                 <xsl:with-param name="chopString" select="."/>
5200                                                         </xsl:call-template>
5201                                                 </city>
5202                                         </xsl:for-each>
5203                                         <xsl:for-each select="marc:subfield[@code='e']">
5204                                                 <citySection>
5205                                                         <xsl:call-template name="chopPunctuation">
5206                                                                 <xsl:with-param name="chopString" select="."/>
5207                                                         </xsl:call-template>
5208                                                 </citySection>
5209                                         </xsl:for-each>
5210                                         <xsl:for-each select="marc:subfield[@code='g']">
5211                                                 <region>
5212                                                         <xsl:call-template name="chopPunctuation">
5213                                                                 <xsl:with-param name="chopString" select="."/>
5214                                                         </xsl:call-template>
5215                                                 </region>
5216                                         </xsl:for-each>
5217                                         <xsl:for-each select="marc:subfield[@code='h']">
5218                                                 <extraterrestrialArea>
5219                                                         <xsl:call-template name="chopPunctuation">
5220                                                                 <xsl:with-param name="chopString" select="."/>
5221                                                         </xsl:call-template>
5222                                                 </extraterrestrialArea>
5223                                         </xsl:for-each>
5224                                 </hierarchicalGeographic>
5225                         </subject>
5226                 </xsl:for-each>
5227                 <xsl:for-each select="marc:datafield[@tag=045][marc:subfield[@code='b']]">
5228                         <subject>
5229                                 <xsl:choose>
5230                                         <xsl:when test="@ind1=2">
5231                                                 <temporal encoding="iso8601" point="start">
5232                                                         <xsl:call-template name="chopPunctuation">
5233                                                                 <xsl:with-param name="chopString">
5234                                                                         <xsl:value-of select="marc:subfield[@code='b'][1]"/>
5235                                                                 </xsl:with-param>
5236                                                         </xsl:call-template>
5237                                                 </temporal>
5238                                                 <temporal encoding="iso8601" point="end">
5239                                                         <xsl:call-template name="chopPunctuation">
5240                                                                 <xsl:with-param name="chopString">
5241                                                                         <xsl:value-of select="marc:subfield[@code='b'][2]"/>
5242                                                                 </xsl:with-param>
5243                                                         </xsl:call-template>
5244                                                 </temporal>
5245                                         </xsl:when>
5246                                         <xsl:otherwise>
5247                                                 <xsl:for-each select="marc:subfield[@code='b']">
5248                                                         <temporal encoding="iso8601">
5249                                                                 <xsl:call-template name="chopPunctuation">
5250                                                                         <xsl:with-param name="chopString" select="."/>
5251                                                                 </xsl:call-template>
5252                                                         </temporal>
5253                                                 </xsl:for-each>
5254                                         </xsl:otherwise>
5255                                 </xsl:choose>
5256                         </subject>
5257                 </xsl:for-each>
5258                 <xsl:for-each select="marc:datafield[@tag=050]">
5259                         <xsl:for-each select="marc:subfield[@code='b']">
5260                                 <classification authority="lcc">
5261                                         <xsl:if test="../marc:subfield[@code='3']">
5262                                                 <xsl:attribute name="displayLabel">
5263                                                         <xsl:value-of select="../marc:subfield[@code='3']"/>
5264                                                 </xsl:attribute>
5265                                         </xsl:if>
5266                                         <xsl:value-of select="preceding-sibling::marc:subfield[@code='a'][1]"/>
5267                                         <xsl:text> </xsl:text>
5268                                         <xsl:value-of select="text()"/>
5269                                 </classification>
5270                         </xsl:for-each>
5271                         <xsl:for-each
5272                                 select="marc:subfield[@code='a'][not(following-sibling::marc:subfield[@code='b'])]">
5273                                 <classification authority="lcc">
5274                                         <xsl:if test="../marc:subfield[@code='3']">
5275                                                 <xsl:attribute name="displayLabel">
5276                                                         <xsl:value-of select="../marc:subfield[@code='3']"/>
5277                                                 </xsl:attribute>
5278                                         </xsl:if>
5279                                         <xsl:value-of select="text()"/>
5280                                 </classification>
5281                         </xsl:for-each>
5282                 </xsl:for-each>
5283                 <xsl:for-each select="marc:datafield[@tag=082]">
5284                         <classification authority="ddc">
5285                                 <xsl:if test="marc:subfield[@code='2']">
5286                                         <xsl:attribute name="edition">
5287                                                 <xsl:value-of select="marc:subfield[@code='2']"/>
5288                                         </xsl:attribute>
5289                                 </xsl:if>
5290                                 <xsl:call-template name="subfieldSelect">
5291                                         <xsl:with-param name="codes">ab</xsl:with-param>
5292                                 </xsl:call-template>
5293                         </classification>
5294                 </xsl:for-each>
5295                 <xsl:for-each select="marc:datafield[@tag=080]">
5296                         <classification authority="udc">
5297                                 <xsl:call-template name="subfieldSelect">
5298                                         <xsl:with-param name="codes">abx</xsl:with-param>
5299                                 </xsl:call-template>
5300                         </classification>
5301                 </xsl:for-each>
5302                 <xsl:for-each select="marc:datafield[@tag=060]">
5303                         <classification authority="nlm">
5304                                 <xsl:call-template name="subfieldSelect">
5305                                         <xsl:with-param name="codes">ab</xsl:with-param>
5306                                 </xsl:call-template>
5307                         </classification>
5308                 </xsl:for-each>
5309                 <xsl:for-each select="marc:datafield[@tag=086][@ind1=0]">
5310                         <classification authority="sudocs">
5311                                 <xsl:value-of select="marc:subfield[@code='a']"/>
5312                         </classification>
5313                 </xsl:for-each>
5314                 <xsl:for-each select="marc:datafield[@tag=086][@ind1=1]">
5315                         <classification authority="candoc">
5316                                 <xsl:value-of select="marc:subfield[@code='a']"/>
5317                         </classification>
5318                 </xsl:for-each>
5319                 <xsl:for-each select="marc:datafield[@tag=086]">
5320                         <classification>
5321                                 <xsl:attribute name="authority">
5322                                         <xsl:value-of select="marc:subfield[@code='2']"/>
5323                                 </xsl:attribute>
5324                                 <xsl:value-of select="marc:subfield[@code='a']"/>
5325                         </classification>
5326                 </xsl:for-each>
5327                 <xsl:for-each select="marc:datafield[@tag=084]">
5328                         <classification>
5329                                 <xsl:attribute name="authority">
5330                                         <xsl:value-of select="marc:subfield[@code='2']"/>
5331                                 </xsl:attribute>
5332                                 <xsl:call-template name="subfieldSelect">
5333                                         <xsl:with-param name="codes">ab</xsl:with-param>
5334                                 </xsl:call-template>
5335                         </classification>
5336                 </xsl:for-each>
5337                 <xsl:for-each select="marc:datafield[@tag=440]">
5338                         <relatedItem type="series">
5339                                 <titleInfo>
5340                                         <title>
5341                                                 <xsl:call-template name="chopPunctuation">
5342                                                         <xsl:with-param name="chopString">
5343                                                                 <xsl:call-template name="subfieldSelect">
5344                                                                         <xsl:with-param name="codes">av</xsl:with-param>
5345                                                                 </xsl:call-template>
5346                                                         </xsl:with-param>
5347                                                 </xsl:call-template>
5348                                         </title>
5349                                         <xsl:call-template name="part"/>
5350                                 </titleInfo>
5351                         </relatedItem>
5352                 </xsl:for-each>
5353                 <xsl:for-each select="marc:datafield[@tag=490][@ind1=0]">
5354                         <relatedItem type="series">
5355                                 <titleInfo>
5356                                         <title>
5357                                                 <xsl:call-template name="chopPunctuation">
5358                                                         <xsl:with-param name="chopString">
5359                                                                 <xsl:call-template name="subfieldSelect">
5360                                                                         <xsl:with-param name="codes">av</xsl:with-param>
5361                                                                 </xsl:call-template>
5362                                                         </xsl:with-param>
5363                                                 </xsl:call-template>
5364                                         </title>
5365                                         <xsl:call-template name="part"/>
5366                                 </titleInfo>
5367                         </relatedItem>
5368                 </xsl:for-each>
5369                 <xsl:for-each select="marc:datafield[@tag=510]">
5370                         <relatedItem type="isReferencedBy">
5371                                 <note>
5372                                         <xsl:call-template name="subfieldSelect">
5373                                                 <xsl:with-param name="codes">abcx3</xsl:with-param>
5374                                         </xsl:call-template>
5375                                 </note>
5376                         </relatedItem>
5377                 </xsl:for-each>
5378                 <xsl:for-each select="marc:datafield[@tag=534]">
5379                         <relatedItem type="original">
5380                                 <xsl:call-template name="relatedTitle"/>
5381                                 <xsl:call-template name="relatedName"/>
5382                                 <xsl:if test="marc:subfield[@code='b' or @code='c']">
5383                                         <originInfo>
5384                                                 <xsl:for-each select="marc:subfield[@code='c']">
5385                                                         <publisher>
5386                                                                 <xsl:value-of select="."/>
5387                                                         </publisher>
5388                                                 </xsl:for-each>
5389                                                 <xsl:for-each select="marc:subfield[@code='b']">
5390                                                         <edition>
5391                                                                 <xsl:value-of select="."/>
5392                                                         </edition>
5393                                                 </xsl:for-each>
5394                                         </originInfo>
5395                                 </xsl:if>
5396                                 <xsl:call-template name="relatedIdentifierISSN"/>
5397                                 <xsl:for-each select="marc:subfield[@code='z']">
5398                                         <identifier type="isbn">
5399                                                 <xsl:value-of select="."/>
5400                                         </identifier>
5401                                 </xsl:for-each>
5402                                 <xsl:call-template name="relatedNote"/>
5403                         </relatedItem>
5404                 </xsl:for-each>
5405                 <xsl:for-each select="marc:datafield[@tag=700][marc:subfield[@code='t']]">
5406                         <relatedItem>
5407                                 <xsl:call-template name="constituentOrRelatedType"/>
5408                                 <titleInfo>
5409                                         <title>
5410                                                 <xsl:call-template name="chopPunctuation">
5411                                                         <xsl:with-param name="chopString">
5412                                                                 <xsl:call-template name="specialSubfieldSelect">
5413                                                                         <xsl:with-param name="anyCodes">tfklmorsv</xsl:with-param>
5414                                                                         <xsl:with-param name="axis">t</xsl:with-param>
5415                                                                         <xsl:with-param name="afterCodes">g</xsl:with-param>
5416                                                                 </xsl:call-template>
5417                                                         </xsl:with-param>
5418                                                 </xsl:call-template>
5419                                         </title>
5420                                         <xsl:call-template name="part"/>
5421                                 </titleInfo>
5422                                 <name type="personal">
5423                                         <namePart>
5424                                                 <xsl:call-template name="specialSubfieldSelect">
5425                                                         <xsl:with-param name="anyCodes">aq</xsl:with-param>
5426                                                         <xsl:with-param name="axis">t</xsl:with-param>
5427                                                         <xsl:with-param name="beforeCodes">g</xsl:with-param>
5428                                                 </xsl:call-template>
5429                                         </namePart>
5430                                         <xsl:call-template name="termsOfAddress"/>
5431                                         <xsl:call-template name="nameDate"/>
5432                                         <xsl:call-template name="role"/>
5433                                 </name>
5434                                 <xsl:call-template name="relatedForm"/>
5435                                 <xsl:call-template name="relatedIdentifierISSN"/>
5436                         </relatedItem>
5437                 </xsl:for-each>
5438                 <xsl:for-each select="marc:datafield[@tag=710][marc:subfield[@code='t']]">
5439                         <relatedItem>
5440                                 <xsl:call-template name="constituentOrRelatedType"/>
5441                                 <titleInfo>
5442                                         <title>
5443                                                 <xsl:call-template name="chopPunctuation">
5444                                                         <xsl:with-param name="chopString">
5445                                                                 <xsl:call-template name="specialSubfieldSelect">
5446                                                                         <xsl:with-param name="anyCodes">tfklmorsv</xsl:with-param>
5447                                                                         <xsl:with-param name="axis">t</xsl:with-param>
5448                                                                         <xsl:with-param name="afterCodes">dg</xsl:with-param>
5449                                                                 </xsl:call-template>
5450                                                         </xsl:with-param>
5451                                                 </xsl:call-template>
5452                                         </title>
5453                                         <xsl:call-template name="relatedPartNumName"/>
5454                                 </titleInfo>
5455                                 <name type="corporate">
5456                                         <xsl:for-each select="marc:subfield[@code='a']">
5457                                                 <namePart>
5458                                                         <xsl:value-of select="."/>
5459                                                 </namePart>
5460                                         </xsl:for-each>
5461                                         <xsl:for-each select="marc:subfield[@code='b']">
5462                                                 <namePart>
5463                                                         <xsl:value-of select="."/>
5464                                                 </namePart>
5465                                         </xsl:for-each>
5466                                         <xsl:variable name="tempNamePart">
5467                                                 <xsl:call-template name="specialSubfieldSelect">
5468                                                         <xsl:with-param name="anyCodes">c</xsl:with-param>
5469                                                         <xsl:with-param name="axis">t</xsl:with-param>
5470                                                         <xsl:with-param name="beforeCodes">dgn</xsl:with-param>
5471                                                 </xsl:call-template>
5472                                         </xsl:variable>
5473                                         <xsl:if test="normalize-space($tempNamePart)">
5474                                                 <namePart>
5475                                                         <xsl:value-of select="$tempNamePart"/>
5476                                                 </namePart>
5477                                         </xsl:if>
5478                                         <xsl:call-template name="role"/>
5479                                 </name>
5480                                 <xsl:call-template name="relatedForm"/>
5481                                 <xsl:call-template name="relatedIdentifierISSN"/>
5482                         </relatedItem>
5483                 </xsl:for-each>
5484                 <xsl:for-each select="marc:datafield[@tag=711][marc:subfield[@code='t']]">
5485                         <relatedItem>
5486                                 <xsl:call-template name="constituentOrRelatedType"/>
5487                                 <titleInfo>
5488                                         <title>
5489                                                 <xsl:call-template name="chopPunctuation">
5490                                                         <xsl:with-param name="chopString">
5491                                                                 <xsl:call-template name="specialSubfieldSelect">
5492                                                                         <xsl:with-param name="anyCodes">tfklsv</xsl:with-param>
5493                                                                         <xsl:with-param name="axis">t</xsl:with-param>
5494                                                                         <xsl:with-param name="afterCodes">g</xsl:with-param>
5495                                                                 </xsl:call-template>
5496                                                         </xsl:with-param>
5497                                                 </xsl:call-template>
5498                                         </title>
5499                                         <xsl:call-template name="relatedPartNumName"/>
5500                                 </titleInfo>
5501                                 <name type="conference">
5502                                         <namePart>
5503                                                 <xsl:call-template name="specialSubfieldSelect">
5504                                                         <xsl:with-param name="anyCodes">aqdc</xsl:with-param>
5505                                                         <xsl:with-param name="axis">t</xsl:with-param>
5506                                                         <xsl:with-param name="beforeCodes">gn</xsl:with-param>
5507                                                 </xsl:call-template>
5508                                         </namePart>
5509                                 </name>
5510                                 <xsl:call-template name="relatedForm"/>
5511                                 <xsl:call-template name="relatedIdentifierISSN"/>
5512                         </relatedItem>
5513                 </xsl:for-each>
5514                 <xsl:for-each select="marc:datafield[@tag=730][@ind2=2]">
5515                         <relatedItem>
5516                                 <xsl:call-template name="constituentOrRelatedType"/>
5517                                 <titleInfo>
5518                                         <title>
5519                                                 <xsl:call-template name="chopPunctuation">
5520                                                         <xsl:with-param name="chopString">
5521                                                                 <xsl:call-template name="subfieldSelect">
5522                                                                         <xsl:with-param name="codes">adfgklmorsv</xsl:with-param>
5523                                                                 </xsl:call-template>
5524                                                         </xsl:with-param>
5525                                                 </xsl:call-template>
5526                                         </title>
5527                                         <xsl:call-template name="part"/>
5528                                 </titleInfo>
5529                                 <xsl:call-template name="relatedForm"/>
5530                                 <xsl:call-template name="relatedIdentifierISSN"/>
5531                         </relatedItem>
5532                 </xsl:for-each>
5533                 <xsl:for-each select="marc:datafield[@tag=740][@ind2=2]">
5534                         <relatedItem>
5535                                 <xsl:call-template name="constituentOrRelatedType"/>
5536                                 <titleInfo>
5537                                         <title>
5538                                                 <xsl:call-template name="chopPunctuation">
5539                                                         <xsl:with-param name="chopString">
5540                                                                 <xsl:value-of select="marc:subfield[@code='a']"/>
5541                                                         </xsl:with-param>
5542                                                 </xsl:call-template>
5543                                         </title>
5544                                         <xsl:call-template name="part"/>
5545                                 </titleInfo>
5546                                 <xsl:call-template name="relatedForm"/>
5547                         </relatedItem>
5548                 </xsl:for-each>
5549                 <xsl:for-each select="marc:datafield[@tag=760]|marc:datafield[@tag=762]">
5550                         <relatedItem type="series">
5551                                 <xsl:call-template name="relatedItem76X-78X"/>
5552                         </relatedItem>
5553                 </xsl:for-each>
5554                 <xsl:for-each
5555                         select="marc:datafield[@tag=765]|marc:datafield[@tag=767]|marc:datafield[@tag=777]|marc:datafield[@tag=787]">
5556                         <relatedItem>
5557                                 <xsl:call-template name="relatedItem76X-78X"/>
5558                         </relatedItem>
5559                 </xsl:for-each>
5560                 <xsl:for-each select="marc:datafield[@tag=775]">
5561                         <relatedItem type="otherVersion">
5562                                 <xsl:call-template name="relatedItem76X-78X"/>
5563                         </relatedItem>
5564                 </xsl:for-each>
5565                 <xsl:for-each select="marc:datafield[@tag=770]|marc:datafield[@tag=774]">
5566                         <relatedItem type="constituent">
5567                                 <xsl:call-template name="relatedItem76X-78X"/>
5568                         </relatedItem>
5569                 </xsl:for-each>
5570                 <xsl:for-each select="marc:datafield[@tag=772]|marc:datafield[@tag=773]">
5571                         <relatedItem type="host">
5572                                 <xsl:call-template name="relatedItem76X-78X"/>
5573                         </relatedItem>
5574                 </xsl:for-each>
5575                 <xsl:for-each select="marc:datafield[@tag=776]">
5576                         <relatedItem type="otherFormat">
5577                                 <xsl:call-template name="relatedItem76X-78X"/>
5578                         </relatedItem>
5579                 </xsl:for-each>
5580                 <xsl:for-each select="marc:datafield[@tag=780]">
5581                         <relatedItem type="preceding">
5582                                 <xsl:call-template name="relatedItem76X-78X"/>
5583                         </relatedItem>
5584                 </xsl:for-each>
5585                 <xsl:for-each select="marc:datafield[@tag=785]">
5586                         <relatedItem type="succeeding">
5587                                 <xsl:call-template name="relatedItem76X-78X"/>
5588                         </relatedItem>
5589                 </xsl:for-each>
5590                 <xsl:for-each select="marc:datafield[@tag=786]">
5591                         <relatedItem type="original">
5592                                 <xsl:call-template name="relatedItem76X-78X"/>
5593                         </relatedItem>
5594                 </xsl:for-each>
5595                 <xsl:for-each select="marc:datafield[@tag=800]">
5596                         <relatedItem type="series">
5597                                 <titleInfo>
5598                                         <title>
5599                                                 <xsl:call-template name="chopPunctuation">
5600                                                         <xsl:with-param name="chopString">
5601                                                                 <xsl:call-template name="specialSubfieldSelect">
5602                                                                         <xsl:with-param name="anyCodes">tfklmorsv</xsl:with-param>
5603                                                                         <xsl:with-param name="axis">t</xsl:with-param>
5604                                                                         <xsl:with-param name="afterCodes">g</xsl:with-param>
5605                                                                 </xsl:call-template>
5606                                                         </xsl:with-param>
5607                                                 </xsl:call-template>
5608                                         </title>
5609                                         <xsl:call-template name="part"/>
5610                                 </titleInfo>
5611                                 <name type="personal">
5612                                         <namePart>
5613                                                 <xsl:call-template name="chopPunctuation">
5614                                                         <xsl:with-param name="chopString">
5615                                                                 <xsl:call-template name="specialSubfieldSelect">
5616                                                                         <xsl:with-param name="anyCodes">aq</xsl:with-param>
5617                                                                         <xsl:with-param name="axis">t</xsl:with-param>
5618                                                                         <xsl:with-param name="beforeCodes">g</xsl:with-param>
5619                                                                 </xsl:call-template>
5620                                                         </xsl:with-param>
5621                                                 </xsl:call-template>
5622                                         </namePart>
5623                                         <xsl:call-template name="termsOfAddress"/>
5624                                         <xsl:call-template name="nameDate"/>
5625                                         <xsl:call-template name="role"/>
5626                                 </name>
5627                                 <xsl:call-template name="relatedForm"/>
5628                         </relatedItem>
5629                 </xsl:for-each>
5630                 <xsl:for-each select="marc:datafield[@tag=810]">
5631                         <relatedItem type="series">
5632                                 <titleInfo>
5633                                         <title>
5634                                                 <xsl:call-template name="chopPunctuation">
5635                                                         <xsl:with-param name="chopString">
5636                                                                 <xsl:call-template name="specialSubfieldSelect">
5637                                                                         <xsl:with-param name="anyCodes">tfklmorsv</xsl:with-param>
5638                                                                         <xsl:with-param name="axis">t</xsl:with-param>
5639                                                                         <xsl:with-param name="afterCodes">dg</xsl:with-param>
5640                                                                 </xsl:call-template>
5641                                                         </xsl:with-param>
5642                                                 </xsl:call-template>
5643                                         </title>
5644                                         <xsl:call-template name="relatedPartNumName"/>
5645                                 </titleInfo>
5646                                 <name type="corporate">
5647                                         <xsl:for-each select="marc:subfield[@code='a']">
5648                                                 <namePart>
5649                                                         <xsl:value-of select="."/>
5650                                                 </namePart>
5651                                         </xsl:for-each>
5652                                         <xsl:for-each select="marc:subfield[@code='b']">
5653                                                 <namePart>
5654                                                         <xsl:value-of select="."/>
5655                                                 </namePart>
5656                                         </xsl:for-each>
5657                                         <namePart>
5658                                                 <xsl:call-template name="specialSubfieldSelect">
5659                                                         <xsl:with-param name="anyCodes">c</xsl:with-param>
5660                                                         <xsl:with-param name="axis">t</xsl:with-param>
5661                                                         <xsl:with-param name="beforeCodes">dgn</xsl:with-param>
5662                                                 </xsl:call-template>
5663                                         </namePart>
5664                                         <xsl:call-template name="role"/>
5665                                 </name>
5666                                 <xsl:call-template name="relatedForm"/>
5667                         </relatedItem>
5668                 </xsl:for-each>
5669                 <xsl:for-each select="marc:datafield[@tag=811]">
5670                         <relatedItem type="series">
5671                                 <titleInfo>
5672                                         <title>
5673                                                 <xsl:call-template name="chopPunctuation">
5674                                                         <xsl:with-param name="chopString">
5675                                                                 <xsl:call-template name="specialSubfieldSelect">
5676                                                                         <xsl:with-param name="anyCodes">tfklsv</xsl:with-param>
5677                                                                         <xsl:with-param name="axis">t</xsl:with-param>
5678                                                                         <xsl:with-param name="afterCodes">g</xsl:with-param>
5679                                                                 </xsl:call-template>
5680                                                         </xsl:with-param>
5681                                                 </xsl:call-template>
5682                                         </title>
5683                                         <xsl:call-template name="relatedPartNumName"/>
5684                                 </titleInfo>
5685                                 <name type="conference">
5686                                         <namePart>
5687                                                 <xsl:call-template name="specialSubfieldSelect">
5688                                                         <xsl:with-param name="anyCodes">aqdc</xsl:with-param>
5689                                                         <xsl:with-param name="axis">t</xsl:with-param>
5690                                                         <xsl:with-param name="beforeCodes">gn</xsl:with-param>
5691                                                 </xsl:call-template>
5692                                         </namePart>
5693                                         <xsl:call-template name="role"/>
5694                                 </name>
5695                                 <xsl:call-template name="relatedForm"/>
5696                         </relatedItem>
5697                 </xsl:for-each>
5698                 <xsl:for-each select="marc:datafield[@tag='830']">
5699                         <relatedItem type="series">
5700                                 <titleInfo>
5701                                         <title>
5702                                                 <xsl:call-template name="chopPunctuation">
5703                                                         <xsl:with-param name="chopString">
5704                                                                 <xsl:call-template name="subfieldSelect">
5705                                                                         <xsl:with-param name="codes">adfgklmorsv</xsl:with-param>
5706                                                                 </xsl:call-template>
5707                                                         </xsl:with-param>
5708                                                 </xsl:call-template>
5709                                         </title>
5710                                         <xsl:call-template name="part"/>
5711                                 </titleInfo>
5712                                 <xsl:call-template name="relatedForm"/>
5713                         </relatedItem>
5714                 </xsl:for-each>
5715                 <xsl:for-each select="marc:datafield[@tag='856'][@ind2='2']/marc:subfield[@code='q']">
5716                         <relatedItem>
5717                                 <internetMediaType>
5718                                         <xsl:value-of select="."/>
5719                                 </internetMediaType>
5720                         </relatedItem>
5721                 </xsl:for-each>
5722                 <xsl:for-each select="marc:datafield[@tag='020']">
5723                         <xsl:call-template name="isInvalid">
5724                                 <xsl:with-param name="type">isbn</xsl:with-param>
5725                         </xsl:call-template>
5726                         <xsl:if test="marc:subfield[@code='a']">
5727                                 <identifier type="isbn">
5728                                         <xsl:value-of select="marc:subfield[@code='a']"/>
5729                                 </identifier>
5730                         </xsl:if>
5731                 </xsl:for-each>
5732                 <xsl:for-each select="marc:datafield[@tag='024'][@ind1='0']">
5733                         <xsl:call-template name="isInvalid">
5734                                 <xsl:with-param name="type">isrc</xsl:with-param>
5735                         </xsl:call-template>
5736                         <xsl:if test="marc:subfield[@code='a']">
5737                                 <identifier type="isrc">
5738                                         <xsl:value-of select="marc:subfield[@code='a']"/>
5739                                 </identifier>
5740                         </xsl:if>
5741                 </xsl:for-each>
5742                 <xsl:for-each select="marc:datafield[@tag='024'][@ind1='2']">
5743                         <xsl:call-template name="isInvalid">
5744                                 <xsl:with-param name="type">ismn</xsl:with-param>
5745                         </xsl:call-template>
5746                         <xsl:if test="marc:subfield[@code='a']">
5747                                 <identifier type="ismn">
5748                                         <xsl:value-of select="marc:subfield[@code='a']"/>
5749                                 </identifier>
5750                         </xsl:if>
5751                 </xsl:for-each>
5752                 <xsl:for-each select="marc:datafield[@tag='024'][@ind1='4']">
5753                         <xsl:call-template name="isInvalid">
5754                                 <xsl:with-param name="type">sici</xsl:with-param>
5755                         </xsl:call-template>
5756                         <identifier type="sici">
5757                                 <xsl:call-template name="subfieldSelect">
5758                                         <xsl:with-param name="codes">ab</xsl:with-param>
5759                                 </xsl:call-template>
5760                         </identifier>
5761                 </xsl:for-each>
5762                 <xsl:for-each select="marc:datafield[@tag='022']">
5763                         <xsl:if test="marc:subfield[@code='a']">
5764                                 <xsl:call-template name="isInvalid">
5765                                         <xsl:with-param name="type">issn</xsl:with-param>
5766                                 </xsl:call-template>
5767                                 <identifier type="issn">
5768                                         <xsl:value-of select="marc:subfield[@code='a']"/>
5769                                 </identifier>
5770                         </xsl:if>
5771                         <xsl:if test="marc:subfield[@code='l']">
5772                                 <xsl:call-template name="isInvalid">
5773                                         <xsl:with-param name="type">issn-l</xsl:with-param>
5774                                 </xsl:call-template>
5775                                 <identifier type="issn-l">
5776                                         <xsl:value-of select="marc:subfield[@code='l']"/>
5777                                 </identifier>
5778                         </xsl:if>
5779                 </xsl:for-each>
5780
5781
5782
5783                 <xsl:for-each select="marc:datafield[@tag='010']">
5784                         <xsl:call-template name="isInvalid">
5785                                 <xsl:with-param name="type">lccn</xsl:with-param>
5786                         </xsl:call-template>
5787                         <identifier type="lccn">
5788                                 <xsl:value-of select="normalize-space(marc:subfield[@code='a'])"/>
5789                         </identifier>
5790                 </xsl:for-each>
5791                 <xsl:for-each select="marc:datafield[@tag='028']">
5792                         <identifier>
5793                                 <xsl:attribute name="type">
5794                                         <xsl:choose>
5795                                                 <xsl:when test="@ind1='0'">issue number</xsl:when>
5796                                                 <xsl:when test="@ind1='1'">matrix number</xsl:when>
5797                                                 <xsl:when test="@ind1='2'">music plate</xsl:when>
5798                                                 <xsl:when test="@ind1='3'">music publisher</xsl:when>
5799                                                 <xsl:when test="@ind1='4'">videorecording identifier</xsl:when>
5800                                         </xsl:choose>
5801                                 </xsl:attribute>
5802                                 <!--<xsl:call-template name="isInvalid"/>-->
5803                                 <!-- no $z in 028 -->
5804                                 <xsl:call-template name="subfieldSelect">
5805                                         <xsl:with-param name="codes">
5806                                                 <xsl:choose>
5807                                                         <xsl:when test="@ind1='0'">ba</xsl:when>
5808                                                         <xsl:otherwise>ab</xsl:otherwise>
5809                                                 </xsl:choose>
5810                                         </xsl:with-param>
5811                                 </xsl:call-template>
5812                         </identifier>
5813                 </xsl:for-each>
5814                 <xsl:for-each select="marc:datafield[@tag='037']">
5815                         <identifier type="stock number">
5816                                 <!--<xsl:call-template name="isInvalid"/>-->
5817                                 <!-- no $z in 037 -->
5818                                 <xsl:call-template name="subfieldSelect">
5819                                         <xsl:with-param name="codes">ab</xsl:with-param>
5820                                 </xsl:call-template>
5821                         </identifier>
5822                 </xsl:for-each>
5823                 <xsl:for-each select="marc:datafield[@tag='856'][marc:subfield[@code='u']]">
5824                         <identifier>
5825                                 <xsl:attribute name="type">
5826                                         <xsl:choose>
5827                                                 <xsl:when
5828                                                         test="starts-with(marc:subfield[@code='u'],'urn:doi') or starts-with(marc:subfield[@code='u'],'doi')"
5829                                                         >doi</xsl:when>
5830                                                 <xsl:when
5831                                                         test="starts-with(marc:subfield[@code='u'],'urn:hdl') or starts-with(marc:subfield[@code='u'],'hdl') or starts-with(marc:subfield[@code='u'],'http://hdl.loc.gov')"
5832                                                         >hdl</xsl:when>
5833                                                 <xsl:otherwise>uri</xsl:otherwise>
5834                                         </xsl:choose>
5835                                 </xsl:attribute>
5836                                 <xsl:choose>
5837                                         <xsl:when
5838                                                 test="starts-with(marc:subfield[@code='u'],'urn:hdl') or starts-with(marc:subfield[@code='u'],'hdl') or starts-with(marc:subfield[@code='u'],'http://hdl.loc.gov') ">
5839                                                 <xsl:value-of
5840                                                         select="concat('hdl:',substring-after(marc:subfield[@code='u'],'http://hdl.loc.gov/'))"
5841                                                 />
5842                                         </xsl:when>
5843                                         <xsl:otherwise>
5844                                                 <xsl:value-of select="marc:subfield[@code='u']"/>
5845                                         </xsl:otherwise>
5846                                 </xsl:choose>
5847                         </identifier>
5848                         <xsl:if
5849                                 test="starts-with(marc:subfield[@code='u'],'urn:hdl') or starts-with(marc:subfield[@code='u'],'hdl')">
5850                                 <identifier type="hdl">
5851                                         <xsl:if test="marc:subfield[@code='y' or @code='3' or @code='z']">
5852                                                 <xsl:attribute name="displayLabel">
5853                                                         <xsl:call-template name="subfieldSelect">
5854                                                                 <xsl:with-param name="codes">y3z</xsl:with-param>
5855                                                         </xsl:call-template>
5856                                                 </xsl:attribute>
5857                                         </xsl:if>
5858                                         <xsl:value-of
5859                                                 select="concat('hdl:',substring-after(marc:subfield[@code='u'],'http://hdl.loc.gov/'))"
5860                                         />
5861                                 </identifier>
5862                         </xsl:if>
5863                 </xsl:for-each>
5864                 <xsl:for-each select="marc:datafield[@tag=024][@ind1=1]">
5865                         <identifier type="upc">
5866                                 <xsl:call-template name="isInvalid"/>
5867                                 <xsl:value-of select="marc:subfield[@code='a']"/>
5868                         </identifier>
5869                 </xsl:for-each>
5870
5871                 <!-- 1/04 fix added $y -->
5872
5873                 <!-- 1.21  tmee-->
5874                 <xsl:for-each select="marc:datafield[@tag=856][@ind2=1][marc:subfield[@code='u']]">
5875                         <relatedItem type="otherVersion">
5876                                 <location>
5877                                         <url>
5878                                                 <xsl:if test="marc:subfield[@code='y' or @code='3']">
5879                                                         <xsl:attribute name="displayLabel">
5880                                                                 <xsl:call-template name="subfieldSelect">
5881                                                                         <xsl:with-param name="codes">y3</xsl:with-param>
5882                                                                 </xsl:call-template>
5883                                                         </xsl:attribute>
5884                                                 </xsl:if>
5885                                                 <xsl:if test="marc:subfield[@code='z' ]">
5886                                                         <xsl:attribute name="note">
5887                                                                 <xsl:call-template name="subfieldSelect">
5888                                                                         <xsl:with-param name="codes">z</xsl:with-param>
5889                                                                 </xsl:call-template>
5890                                                         </xsl:attribute>
5891                                                 </xsl:if>
5892                                                 <xsl:value-of select="marc:subfield[@code='u']"/>
5893                                         </url>
5894                                 </location>
5895                         </relatedItem>
5896                 </xsl:for-each>
5897                 <xsl:for-each select="marc:datafield[@tag=856][@ind2=2][marc:subfield[@code='u']]">
5898                         <relatedItem>
5899                                 <location>
5900                                         <url>
5901                                                 <xsl:if test="marc:subfield[@code='y' or @code='3']">
5902                                                         <xsl:attribute name="displayLabel">
5903                                                                 <xsl:call-template name="subfieldSelect">
5904                                                                         <xsl:with-param name="codes">y3</xsl:with-param>
5905                                                                 </xsl:call-template>
5906                                                         </xsl:attribute>
5907                                                 </xsl:if>
5908                                                 <xsl:if test="marc:subfield[@code='z' ]">
5909                                                         <xsl:attribute name="note">
5910                                                                 <xsl:call-template name="subfieldSelect">
5911                                                                         <xsl:with-param name="codes">z</xsl:with-param>
5912                                                                 </xsl:call-template>
5913                                                         </xsl:attribute>
5914                                                 </xsl:if>
5915                                                 <xsl:value-of select="marc:subfield[@code='u']"/>
5916                                         </url>
5917                                 </location>
5918                         </relatedItem>
5919                 </xsl:for-each>
5920
5921                 <!-- 3.2 change tmee 856z  -->
5922
5923                 <!-- 1.24  tmee  -->
5924                 <xsl:for-each select="marc:datafield[@tag=852]">
5925                         <location>
5926                                 <xsl:if test="marc:subfield[@code='a' or @code='b' or @code='e']">
5927                                         <physicalLocation>
5928                                                 <xsl:call-template name="subfieldSelect">
5929                                                         <xsl:with-param name="codes">abe</xsl:with-param>
5930                                                 </xsl:call-template>
5931                                         </physicalLocation>
5932                                 </xsl:if>
5933
5934                                 <xsl:if test="marc:subfield[@code='u']">
5935                                         <physicalLocation>
5936                                                 <xsl:call-template name="uri"/>
5937                                                 <xsl:call-template name="subfieldSelect">
5938                                                         <xsl:with-param name="codes">u</xsl:with-param>
5939                                                 </xsl:call-template>
5940                                         </physicalLocation>
5941                                 </xsl:if>
5942
5943                                 <xsl:if
5944                                         test="marc:subfield[@code='h' or @code='i' or @code='j' or @code='k' or @code='l' or @code='m' or @code='t']">
5945                                         <shelfLocation>
5946                                                 <xsl:call-template name="subfieldSelect">
5947                                                         <xsl:with-param name="codes">hijklmt</xsl:with-param>
5948                                                 </xsl:call-template>
5949                                         </shelfLocation>
5950                                 </xsl:if>
5951                         </location>
5952                 </xsl:for-each>
5953
5954                 <xsl:for-each select="marc:datafield[@tag=506]">
5955                         <accessCondition type="restrictionOnAccess">
5956                                 <xsl:call-template name="subfieldSelect">
5957                                         <xsl:with-param name="codes">abcd35</xsl:with-param>
5958                                 </xsl:call-template>
5959                         </accessCondition>
5960                 </xsl:for-each>
5961                 <xsl:for-each select="marc:datafield[@tag=540]">
5962                         <accessCondition type="useAndReproduction">
5963                                 <xsl:call-template name="subfieldSelect">
5964                                         <xsl:with-param name="codes">abcde35</xsl:with-param>
5965                                 </xsl:call-template>
5966                         </accessCondition>
5967                 </xsl:for-each>
5968
5969                 <recordInfo>
5970                         <!-- 1.25  tmee-->
5971
5972
5973                         <xsl:for-each select="marc:leader[substring($leader,19,1)='a']">
5974                                 <descriptionStandard>aacr2</descriptionStandard>
5975                         </xsl:for-each>
5976
5977                         <xsl:for-each select="marc:datafield[@tag=040]">
5978                                 <xsl:if test="marc:subfield[@code='e']">
5979                                         <descriptionStandard>
5980                                                 <xsl:value-of select="marc:subfield[@code='e']"/>
5981                                         </descriptionStandard>
5982                                 </xsl:if>
5983                                 <recordContentSource authority="marcorg">
5984                                         <xsl:value-of select="marc:subfield[@code='a']"/>
5985                                 </recordContentSource>
5986                         </xsl:for-each>
5987                         <xsl:for-each select="marc:controlfield[@tag=008]">
5988                                 <recordCreationDate encoding="marc">
5989                                         <xsl:value-of select="substring(.,1,6)"/>
5990                                 </recordCreationDate>
5991                         </xsl:for-each>
5992
5993                         <xsl:for-each select="marc:controlfield[@tag=005]">
5994                                 <recordChangeDate encoding="iso8601">
5995                                         <xsl:value-of select="."/>
5996                                 </recordChangeDate>
5997                         </xsl:for-each>
5998                         <xsl:for-each select="marc:controlfield[@tag=001]">
5999                                 <recordIdentifier>
6000                                         <xsl:if test="../marc:controlfield[@tag=003]">
6001                                                 <xsl:attribute name="source">
6002                                                         <xsl:value-of select="../marc:controlfield[@tag=003]"/>
6003                                                 </xsl:attribute>
6004                                         </xsl:if>
6005                                         <xsl:value-of select="."/>
6006                                 </recordIdentifier>
6007                         </xsl:for-each>
6008                         <xsl:for-each select="marc:datafield[@tag=040]/marc:subfield[@code='b']">
6009                                 <languageOfCataloging>
6010                                         <languageTerm authority="iso639-2b" type="code">
6011                                                 <xsl:value-of select="."/>
6012                                         </languageTerm>
6013                                 </languageOfCataloging>
6014                         </xsl:for-each>
6015                 </recordInfo>
6016         </xsl:template>
6017         <xsl:template name="displayForm">
6018                 <xsl:for-each select="marc:subfield[@code='c']">
6019                         <displayForm>
6020                                 <xsl:value-of select="."/>
6021                         </displayForm>
6022                 </xsl:for-each>
6023         </xsl:template>
6024         <xsl:template name="affiliation">
6025                 <xsl:for-each select="marc:subfield[@code='u']">
6026                         <affiliation>
6027                                 <xsl:value-of select="."/>
6028                         </affiliation>
6029                 </xsl:for-each>
6030         </xsl:template>
6031         <xsl:template name="uri">
6032                 <xsl:for-each select="marc:subfield[@code='u']">
6033                         <xsl:attribute name="xlink:href">
6034                                 <xsl:value-of select="."/>
6035                         </xsl:attribute>
6036                 </xsl:for-each>
6037                 <xsl:for-each select="marc:subfield[@code='0']">
6038                         <xsl:choose>
6039                                 <xsl:when test="contains(text(), ')')">
6040                                         <xsl:attribute name="xlink:href">
6041                                                 <xsl:value-of select="substring-after(text(), ')')"></xsl:value-of>
6042                                         </xsl:attribute>
6043                                 </xsl:when>
6044                                 <xsl:otherwise>
6045                                         <xsl:attribute name="xlink:href">
6046                                                 <xsl:value-of select="."></xsl:value-of>
6047                                         </xsl:attribute>
6048                                 </xsl:otherwise>
6049                         </xsl:choose>
6050                 </xsl:for-each>
6051         </xsl:template>
6052         <xsl:template name="role">
6053                 <xsl:for-each select="marc:subfield[@code='e']">
6054                         <role>
6055                                 <roleTerm type="text">
6056                                         <xsl:value-of select="."/>
6057                                 </roleTerm>
6058                         </role>
6059                 </xsl:for-each>
6060                 <xsl:for-each select="marc:subfield[@code='4']">
6061                         <role>
6062                                 <roleTerm authority="marcrelator" type="code">
6063                                         <xsl:value-of select="."/>
6064                                 </roleTerm>
6065                         </role>
6066                 </xsl:for-each>
6067         </xsl:template>
6068         <xsl:template name="part">
6069                 <xsl:variable name="partNumber">
6070                         <xsl:call-template name="specialSubfieldSelect">
6071                                 <xsl:with-param name="axis">n</xsl:with-param>
6072                                 <xsl:with-param name="anyCodes">n</xsl:with-param>
6073                                 <xsl:with-param name="afterCodes">fgkdlmor</xsl:with-param>
6074                         </xsl:call-template>
6075                 </xsl:variable>
6076                 <xsl:variable name="partName">
6077                         <xsl:call-template name="specialSubfieldSelect">
6078                                 <xsl:with-param name="axis">p</xsl:with-param>
6079                                 <xsl:with-param name="anyCodes">p</xsl:with-param>
6080                                 <xsl:with-param name="afterCodes">fgkdlmor</xsl:with-param>
6081                         </xsl:call-template>
6082                 </xsl:variable>
6083                 <xsl:if test="string-length(normalize-space($partNumber))">
6084                         <partNumber>
6085                                 <xsl:call-template name="chopPunctuation">
6086                                         <xsl:with-param name="chopString" select="$partNumber"/>
6087                                 </xsl:call-template>
6088                         </partNumber>
6089                 </xsl:if>
6090                 <xsl:if test="string-length(normalize-space($partName))">
6091                         <partName>
6092                                 <xsl:call-template name="chopPunctuation">
6093                                         <xsl:with-param name="chopString" select="$partName"/>
6094                                 </xsl:call-template>
6095                         </partName>
6096                 </xsl:if>
6097         </xsl:template>
6098         <xsl:template name="relatedPart">
6099                 <xsl:if test="@tag=773">
6100                         <xsl:for-each select="marc:subfield[@code='g']">
6101                                 <part>
6102                                         <text>
6103                                                 <xsl:value-of select="."/>
6104                                         </text>
6105                                 </part>
6106                         </xsl:for-each>
6107                         <xsl:for-each select="marc:subfield[@code='q']">
6108                                 <part>
6109                                         <xsl:call-template name="parsePart"/>
6110                                 </part>
6111                         </xsl:for-each>
6112                 </xsl:if>
6113         </xsl:template>
6114         <xsl:template name="relatedPartNumName">
6115                 <xsl:variable name="partNumber">
6116                         <xsl:call-template name="specialSubfieldSelect">
6117                                 <xsl:with-param name="axis">g</xsl:with-param>
6118                                 <xsl:with-param name="anyCodes">g</xsl:with-param>
6119                                 <xsl:with-param name="afterCodes">pst</xsl:with-param>
6120                         </xsl:call-template>
6121                 </xsl:variable>
6122                 <xsl:variable name="partName">
6123                         <xsl:call-template name="specialSubfieldSelect">
6124                                 <xsl:with-param name="axis">p</xsl:with-param>
6125                                 <xsl:with-param name="anyCodes">p</xsl:with-param>
6126                                 <xsl:with-param name="afterCodes">fgkdlmor</xsl:with-param>
6127                         </xsl:call-template>
6128                 </xsl:variable>
6129                 <xsl:if test="string-length(normalize-space($partNumber))">
6130                         <partNumber>
6131                                 <xsl:value-of select="$partNumber"/>
6132                         </partNumber>
6133                 </xsl:if>
6134                 <xsl:if test="string-length(normalize-space($partName))">
6135                         <partName>
6136                                 <xsl:value-of select="$partName"/>
6137                         </partName>
6138                 </xsl:if>
6139         </xsl:template>
6140         <xsl:template name="relatedName">
6141                 <xsl:for-each select="marc:subfield[@code='a']">
6142                         <name>
6143                                 <namePart>
6144                                         <xsl:value-of select="."/>
6145                                 </namePart>
6146                         </name>
6147                 </xsl:for-each>
6148         </xsl:template>
6149         <xsl:template name="relatedForm">
6150                 <xsl:for-each select="marc:subfield[@code='h']">
6151                         <physicalDescription>
6152                                 <form>
6153                                         <xsl:value-of select="."/>
6154                                 </form>
6155                         </physicalDescription>
6156                 </xsl:for-each>
6157         </xsl:template>
6158         <xsl:template name="relatedExtent">
6159                 <xsl:for-each select="marc:subfield[@code='h']">
6160                         <physicalDescription>
6161                                 <extent>
6162                                         <xsl:value-of select="."/>
6163                                 </extent>
6164                         </physicalDescription>
6165                 </xsl:for-each>
6166         </xsl:template>
6167         <xsl:template name="relatedNote">
6168                 <xsl:for-each select="marc:subfield[@code='n']">
6169                         <note>
6170                                 <xsl:value-of select="."/>
6171                         </note>
6172                 </xsl:for-each>
6173         </xsl:template>
6174         <xsl:template name="relatedSubject">
6175                 <xsl:for-each select="marc:subfield[@code='j']">
6176                         <subject>
6177                                 <temporal encoding="iso8601">
6178                                         <xsl:call-template name="chopPunctuation">
6179                                                 <xsl:with-param name="chopString" select="."/>
6180                                         </xsl:call-template>
6181                                 </temporal>
6182                         </subject>
6183                 </xsl:for-each>
6184         </xsl:template>
6185         <xsl:template name="relatedIdentifierISSN">
6186                 <xsl:for-each select="marc:subfield[@code='x']">
6187                         <identifier type="issn">
6188                                 <xsl:value-of select="."/>
6189                         </identifier>
6190                 </xsl:for-each>
6191         </xsl:template>
6192         <xsl:template name="relatedIdentifierLocal">
6193                 <xsl:for-each select="marc:subfield[@code='w']">
6194                         <identifier type="local">
6195                                 <xsl:value-of select="."/>
6196                         </identifier>
6197                 </xsl:for-each>
6198         </xsl:template>
6199         <xsl:template name="relatedIdentifier">
6200                 <xsl:for-each select="marc:subfield[@code='o']">
6201                         <identifier>
6202                                 <xsl:value-of select="."/>
6203                         </identifier>
6204                 </xsl:for-each>
6205         </xsl:template>
6206         <xsl:template name="relatedItem76X-78X">
6207                 <xsl:call-template name="displayLabel"/>
6208                 <xsl:call-template name="relatedTitle76X-78X"/>
6209                 <xsl:call-template name="relatedName"/>
6210                 <xsl:call-template name="relatedOriginInfo"/>
6211                 <xsl:call-template name="relatedLanguage"/>
6212                 <xsl:call-template name="relatedExtent"/>
6213                 <xsl:call-template name="relatedNote"/>
6214                 <xsl:call-template name="relatedSubject"/>
6215                 <xsl:call-template name="relatedIdentifier"/>
6216                 <xsl:call-template name="relatedIdentifierISSN"/>
6217                 <xsl:call-template name="relatedIdentifierLocal"/>
6218                 <xsl:call-template name="relatedPart"/>
6219         </xsl:template>
6220         <xsl:template name="subjectGeographicZ">
6221                 <geographic>
6222                         <xsl:call-template name="chopPunctuation">
6223                                 <xsl:with-param name="chopString" select="."/>
6224                         </xsl:call-template>
6225                 </geographic>
6226         </xsl:template>
6227         <xsl:template name="subjectTemporalY">
6228                 <temporal>
6229                         <xsl:call-template name="chopPunctuation">
6230                                 <xsl:with-param name="chopString" select="."/>
6231                         </xsl:call-template>
6232                 </temporal>
6233         </xsl:template>
6234         <xsl:template name="subjectTopic">
6235                 <topic>
6236                         <xsl:call-template name="chopPunctuation">
6237                                 <xsl:with-param name="chopString" select="."/>
6238                         </xsl:call-template>
6239                 </topic>
6240         </xsl:template>
6241         <!-- 3.2 change tmee 6xx $v genre -->
6242         <xsl:template name="subjectGenre">
6243                 <genre>
6244                         <xsl:call-template name="chopPunctuation">
6245                                 <xsl:with-param name="chopString" select="."/>
6246                         </xsl:call-template>
6247                 </genre>
6248         </xsl:template>
6249
6250         <xsl:template name="nameABCDN">
6251                 <xsl:for-each select="marc:subfield[@code='a']">
6252                         <namePart>
6253                                 <xsl:call-template name="chopPunctuation">
6254                                         <xsl:with-param name="chopString" select="."/>
6255                                 </xsl:call-template>
6256                         </namePart>
6257                 </xsl:for-each>
6258                 <xsl:for-each select="marc:subfield[@code='b']">
6259                         <namePart>
6260                                 <xsl:value-of select="."/>
6261                         </namePart>
6262                 </xsl:for-each>
6263                 <xsl:if
6264                         test="marc:subfield[@code='c'] or marc:subfield[@code='d'] or marc:subfield[@code='n']">
6265                         <namePart>
6266                                 <xsl:call-template name="subfieldSelect">
6267                                         <xsl:with-param name="codes">cdn</xsl:with-param>
6268                                 </xsl:call-template>
6269                         </namePart>
6270                 </xsl:if>
6271         </xsl:template>
6272         <xsl:template name="nameABCDQ">
6273                 <namePart>
6274                         <xsl:call-template name="chopPunctuation">
6275                                 <xsl:with-param name="chopString">
6276                                         <xsl:call-template name="subfieldSelect">
6277                                                 <xsl:with-param name="codes">aq</xsl:with-param>
6278                                         </xsl:call-template>
6279                                 </xsl:with-param>
6280                                 <xsl:with-param name="punctuation">
6281                                         <xsl:text>:,;/ </xsl:text>
6282                                 </xsl:with-param>
6283                         </xsl:call-template>
6284                 </namePart>
6285                 <xsl:call-template name="termsOfAddress"/>
6286                 <xsl:call-template name="nameDate"/>
6287         </xsl:template>
6288         <xsl:template name="nameACDEQ">
6289                 <namePart>
6290                         <xsl:call-template name="subfieldSelect">
6291                                 <xsl:with-param name="codes">acdeq</xsl:with-param>
6292                         </xsl:call-template>
6293                 </namePart>
6294         </xsl:template>
6295         <xsl:template name="constituentOrRelatedType">
6296                 <xsl:if test="@ind2=2">
6297                         <xsl:attribute name="type">constituent</xsl:attribute>
6298                 </xsl:if>
6299         </xsl:template>
6300         <xsl:template name="relatedTitle">
6301                 <xsl:for-each select="marc:subfield[@code='t']">
6302                         <titleInfo>
6303                                 <title>
6304                                         <xsl:call-template name="chopPunctuation">
6305                                                 <xsl:with-param name="chopString">
6306                                                         <xsl:value-of select="."/>
6307                                                 </xsl:with-param>
6308                                         </xsl:call-template>
6309                                 </title>
6310                         </titleInfo>
6311                 </xsl:for-each>
6312         </xsl:template>
6313         <xsl:template name="relatedTitle76X-78X">
6314                 <xsl:for-each select="marc:subfield[@code='t']">
6315                         <titleInfo>
6316                                 <title>
6317                                         <xsl:call-template name="chopPunctuation">
6318                                                 <xsl:with-param name="chopString">
6319                                                         <xsl:value-of select="."/>
6320                                                 </xsl:with-param>
6321                                         </xsl:call-template>
6322                                 </title>
6323                                 <xsl:if test="marc:datafield[@tag!=773]and marc:subfield[@code='g']">
6324                                         <xsl:call-template name="relatedPartNumName"/>
6325                                 </xsl:if>
6326                         </titleInfo>
6327                 </xsl:for-each>
6328                 <xsl:for-each select="marc:subfield[@code='p']">
6329                         <titleInfo type="abbreviated">
6330                                 <title>
6331                                         <xsl:call-template name="chopPunctuation">
6332                                                 <xsl:with-param name="chopString">
6333                                                         <xsl:value-of select="."/>
6334                                                 </xsl:with-param>
6335                                         </xsl:call-template>
6336                                 </title>
6337                                 <xsl:if test="marc:datafield[@tag!=773]and marc:subfield[@code='g']">
6338                                         <xsl:call-template name="relatedPartNumName"/>
6339                                 </xsl:if>
6340                         </titleInfo>
6341                 </xsl:for-each>
6342                 <xsl:for-each select="marc:subfield[@code='s']">
6343                         <titleInfo type="uniform">
6344                                 <title>
6345                                         <xsl:call-template name="chopPunctuation">
6346                                                 <xsl:with-param name="chopString">
6347                                                         <xsl:value-of select="."/>
6348                                                 </xsl:with-param>
6349                                         </xsl:call-template>
6350                                 </title>
6351                                 <xsl:if test="marc:datafield[@tag!=773]and marc:subfield[@code='g']">
6352                                         <xsl:call-template name="relatedPartNumName"/>
6353                                 </xsl:if>
6354                         </titleInfo>
6355                 </xsl:for-each>
6356         </xsl:template>
6357         <xsl:template name="relatedOriginInfo">
6358                 <xsl:if test="marc:subfield[@code='b' or @code='d'] or marc:subfield[@code='f']">
6359                         <originInfo>
6360                                 <xsl:if test="@tag=775">
6361                                         <xsl:for-each select="marc:subfield[@code='f']">
6362                                                 <place>
6363                                                         <placeTerm>
6364                                                                 <xsl:attribute name="type">code</xsl:attribute>
6365                                                                 <xsl:attribute name="authority">marcgac</xsl:attribute>
6366                                                                 <xsl:value-of select="."/>
6367                                                         </placeTerm>
6368                                                 </place>
6369                                         </xsl:for-each>
6370                                 </xsl:if>
6371                                 <xsl:for-each select="marc:subfield[@code='d']">
6372                                         <publisher>
6373                                                 <xsl:value-of select="."/>
6374                                         </publisher>
6375                                 </xsl:for-each>
6376                                 <xsl:for-each select="marc:subfield[@code='b']">
6377                                         <edition>
6378                                                 <xsl:value-of select="."/>
6379                                         </edition>
6380                                 </xsl:for-each>
6381                         </originInfo>
6382                 </xsl:if>
6383         </xsl:template>
6384         <xsl:template name="relatedLanguage">
6385                 <xsl:for-each select="marc:subfield[@code='e']">
6386                         <xsl:call-template name="getLanguage">
6387                                 <xsl:with-param name="langString">
6388                                         <xsl:value-of select="."/>
6389                                 </xsl:with-param>
6390                         </xsl:call-template>
6391                 </xsl:for-each>
6392         </xsl:template>
6393         <xsl:template name="nameDate">
6394                 <xsl:for-each select="marc:subfield[@code='d']">
6395                         <namePart type="date">
6396                                 <xsl:call-template name="chopPunctuation">
6397                                         <xsl:with-param name="chopString" select="."/>
6398                                 </xsl:call-template>
6399                         </namePart>
6400                 </xsl:for-each>
6401         </xsl:template>
6402         <xsl:template name="subjectAuthority">
6403                 <xsl:if test="@ind2!=4">
6404                         <xsl:if test="@ind2!=' '">
6405                                 <xsl:if test="@ind2!=8">
6406                                         <xsl:if test="@ind2!=9">
6407                                                 <xsl:attribute name="authority">
6408                                                         <xsl:choose>
6409                                                                 <xsl:when test="@ind2=0">lcsh</xsl:when>
6410                                                                 <xsl:when test="@ind2=1">lcshac</xsl:when>
6411                                                                 <xsl:when test="@ind2=2">mesh</xsl:when>
6412                                                                 <!-- 1/04 fix -->
6413                                                                 <xsl:when test="@ind2=3">nal</xsl:when>
6414                                                                 <xsl:when test="@ind2=5">csh</xsl:when>
6415                                                                 <xsl:when test="@ind2=6">rvm</xsl:when>
6416                                                                 <xsl:when test="@ind2=7">
6417                                                                         <xsl:value-of select="marc:subfield[@code='2']"/>
6418                                                                 </xsl:when>
6419                                                         </xsl:choose>
6420                                                 </xsl:attribute>
6421                                         </xsl:if>
6422                                 </xsl:if>
6423                         </xsl:if>
6424                 </xsl:if>
6425         </xsl:template>
6426         <xsl:template name="subjectAnyOrder">
6427                 <xsl:for-each select="marc:subfield[@code='v' or @code='x' or @code='y' or @code='z']">
6428                         <xsl:choose>
6429                                 <xsl:when test="@code='v'">
6430                                         <xsl:call-template name="subjectGenre"/>
6431                                 </xsl:when>
6432                                 <xsl:when test="@code='x'">
6433                                         <xsl:call-template name="subjectTopic"/>
6434                                 </xsl:when>
6435                                 <xsl:when test="@code='y'">
6436                                         <xsl:call-template name="subjectTemporalY"/>
6437                                 </xsl:when>
6438                                 <xsl:when test="@code='z'">
6439                                         <xsl:call-template name="subjectGeographicZ"/>
6440                                 </xsl:when>
6441                         </xsl:choose>
6442                 </xsl:for-each>
6443         </xsl:template>
6444         <xsl:template name="specialSubfieldSelect">
6445                 <xsl:param name="anyCodes"/>
6446                 <xsl:param name="axis"/>
6447                 <xsl:param name="beforeCodes"/>
6448                 <xsl:param name="afterCodes"/>
6449                 <xsl:variable name="str">
6450                         <xsl:for-each select="marc:subfield">
6451                                 <xsl:if
6452                                         test="contains($anyCodes, @code)      or (contains($beforeCodes,@code) and following-sibling::marc:subfield[@code=$axis])      or (contains($afterCodes,@code) and preceding-sibling::marc:subfield[@code=$axis])">
6453                                         <xsl:value-of select="text()"/>
6454                                         <xsl:text> </xsl:text>
6455                                 </xsl:if>
6456                         </xsl:for-each>
6457                 </xsl:variable>
6458                 <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
6459         </xsl:template>
6460
6461         <!-- 3.2 change tmee 6xx $v genre -->
6462         <xsl:template match="marc:datafield[@tag=600]">
6463                 <subject>
6464                         <xsl:call-template name="subjectAuthority"/>
6465                         <name type="personal">
6466                                 <xsl:call-template name="termsOfAddress"/>
6467                                 <namePart>
6468                                         <xsl:call-template name="chopPunctuation">
6469                                                 <xsl:with-param name="chopString">
6470                                                         <xsl:call-template name="subfieldSelect">
6471                                                                 <xsl:with-param name="codes">aq</xsl:with-param>
6472                                                         </xsl:call-template>
6473                                                 </xsl:with-param>
6474                                         </xsl:call-template>
6475                                 </namePart>
6476                                 <xsl:call-template name="nameDate"/>
6477                                 <xsl:call-template name="affiliation"/>
6478                                 <xsl:call-template name="role"/>
6479                         </name>
6480                         <xsl:call-template name="subjectAnyOrder"/>
6481                 </subject>
6482         </xsl:template>
6483         <xsl:template match="marc:datafield[@tag=610]">
6484                 <subject>
6485                         <xsl:call-template name="subjectAuthority"/>
6486                         <name type="corporate">
6487                                 <xsl:for-each select="marc:subfield[@code='a']">
6488                                         <namePart>
6489                                                 <xsl:value-of select="."/>
6490                                         </namePart>
6491                                 </xsl:for-each>
6492                                 <xsl:for-each select="marc:subfield[@code='b']">
6493                                         <namePart>
6494                                                 <xsl:value-of select="."/>
6495                                         </namePart>
6496                                 </xsl:for-each>
6497                                 <xsl:if test="marc:subfield[@code='c' or @code='d' or @code='n' or @code='p']">
6498                                         <namePart>
6499                                                 <xsl:call-template name="subfieldSelect">
6500                                                         <xsl:with-param name="codes">cdnp</xsl:with-param>
6501                                                 </xsl:call-template>
6502                                         </namePart>
6503                                 </xsl:if>
6504                                 <xsl:call-template name="role"/>
6505                         </name>
6506                         <xsl:call-template name="subjectAnyOrder"/>
6507                 </subject>
6508         </xsl:template>
6509         <xsl:template match="marc:datafield[@tag=611]">
6510                 <subject>
6511                         <xsl:call-template name="subjectAuthority"/>
6512                         <name type="conference">
6513                                 <namePart>
6514                                         <xsl:call-template name="subfieldSelect">
6515                                                 <xsl:with-param name="codes">abcdeqnp</xsl:with-param>
6516                                         </xsl:call-template>
6517                                 </namePart>
6518                                 <xsl:for-each select="marc:subfield[@code='4']">
6519                                         <role>
6520                                                 <roleTerm authority="marcrelator" type="code">
6521                                                         <xsl:value-of select="."/>
6522                                                 </roleTerm>
6523                                         </role>
6524                                 </xsl:for-each>
6525                         </name>
6526                         <xsl:call-template name="subjectAnyOrder"/>
6527                 </subject>
6528         </xsl:template>
6529         <xsl:template match="marc:datafield[@tag=630]">
6530                 <subject>
6531                         <xsl:call-template name="subjectAuthority"/>
6532                         <titleInfo>
6533                                 <title>
6534                                         <xsl:call-template name="chopPunctuation">
6535                                                 <xsl:with-param name="chopString">
6536                                                         <xsl:call-template name="subfieldSelect">
6537                                                                 <xsl:with-param name="codes">adfhklor</xsl:with-param>
6538                                                         </xsl:call-template>
6539                                                 </xsl:with-param>
6540                                         </xsl:call-template>
6541                                 </title>
6542                                 <xsl:call-template name="part"/>
6543                         </titleInfo>
6544                         <xsl:call-template name="subjectAnyOrder"/>
6545                 </subject>
6546         </xsl:template>
6547         <!-- 1.27 648 tmee-->
6548         <xsl:template match="marc:datafield[@tag=648]">
6549                 <subject>
6550                         <xsl:if test="marc:subfield[@code=2]">
6551                                 <xsl:attribute name="authority">
6552                                         <xsl:value-of select="marc:subfield[@code=2]"/>
6553                                 </xsl:attribute>
6554                         </xsl:if>
6555                         <xsl:call-template name="uri"/>
6556
6557                         <xsl:call-template name="subjectAuthority"/>
6558                         <temporal>
6559                                 <xsl:call-template name="chopPunctuation">
6560                                         <xsl:with-param name="chopString">
6561                                                 <xsl:call-template name="subfieldSelect">
6562                                                         <xsl:with-param name="codes">abcd</xsl:with-param>
6563                                                 </xsl:call-template>
6564                                         </xsl:with-param>
6565                                 </xsl:call-template>
6566                         </temporal>
6567                         <xsl:call-template name="subjectAnyOrder"/>
6568
6569                 </subject>
6570         </xsl:template>
6571         <xsl:template match="marc:datafield[@tag=650]">
6572                 <subject>
6573                         <xsl:call-template name="subjectAuthority"/>
6574                         <topic>
6575                                 <xsl:call-template name="chopPunctuation">
6576                                         <xsl:with-param name="chopString">
6577                                                 <xsl:call-template name="subfieldSelect">
6578                                                         <xsl:with-param name="codes">abcd</xsl:with-param>
6579                                                 </xsl:call-template>
6580                                         </xsl:with-param>
6581                                 </xsl:call-template>
6582                         </topic>
6583                         <xsl:call-template name="subjectAnyOrder"/>
6584                 </subject>
6585         </xsl:template>
6586         <xsl:template match="marc:datafield[@tag=651]">
6587                 <subject>
6588                         <xsl:call-template name="subjectAuthority"/>
6589                         <xsl:for-each select="marc:subfield[@code='a']">
6590                                 <geographic>
6591                                         <xsl:call-template name="chopPunctuation">
6592                                                 <xsl:with-param name="chopString" select="."/>
6593                                         </xsl:call-template>
6594                                 </geographic>
6595                         </xsl:for-each>
6596                         <xsl:call-template name="subjectAnyOrder"/>
6597                 </subject>
6598         </xsl:template>
6599         <xsl:template match="marc:datafield[@tag=653]">
6600                 <subject>
6601                         <xsl:for-each select="marc:subfield[@code='a']">
6602                                 <topic>
6603                                         <xsl:value-of select="."/>
6604                                 </topic>
6605                         </xsl:for-each>
6606                 </subject>
6607         </xsl:template>
6608         <xsl:template match="marc:datafield[@tag=656]">
6609                 <subject>
6610                         <xsl:if test="marc:subfield[@code=2]">
6611                                 <xsl:attribute name="authority">
6612                                         <xsl:value-of select="marc:subfield[@code=2]"/>
6613                                 </xsl:attribute>
6614                         </xsl:if>
6615                         <occupation>
6616                                 <xsl:call-template name="chopPunctuation">
6617                                         <xsl:with-param name="chopString">
6618                                                 <xsl:value-of select="marc:subfield[@code='a']"/>
6619                                         </xsl:with-param>
6620                                 </xsl:call-template>
6621                         </occupation>
6622                 </subject>
6623         </xsl:template>
6624         <xsl:template name="termsOfAddress">
6625                 <xsl:if test="marc:subfield[@code='b' or @code='c']">
6626                         <namePart type="termsOfAddress">
6627                                 <xsl:call-template name="chopPunctuation">
6628                                         <xsl:with-param name="chopString">
6629                                                 <xsl:call-template name="subfieldSelect">
6630                                                         <xsl:with-param name="codes">bc</xsl:with-param>
6631                                                 </xsl:call-template>
6632                                         </xsl:with-param>
6633                                 </xsl:call-template>
6634                         </namePart>
6635                 </xsl:if>
6636         </xsl:template>
6637         <xsl:template name="displayLabel">
6638                 <xsl:if test="marc:subfield[@code='i']">
6639                         <xsl:attribute name="displayLabel">
6640                                 <xsl:value-of select="marc:subfield[@code='i']"/>
6641                         </xsl:attribute>
6642                 </xsl:if>
6643                 <xsl:if test="marc:subfield[@code='3']">
6644                         <xsl:attribute name="displayLabel">
6645                                 <xsl:value-of select="marc:subfield[@code='3']"/>
6646                         </xsl:attribute>
6647                 </xsl:if>
6648         </xsl:template>
6649         <xsl:template name="isInvalid">
6650                 <xsl:param name="type"/>
6651                 <xsl:if
6652                         test="marc:subfield[@code='z'] or marc:subfield[@code='y']  or marc:subfield[@code='m']">
6653                         <identifier>
6654                                 <xsl:attribute name="type">
6655                                         <xsl:value-of select="$type"/>
6656                                 </xsl:attribute>
6657                                 <xsl:attribute name="invalid">
6658                                         <xsl:text>yes</xsl:text>
6659                                 </xsl:attribute>
6660                                 <xsl:if test="marc:subfield[@code='z']">
6661                                         <xsl:value-of select="marc:subfield[@code='z']"/>
6662                                 </xsl:if>
6663                                 <xsl:if test="marc:subfield[@code='y']">
6664                                         <xsl:value-of select="marc:subfield[@code='y']"/>
6665                                 </xsl:if>
6666                                 <xsl:if test="marc:subfield[@code='m']">
6667                                         <xsl:value-of select="marc:subfield[@code='m']"/>
6668                                 </xsl:if>
6669                         </identifier>
6670                 </xsl:if>
6671         </xsl:template>
6672         <xsl:template name="subtitle">
6673                 <xsl:if test="marc:subfield[@code='b']">
6674                         <subTitle>
6675                                 <xsl:call-template name="chopPunctuation">
6676                                         <xsl:with-param name="chopString">
6677                                                 <xsl:value-of select="marc:subfield[@code='b']"/>
6678                                                 <!--<xsl:call-template name="subfieldSelect">
6679                                                         <xsl:with-param name="codes">b</xsl:with-param>                                                                 
6680                                                 </xsl:call-template>-->
6681                                         </xsl:with-param>
6682                                 </xsl:call-template>
6683                         </subTitle>
6684                 </xsl:if>
6685         </xsl:template>
6686         <xsl:template name="script">
6687                 <xsl:param name="scriptCode"/>
6688                 <xsl:attribute name="script">
6689                         <xsl:choose>
6690                                 <xsl:when test="$scriptCode='(3'">Arabic</xsl:when>
6691                                 <xsl:when test="$scriptCode='(B'">Latin</xsl:when>
6692                                 <xsl:when test="$scriptCode='$1'">Chinese, Japanese, Korean</xsl:when>
6693                                 <xsl:when test="$scriptCode='(N'">Cyrillic</xsl:when>
6694                                 <xsl:when test="$scriptCode='(2'">Hebrew</xsl:when>
6695                                 <xsl:when test="$scriptCode='(S'">Greek</xsl:when>
6696                         </xsl:choose>
6697                 </xsl:attribute>
6698         </xsl:template>
6699         <xsl:template name="parsePart">
6700                 <!-- assumes 773$q= 1:2:3<4
6701                      with up to 3 levels and one optional start page
6702                 -->
6703                 <xsl:variable name="level1">
6704                         <xsl:choose>
6705                                 <xsl:when test="contains(text(),':')">
6706                                         <!-- 1:2 -->
6707                                         <xsl:value-of select="substring-before(text(),':')"/>
6708                                 </xsl:when>
6709                                 <xsl:when test="not(contains(text(),':'))">
6710                                         <!-- 1 or 1<3 -->
6711                                         <xsl:if test="contains(text(),'&lt;')">
6712                                                 <!-- 1<3 -->
6713                                                 <xsl:value-of select="substring-before(text(),'&lt;')"/>
6714                                         </xsl:if>
6715                                         <xsl:if test="not(contains(text(),'&lt;'))">
6716                                                 <!-- 1 -->
6717                                                 <xsl:value-of select="text()"/>
6718                                         </xsl:if>
6719                                 </xsl:when>
6720                         </xsl:choose>
6721                 </xsl:variable>
6722                 <xsl:variable name="sici2">
6723                         <xsl:choose>
6724                                 <xsl:when test="starts-with(substring-after(text(),$level1),':')">
6725                                         <xsl:value-of select="substring(substring-after(text(),$level1),2)"/>
6726                                 </xsl:when>
6727                                 <xsl:otherwise>
6728                                         <xsl:value-of select="substring-after(text(),$level1)"/>
6729                                 </xsl:otherwise>
6730                         </xsl:choose>
6731                 </xsl:variable>
6732                 <xsl:variable name="level2">
6733                         <xsl:choose>
6734                                 <xsl:when test="contains($sici2,':')">
6735                                         <!--  2:3<4  -->
6736                                         <xsl:value-of select="substring-before($sici2,':')"/>
6737                                 </xsl:when>
6738                                 <xsl:when test="contains($sici2,'&lt;')">
6739                                         <!-- 1: 2<4 -->
6740                                         <xsl:value-of select="substring-before($sici2,'&lt;')"/>
6741                                 </xsl:when>
6742                                 <xsl:otherwise>
6743                                         <xsl:value-of select="$sici2"/>
6744                                         <!-- 1:2 -->
6745                                 </xsl:otherwise>
6746                         </xsl:choose>
6747                 </xsl:variable>
6748                 <xsl:variable name="sici3">
6749                         <xsl:choose>
6750                                 <xsl:when test="starts-with(substring-after($sici2,$level2),':')">
6751                                         <xsl:value-of select="substring(substring-after($sici2,$level2),2)"/>
6752                                 </xsl:when>
6753                                 <xsl:otherwise>
6754                                         <xsl:value-of select="substring-after($sici2,$level2)"/>
6755                                 </xsl:otherwise>
6756                         </xsl:choose>
6757                 </xsl:variable>
6758                 <xsl:variable name="level3">
6759                         <xsl:choose>
6760                                 <xsl:when test="contains($sici3,'&lt;')">
6761                                         <!-- 2<4 -->
6762                                         <xsl:value-of select="substring-before($sici3,'&lt;')"/>
6763                                 </xsl:when>
6764                                 <xsl:otherwise>
6765                                         <xsl:value-of select="$sici3"/>
6766                                         <!-- 3 -->
6767                                 </xsl:otherwise>
6768                         </xsl:choose>
6769                 </xsl:variable>
6770                 <xsl:variable name="page">
6771                         <xsl:if test="contains(text(),'&lt;')">
6772                                 <xsl:value-of select="substring-after(text(),'&lt;')"/>
6773                         </xsl:if>
6774                 </xsl:variable>
6775                 <xsl:if test="$level1">
6776                         <detail level="1">
6777                                 <number>
6778                                         <xsl:value-of select="$level1"/>
6779                                 </number>
6780                         </detail>
6781                 </xsl:if>
6782                 <xsl:if test="$level2">
6783                         <detail level="2">
6784                                 <number>
6785                                         <xsl:value-of select="$level2"/>
6786                                 </number>
6787                         </detail>
6788                 </xsl:if>
6789                 <xsl:if test="$level3">
6790                         <detail level="3">
6791                                 <number>
6792                                         <xsl:value-of select="$level3"/>
6793                                 </number>
6794                         </detail>
6795                 </xsl:if>
6796                 <xsl:if test="$page">
6797                         <extent unit="page">
6798                                 <start>
6799                                         <xsl:value-of select="$page"/>
6800                                 </start>
6801                         </extent>
6802                 </xsl:if>
6803         </xsl:template>
6804         <xsl:template name="getLanguage">
6805                 <xsl:param name="langString"/>
6806                 <xsl:param name="controlField008-35-37"/>
6807                 <xsl:variable name="length" select="string-length($langString)"/>
6808                 <xsl:choose>
6809                         <xsl:when test="$length=0"/>
6810                         <xsl:when test="$controlField008-35-37=substring($langString,1,3)">
6811                                 <xsl:call-template name="getLanguage">
6812                                         <xsl:with-param name="langString" select="substring($langString,4,$length)"/>
6813                                         <xsl:with-param name="controlField008-35-37" select="$controlField008-35-37"/>
6814                                 </xsl:call-template>
6815                         </xsl:when>
6816                         <xsl:otherwise>
6817                                 <language>
6818                                         <languageTerm authority="iso639-2b" type="code">
6819                                                 <xsl:value-of select="substring($langString,1,3)"/>
6820                                         </languageTerm>
6821                                 </language>
6822                                 <xsl:call-template name="getLanguage">
6823                                         <xsl:with-param name="langString" select="substring($langString,4,$length)"/>
6824                                         <xsl:with-param name="controlField008-35-37" select="$controlField008-35-37"/>
6825                                 </xsl:call-template>
6826                         </xsl:otherwise>
6827                 </xsl:choose>
6828         </xsl:template>
6829         <xsl:template name="isoLanguage">
6830                 <xsl:param name="currentLanguage"/>
6831                 <xsl:param name="usedLanguages"/>
6832                 <xsl:param name="remainingLanguages"/>
6833                 <xsl:choose>
6834                         <xsl:when test="string-length($currentLanguage)=0"/>
6835                         <xsl:when test="not(contains($usedLanguages, $currentLanguage))">
6836                                 <language>
6837                                         <xsl:if test="@code!='a'">
6838                                                 <xsl:attribute name="objectPart">
6839                                                         <xsl:choose>
6840                                                                 <xsl:when test="@code='b'">summary or subtitle</xsl:when>
6841                                                                 <xsl:when test="@code='d'">sung or spoken text</xsl:when>
6842                                                                 <xsl:when test="@code='e'">libretto</xsl:when>
6843                                                                 <xsl:when test="@code='f'">table of contents</xsl:when>
6844                                                                 <xsl:when test="@code='g'">accompanying material</xsl:when>
6845                                                                 <xsl:when test="@code='h'">translation</xsl:when>
6846                                                         </xsl:choose>
6847                                                 </xsl:attribute>
6848                                         </xsl:if>
6849                                         <languageTerm authority="iso639-2b" type="code">
6850                                                 <xsl:value-of select="$currentLanguage"/>
6851                                         </languageTerm>
6852                                 </language>
6853                                 <xsl:call-template name="isoLanguage">
6854                                         <xsl:with-param name="currentLanguage">
6855                                                 <xsl:value-of select="substring($remainingLanguages,1,3)"/>
6856                                         </xsl:with-param>
6857                                         <xsl:with-param name="usedLanguages">
6858                                                 <xsl:value-of select="concat($usedLanguages,$currentLanguage)"/>
6859                                         </xsl:with-param>
6860                                         <xsl:with-param name="remainingLanguages">
6861                                                 <xsl:value-of
6862                                                         select="substring($remainingLanguages,4,string-length($remainingLanguages))"
6863                                                 />
6864                                         </xsl:with-param>
6865                                 </xsl:call-template>
6866                         </xsl:when>
6867                         <xsl:otherwise>
6868                                 <xsl:call-template name="isoLanguage">
6869                                         <xsl:with-param name="currentLanguage">
6870                                                 <xsl:value-of select="substring($remainingLanguages,1,3)"/>
6871                                         </xsl:with-param>
6872                                         <xsl:with-param name="usedLanguages">
6873                                                 <xsl:value-of select="concat($usedLanguages,$currentLanguage)"/>
6874                                         </xsl:with-param>
6875                                         <xsl:with-param name="remainingLanguages">
6876                                                 <xsl:value-of
6877                                                         select="substring($remainingLanguages,4,string-length($remainingLanguages))"
6878                                                 />
6879                                         </xsl:with-param>
6880                                 </xsl:call-template>
6881                         </xsl:otherwise>
6882                 </xsl:choose>
6883         </xsl:template>
6884         <xsl:template name="chopBrackets">
6885                 <xsl:param name="chopString"/>
6886                 <xsl:variable name="string">
6887                         <xsl:call-template name="chopPunctuation">
6888                                 <xsl:with-param name="chopString" select="$chopString"/>
6889                         </xsl:call-template>
6890                 </xsl:variable>
6891                 <xsl:if test="substring($string, 1,1)='['">
6892                         <xsl:value-of select="substring($string,2, string-length($string)-2)"/>
6893                 </xsl:if>
6894                 <xsl:if test="substring($string, 1,1)!='['">
6895                         <xsl:value-of select="$string"/>
6896                 </xsl:if>
6897         </xsl:template>
6898         <xsl:template name="rfcLanguages">
6899                 <xsl:param name="nodeNum"/>
6900                 <xsl:param name="usedLanguages"/>
6901                 <xsl:param name="controlField008-35-37"/>
6902                 <xsl:variable name="currentLanguage" select="."/>
6903                 <xsl:choose>
6904                         <xsl:when test="not($currentLanguage)"/>
6905                         <xsl:when
6906                                 test="$currentLanguage!=$controlField008-35-37 and $currentLanguage!='rfc3066'">
6907                                 <xsl:if test="not(contains($usedLanguages,$currentLanguage))">
6908                                         <language>
6909                                                 <xsl:if test="@code!='a'">
6910                                                         <xsl:attribute name="objectPart">
6911                                                                 <xsl:choose>
6912                                                                         <xsl:when test="@code='b'">summary or subtitle</xsl:when>
6913                                                                         <xsl:when test="@code='d'">sung or spoken text</xsl:when>
6914                                                                         <xsl:when test="@code='e'">libretto</xsl:when>
6915                                                                         <xsl:when test="@code='f'">table of contents</xsl:when>
6916                                                                         <xsl:when test="@code='g'">accompanying material</xsl:when>
6917                                                                         <xsl:when test="@code='h'">translation</xsl:when>
6918                                                                 </xsl:choose>
6919                                                         </xsl:attribute>
6920                                                 </xsl:if>
6921                                                 <languageTerm authority="rfc3066" type="code">
6922                                                         <xsl:value-of select="$currentLanguage"/>
6923                                                 </languageTerm>
6924                                         </language>
6925                                 </xsl:if>
6926                         </xsl:when>
6927                         <xsl:otherwise> </xsl:otherwise>
6928                 </xsl:choose>
6929         </xsl:template>
6930
6931     <xsl:template name="datafield">
6932                 <xsl:param name="tag"/>
6933                 <xsl:param name="ind1">
6934                         <xsl:text> </xsl:text>
6935                 </xsl:param>
6936                 <xsl:param name="ind2">
6937                         <xsl:text> </xsl:text>
6938                 </xsl:param>
6939                 <xsl:param name="subfields"/>
6940                 <xsl:element name="marc:datafield">
6941                         <xsl:attribute name="tag">
6942                                 <xsl:value-of select="$tag"/>
6943                         </xsl:attribute>
6944                         <xsl:attribute name="ind1">
6945                                 <xsl:value-of select="$ind1"/>
6946                         </xsl:attribute>
6947                         <xsl:attribute name="ind2">
6948                                 <xsl:value-of select="$ind2"/>
6949                         </xsl:attribute>
6950                         <xsl:copy-of select="$subfields"/>
6951                 </xsl:element>
6952         </xsl:template>
6953
6954         <xsl:template name="subfieldSelect">
6955                 <xsl:param name="codes">abcdefghijklmnopqrstuvwxyz</xsl:param>
6956                 <xsl:param name="delimeter">
6957                         <xsl:text> </xsl:text>
6958                 </xsl:param>
6959                 <xsl:variable name="str">
6960                         <xsl:for-each select="marc:subfield">
6961                                 <xsl:if test="contains($codes, @code)">
6962                                         <xsl:value-of select="text()"/>
6963                                         <xsl:value-of select="$delimeter"/>
6964                                 </xsl:if>
6965                         </xsl:for-each>
6966                 </xsl:variable>
6967                 <xsl:value-of select="substring($str,1,string-length($str)-string-length($delimeter))"/>
6968         </xsl:template>
6969
6970         <xsl:template name="buildSpaces">
6971                 <xsl:param name="spaces"/>
6972                 <xsl:param name="char">
6973                         <xsl:text> </xsl:text>
6974                 </xsl:param>
6975                 <xsl:if test="$spaces>0">
6976                         <xsl:value-of select="$char"/>
6977                         <xsl:call-template name="buildSpaces">
6978                                 <xsl:with-param name="spaces" select="$spaces - 1"/>
6979                                 <xsl:with-param name="char" select="$char"/>
6980                         </xsl:call-template>
6981                 </xsl:if>
6982         </xsl:template>
6983
6984         <xsl:template name="chopPunctuation">
6985                 <xsl:param name="chopString"/>
6986                 <xsl:param name="punctuation">
6987                         <xsl:text>.:,;/ </xsl:text>
6988                 </xsl:param>
6989                 <xsl:variable name="length" select="string-length($chopString)"/>
6990                 <xsl:choose>
6991                         <xsl:when test="$length=0"/>
6992                         <xsl:when test="contains($punctuation, substring($chopString,$length,1))">
6993                                 <xsl:call-template name="chopPunctuation">
6994                                         <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
6995                                         <xsl:with-param name="punctuation" select="$punctuation"/>
6996                                 </xsl:call-template>
6997                         </xsl:when>
6998                         <xsl:when test="not($chopString)"/>
6999                         <xsl:otherwise>
7000                                 <xsl:value-of select="$chopString"/>
7001                         </xsl:otherwise>
7002                 </xsl:choose>
7003         </xsl:template>
7004
7005         <xsl:template name="chopPunctuationFront">
7006                 <xsl:param name="chopString"/>
7007                 <xsl:variable name="length" select="string-length($chopString)"/>
7008                 <xsl:choose>
7009                         <xsl:when test="$length=0"/>
7010                         <xsl:when test="contains('.:,;/[ ', substring($chopString,1,1))">
7011                                 <xsl:call-template name="chopPunctuationFront">
7012                                         <xsl:with-param name="chopString" select="substring($chopString,2,$length - 1)"
7013                                         />
7014                                 </xsl:call-template>
7015                         </xsl:when>
7016                         <xsl:when test="not($chopString)"/>
7017                         <xsl:otherwise>
7018                                 <xsl:value-of select="$chopString"/>
7019                         </xsl:otherwise>
7020                 </xsl:choose>
7021         </xsl:template>
7022
7023         <xsl:template name="chopPunctuationBack">
7024                 <xsl:param name="chopString"/>
7025                 <xsl:param name="punctuation">
7026                         <xsl:text>.:,;/] </xsl:text>
7027                 </xsl:param>
7028                 <xsl:variable name="length" select="string-length($chopString)"/>
7029                 <xsl:choose>
7030                         <xsl:when test="$length=0"/>
7031                         <xsl:when test="contains($punctuation, substring($chopString,$length,1))">
7032                                 <xsl:call-template name="chopPunctuation">
7033                                         <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
7034                                         <xsl:with-param name="punctuation" select="$punctuation"/>
7035                                 </xsl:call-template>
7036                         </xsl:when>
7037                         <xsl:when test="not($chopString)"/>
7038                         <xsl:otherwise>
7039                                 <xsl:value-of select="$chopString"/>
7040                         </xsl:otherwise>
7041                 </xsl:choose>
7042         </xsl:template>
7043
7044         <!-- nate added 12/14/2007 for lccn.loc.gov: url encode ampersand, etc. -->
7045         <xsl:template name="url-encode">
7046
7047                 <xsl:param name="str"/>
7048
7049                 <xsl:if test="$str">
7050                         <xsl:variable name="first-char" select="substring($str,1,1)"/>
7051                         <xsl:choose>
7052                                 <xsl:when test="contains($safe,$first-char)">
7053                                         <xsl:value-of select="$first-char"/>
7054                                 </xsl:when>
7055                                 <xsl:otherwise>
7056                                         <xsl:variable name="codepoint">
7057                                                 <xsl:choose>
7058                                                         <xsl:when test="contains($ascii,$first-char)">
7059                                                                 <xsl:value-of
7060                                                                         select="string-length(substring-before($ascii,$first-char)) + 32"
7061                                                                 />
7062                                                         </xsl:when>
7063                                                         <xsl:when test="contains($latin1,$first-char)">
7064                                                                 <xsl:value-of
7065                                                                         select="string-length(substring-before($latin1,$first-char)) + 160"/>
7066                                                                 <!-- was 160 -->
7067                                                         </xsl:when>
7068                                                         <xsl:otherwise>
7069                                                                 <xsl:message terminate="no">Warning: string contains a character
7070                                                                         that is out of range! Substituting "?".</xsl:message>
7071                                                                 <xsl:text>63</xsl:text>
7072                                                         </xsl:otherwise>
7073                                                 </xsl:choose>
7074                                         </xsl:variable>
7075                                         <xsl:variable name="hex-digit1"
7076                                                 select="substring($hex,floor($codepoint div 16) + 1,1)"/>
7077                                         <xsl:variable name="hex-digit2" select="substring($hex,$codepoint mod 16 + 1,1)"/>
7078                                         <!-- <xsl:value-of select="concat('%',$hex-digit2)"/> -->
7079                                         <xsl:value-of select="concat('%',$hex-digit1,$hex-digit2)"/>
7080                                 </xsl:otherwise>
7081                         </xsl:choose>
7082                         <xsl:if test="string-length($str) &gt; 1">
7083                                 <xsl:call-template name="url-encode">
7084                                         <xsl:with-param name="str" select="substring($str,2)"/>
7085                                 </xsl:call-template>
7086                         </xsl:if>
7087                 </xsl:if>
7088         </xsl:template>
7089 </xsl:stylesheet>$$ WHERE name = 'mods33';
7090
7091
7092 INSERT INTO config.global_flag (name, value, enabled, label) VALUES
7093 (
7094     'opac.browse.warnable_regexp_per_class',
7095     '{"title": "^(a|the|an)\\s"}',
7096     FALSE,
7097     oils_i18n_gettext(
7098         'opac.browse.warnable_regexp_per_class',
7099         'Map of search classes to regular expressions to warn user about leading articles.',
7100         'cgf',
7101         'label'
7102     )
7103 ),
7104 (
7105     'opac.browse.holdings_visibility_test_limit',
7106     '100',
7107     TRUE,
7108     oils_i18n_gettext(
7109         'opac.browse.holdings_visibility_test_limit',
7110         'Don''t look for more than this number of records with holdings when displaying browse headings with visible record counts.',
7111         'cgf',
7112         'label'
7113     )
7114 );
7115
7116 ALTER TABLE metabib.browse_entry DROP CONSTRAINT browse_entry_value_key;
7117 ALTER TABLE metabib.browse_entry ADD COLUMN sort_value TEXT;
7118 DELETE FROM metabib.browse_entry_def_map; -- Yeah.
7119 DELETE FROM metabib.browse_entry WHERE sort_value IS NULL;
7120 ALTER TABLE metabib.browse_entry ALTER COLUMN sort_value SET NOT NULL;
7121 ALTER TABLE metabib.browse_entry ADD UNIQUE (value, sort_value);
7122 DROP TRIGGER IF EXISTS mbe_sort_value ON metabib.browse_entry;
7123
7124 CREATE INDEX browse_entry_sort_value_idx
7125     ON metabib.browse_entry USING BTREE (sort_value);
7126
7127 -- NOTE If I understand ordered indices correctly, an index on sort_value DESC
7128 -- is not actually needed, even though we do have a query that does ORDER BY
7129 -- on this column in that direction.  The previous index serves for both
7130 -- directions, and ordering in an index is only helpful for multi-column
7131 -- indices, I think. See http://www.postgresql.org/docs/9.1/static/indexes-ordering.html
7132
7133 -- CREATE INDEX CONCURRENTLY browse_entry_sort_value_idx_desc
7134 --     ON metabib.browse_entry USING BTREE (sort_value DESC);
7135
7136 CREATE TYPE metabib.flat_browse_entry_appearance AS (
7137     browse_entry    BIGINT,
7138     value           TEXT,
7139     fields          TEXT,
7140     authorities     TEXT,
7141     sources         INT,        -- visible ones, that is
7142     row_number      INT,        -- internal use, sort of
7143     accurate        BOOL        -- Count in sources field is accurate? Not
7144                                 -- if we had more than a browse superpage
7145                                 -- of records to look at.
7146 );
7147
7148
7149 CREATE OR REPLACE FUNCTION metabib.browse_pivot(
7150     search_field        INT[],
7151     browse_term         TEXT
7152 ) RETURNS BIGINT AS $p$
7153 DECLARE
7154     id                  BIGINT;
7155 BEGIN
7156     SELECT INTO id mbe.id FROM metabib.browse_entry mbe
7157         JOIN metabib.browse_entry_def_map mbedm ON (
7158             mbedm.entry = mbe.id AND
7159             mbedm.def = ANY(search_field)
7160         )
7161         WHERE mbe.sort_value >= public.search_normalize(browse_term)
7162         ORDER BY mbe.sort_value, mbe.value LIMIT 1;
7163
7164     RETURN id;
7165 END;
7166 $p$ LANGUAGE PLPGSQL;
7167
7168 CREATE OR REPLACE FUNCTION metabib.staged_browse(
7169     core_query              TEXT,
7170     context_org             INT,
7171     context_locations       INT[],
7172     staff                   BOOL,
7173     browse_superpage_size   INT,
7174     result_limit            INT,
7175     use_offset              INT
7176 ) RETURNS SETOF metabib.flat_browse_entry_appearance AS $p$
7177 DECLARE
7178     core_cursor             REFCURSOR;
7179     core_record             RECORD;
7180     qpfts_query             TEXT;
7181     result_row              metabib.flat_browse_entry_appearance%ROWTYPE;
7182     results_skipped         INT := 0;
7183     results_returned        INT := 0;
7184     slice_start             INT;
7185     slice_end               INT;
7186     full_end                INT;
7187     superpage_of_records    BIGINT[];
7188     superpage_size          INT;
7189 BEGIN
7190     OPEN core_cursor FOR EXECUTE core_query;
7191
7192     LOOP
7193         FETCH core_cursor INTO core_record;
7194         EXIT WHEN NOT FOUND;
7195
7196         result_row.sources := 0;
7197
7198         full_end := ARRAY_LENGTH(core_record.records, 1);
7199         superpage_size := COALESCE(browse_superpage_size, full_end);
7200         slice_start := 1;
7201         slice_end := superpage_size;
7202
7203         WHILE result_row.sources = 0 AND slice_start <= full_end LOOP
7204             superpage_of_records := core_record.records[slice_start:slice_end];
7205             qpfts_query :=
7206                 'SELECT NULL::BIGINT AS id, ARRAY[r] AS records, ' ||
7207                 '1::INT AS rel FROM (SELECT UNNEST(' ||
7208                 quote_literal(superpage_of_records) || '::BIGINT[]) AS r) rr';
7209
7210             -- We use search.query_parser_fts() for visibility testing.
7211             -- We're calling it once per browse-superpage worth of records
7212             -- out of the set of records related to a given mbe, until we've
7213             -- either exhausted that set of records or found at least 1
7214             -- visible record.
7215
7216             SELECT INTO result_row.sources visible
7217                 FROM search.query_parser_fts(
7218                     context_org, NULL, qpfts_query, NULL,
7219                     context_locations, 0, NULL, NULL, FALSE, staff, FALSE
7220                 ) qpfts
7221                 WHERE qpfts.rel IS NULL;
7222
7223             slice_start := slice_start + superpage_size;
7224             slice_end := slice_end + superpage_size;
7225         END LOOP;
7226
7227         -- Accurate?  Well, probably.
7228         result_row.accurate := browse_superpage_size IS NULL OR
7229             browse_superpage_size >= full_end;
7230
7231         IF result_row.sources > 0 THEN
7232             IF results_skipped < use_offset THEN
7233                 results_skipped := results_skipped + 1;
7234                 CONTINUE;
7235             END IF;
7236
7237             result_row.browse_entry := core_record.id;
7238             result_row.authorities := core_record.authorities;
7239             result_row.fields := core_record.fields;
7240             result_row.value := core_record.value;
7241
7242             -- This is needed so our caller can flip it and reverse it.
7243             result_row.row_number := results_returned;
7244
7245             RETURN NEXT result_row;
7246
7247             results_returned := results_returned + 1;
7248
7249             EXIT WHEN results_returned >= result_limit;
7250         END IF;
7251     END LOOP;
7252 END;
7253 $p$ LANGUAGE PLPGSQL;
7254
7255 -- This is optimized to be fast for values of result_offset near zero.
7256 CREATE OR REPLACE FUNCTION metabib.browse(
7257     search_field            INT[],
7258     browse_term             TEXT,
7259     context_org             INT DEFAULT NULL,
7260     context_loc_group       INT DEFAULT NULL,
7261     staff                   BOOL DEFAULT FALSE,
7262     pivot_id                BIGINT DEFAULT NULL,
7263     force_backward          BOOL DEFAULT FALSE,
7264     result_limit            INT DEFAULT 10,
7265     result_offset           INT DEFAULT 0   -- Can be negative!
7266 ) RETURNS SETOF metabib.flat_browse_entry_appearance AS $p$
7267 DECLARE
7268     core_query              TEXT;
7269     whole_query             TEXT;
7270     pivot_sort_value        TEXT;
7271     pivot_sort_fallback     TEXT;
7272     context_locations       INT[];
7273     use_offset              INT;
7274     browse_superpage_size   INT;
7275     results_skipped         INT := 0;
7276 BEGIN
7277     IF pivot_id IS NULL THEN
7278         pivot_id := metabib.browse_pivot(search_field, browse_term);
7279     END IF;
7280
7281     SELECT INTO pivot_sort_value, pivot_sort_fallback
7282         sort_value, value FROM metabib.browse_entry WHERE id = pivot_id;
7283
7284     IF pivot_sort_value IS NULL THEN
7285         RETURN;
7286     END IF;
7287
7288     IF context_loc_group IS NOT NULL THEN
7289         SELECT INTO context_locations ARRAY_AGG(location)
7290             FROM asset.copy_location_group_map
7291             WHERE lgroup = context_loc_group;
7292     END IF;
7293
7294     SELECT INTO browse_superpage_size value     -- NULL ok
7295         FROM config.global_flag
7296         WHERE enabled AND name = 'opac.browse.holdings_visibility_test_limit';
7297
7298     core_query := '
7299     SELECT
7300         mbe.id,
7301         mbe.value,
7302         mbe.sort_value,
7303         (SELECT ARRAY_AGG(src) FROM (
7304             SELECT DISTINCT UNNEST(ARRAY_AGG(mbedm.source)) AS src
7305         ) ss) AS records,
7306         (SELECT ARRAY_TO_STRING(ARRAY_AGG(authority), $$,$$) FROM (
7307             SELECT DISTINCT UNNEST(ARRAY_AGG(mbedm.authority)) AS authority
7308         ) au) AS authorities,
7309         (SELECT ARRAY_TO_STRING(ARRAY_AGG(field), $$,$$) FROM (
7310             SELECT DISTINCT UNNEST(ARRAY_AGG(mbedm.def)) AS field
7311         ) fi) AS fields
7312     FROM metabib.browse_entry mbe
7313     JOIN metabib.browse_entry_def_map mbedm ON (
7314         mbedm.entry = mbe.id AND
7315         mbedm.def = ANY(' || quote_literal(search_field) || ')
7316     )
7317     WHERE ';
7318
7319     -- PostgreSQL is not magic. We can't actually pass a negative offset.
7320     IF result_offset >= 0 AND NOT force_backward THEN
7321         use_offset := result_offset;
7322         core_query := core_query ||
7323             ' mbe.sort_value >= ' || quote_literal(pivot_sort_value) ||
7324         ' GROUP BY 1,2,3 ORDER BY mbe.sort_value, mbe.value ';
7325
7326         RETURN QUERY SELECT * FROM metabib.staged_browse(
7327             core_query, context_org, context_locations,
7328             staff, browse_superpage_size, result_limit, use_offset
7329         );
7330     ELSE
7331         -- Part 1 of 2 to deliver what the user wants with a negative offset:
7332         core_query := core_query ||
7333             ' mbe.sort_value < ' || quote_literal(pivot_sort_value) ||
7334         ' GROUP BY 1,2,3 ORDER BY mbe.sort_value DESC, mbe.value DESC ';
7335
7336         -- Part 2 of 2 to deliver what the user wants with a negative offset:
7337         RETURN QUERY SELECT * FROM (SELECT * FROM metabib.staged_browse(
7338             core_query, context_org, context_locations,
7339             staff, browse_superpage_size, result_limit, use_offset
7340         )) sb ORDER BY row_number DESC;
7341
7342     END IF;
7343 END;
7344 $p$ LANGUAGE PLPGSQL;
7345
7346 CREATE OR REPLACE FUNCTION metabib.browse(
7347     search_class        TEXT,
7348     browse_term         TEXT,
7349     context_org         INT DEFAULT NULL,
7350     context_loc_group   INT DEFAULT NULL,
7351     staff               BOOL DEFAULT FALSE,
7352     pivot_id            BIGINT DEFAULT NULL,
7353     force_backward      BOOL DEFAULT FALSE,
7354     result_limit        INT DEFAULT 10,
7355     result_offset       INT DEFAULT 0   -- Can be negative, implying backward!
7356 ) RETURNS SETOF metabib.flat_browse_entry_appearance AS $p$
7357 BEGIN
7358     RETURN QUERY SELECT * FROM metabib.browse(
7359         (SELECT COALESCE(ARRAY_AGG(id), ARRAY[]::INT[])
7360             FROM config.metabib_field WHERE field_class = search_class),
7361         browse_term,
7362         context_org,
7363         context_loc_group,
7364         staff,
7365         pivot_id,
7366         force_backward,
7367         result_limit,
7368         result_offset
7369     );
7370 END;
7371 $p$ LANGUAGE PLPGSQL;
7372
7373 UPDATE config.metabib_field
7374 SET
7375     xpath = $$//mods32:mods/mods32:relatedItem[@type="series"]/mods32:titleInfo[@type="nfi"]$$,
7376     browse_sort_xpath = $$*[local-name() != "nonSort"]$$,
7377     browse_xpath = NULL
7378 WHERE
7379     field_class = 'series' AND name = 'seriestitle' ;
7380
7381 UPDATE config.metabib_field
7382 SET
7383     xpath = $$//mods32:mods/mods32:titleInfo[mods32:title and not (@type)]$$,
7384     browse_sort_xpath = $$*[local-name() != "nonSort"]$$,
7385     browse_xpath = NULL,
7386     browse_field = TRUE
7387 WHERE
7388     field_class = 'title' AND name = 'proper' ;
7389
7390 UPDATE config.metabib_field
7391 SET
7392     xpath = $$//mods32:mods/mods32:titleInfo[mods32:title and (@type='alternative-nfi')]$$,
7393     browse_sort_xpath = $$*[local-name() != "nonSort"]$$,
7394     browse_xpath = NULL
7395 WHERE
7396     field_class = 'title' AND name = 'alternative' ;
7397
7398 UPDATE config.metabib_field
7399 SET
7400     xpath = $$//mods32:mods/mods32:titleInfo[mods32:title and (@type='uniform-nfi')]$$,
7401     browse_sort_xpath = $$*[local-name() != "nonSort"]$$,
7402     browse_xpath = NULL
7403 WHERE
7404     field_class = 'title' AND name = 'uniform' ;
7405
7406 UPDATE config.metabib_field
7407 SET
7408     xpath = $$//mods32:mods/mods32:titleInfo[mods32:title and (@type='translated-nfi')]$$,
7409     browse_sort_xpath = $$*[local-name() != "nonSort"]$$,
7410     browse_xpath = NULL
7411 WHERE
7412     field_class = 'title' AND name = 'translated' ;
7413
7414 -- This keeps extra terms like "creator" out of browse headings.
7415 UPDATE config.metabib_field
7416     SET browse_xpath = $$//*[local-name()='namePart']$$     -- vim */
7417     WHERE
7418         browse_field AND
7419         browse_xpath IS NULL AND
7420         field_class = 'author';
7421
7422 COMMIT;
7423
7424 \qecho This is a browse-only reingest of your bib records. It may take a while.
7425 \qecho You may cancel now without losing the effect of the rest of the
7426 \qecho upgrade script, and arrange the reingest later.
7427 \qecho .
7428 SELECT metabib.reingest_metabib_field_entries(id, TRUE, FALSE, TRUE)
7429     FROM biblio.record_entry;