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