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