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