2077f9c9da1aac34bff68c9805c81cfb16bbcc74
[working/Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / YYYY.schema.bib-auth-browse.sql
1 BEGIN;
2
3 -- check whether patch can be applied
4 -- SELECT evergreen.upgrade_deps_block_check('YYYY', :eg_version);
5
6 -- 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              &nbs