]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/sql/Pg/upgrade/0672.fix-nonfiling-titles.sql
LP#1947173: Clean up bad cataloging pot hole
[Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / 0672.fix-nonfiling-titles.sql
1 -- Evergreen DB patch 0672.fix-nonfiling-titles.sql
2 --
3 -- Titles that begin with non-filing articles using apostrophes
4 -- (for example, "L'armée") get spaces injected between the article
5 -- and the subsequent text, which then breaks searching for titles
6 -- beginning with those articles.
7 --
8 -- This patch adds a nonfiling title element to MODS32 that can then
9 -- be used to retrieve the title proper without affecting the spaces
10 -- in the title. It's what we want, what we really really want, for
11 -- title searches.
12 --
13 BEGIN;
14
15
16 -- check whether patch can be applied
17 SELECT evergreen.upgrade_deps_block_check('0672', :eg_version);
18
19 -- Update the XPath definition before the titleNonfiling element exists;
20 -- but are you really going to read through the whole XSL below before
21 -- seeing this important bit?
22 UPDATE config.metabib_field
23     SET xpath = $$//mods32:mods/mods32:titleNonfiling[mods32:title and not (@type)]$$,
24         format = 'mods32'
25     WHERE field_class = 'title' AND name = 'proper';
26
27 UPDATE config.xml_transform SET xslt=$$<?xml version="1.0" encoding="UTF-8"?>
28 <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">
29         <xsl:output encoding="UTF-8" indent="yes" method="xml"/>
30 <!--
31 Revision 1.14 - Fixed template isValid and fields 010, 020, 022, 024, 028, and 037 to output additional identifier elements 
32   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
33
34 Revision 1.13 - Changed order of output under cartographics to reflect schema  2006/11/28 tmee
35         
36 Revision 1.12 - Updated to reflect MODS 3.2 Mapping  2006/10/11 tmee
37                 
38 Revision 1.11 - The attribute objectPart moved from <languageTerm> to <language>
39       2006/04/08  jrad
40
41 Revision 1.10 MODS 3.1 revisions to language and classification elements  
42                                 (plus ability to find marc:collection embedded in wrapper elements such as SRU zs: wrappers)
43                                 2006/02/06  ggar
44
45 Revision 1.9 subfield $y was added to field 242 2004/09/02 10:57 jrad
46
47 Revision 1.8 Subject chopPunctuation expanded and attribute fixes 2004/08/12 jrad
48
49 Revision 1.7 2004/03/25 08:29 jrad
50
51 Revision 1.6 various validation fixes 2004/02/20 ntra
52
53 Revision 1.5  2003/10/02 16:18:58  ntra
54 MODS2 to MODS3 updates, language unstacking and 
55 de-duping, chopPunctuation expanded
56
57 Revision 1.3  2003/04/03 00:07:19  ntra
58 Revision 1.3 Additional Changes not related to MODS Version 2.0 by ntra
59
60 Revision 1.2  2003/03/24 19:37:42  ckeith
61 Added Log Comment
62
63 -->
64         <xsl:template match="/">
65                 <xsl:choose>
66                         <xsl:when test="//marc:collection">
67                                 <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">
68                                         <xsl:for-each select="//marc:collection/marc:record">
69                                                 <mods version="3.2">
70                                                         <xsl:call-template name="marcRecord"/>
71                                                 </mods>
72                                         </xsl:for-each>
73                                 </modsCollection>
74                         </xsl:when>
75                         <xsl:otherwise>
76                                 <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">
77                                         <xsl:for-each select="//marc:record">
78                                                 <xsl:call-template name="marcRecord"/>
79                                         </xsl:for-each>
80                                 </mods>
81                         </xsl:otherwise>
82                 </xsl:choose>
83         </xsl:template>
84         <xsl:template name="marcRecord">
85                 <xsl:variable name="leader" select="marc:leader"/>
86                 <xsl:variable name="leader6" select="substring($leader,7,1)"/>
87                 <xsl:variable name="leader7" select="substring($leader,8,1)"/>
88                 <xsl:variable name="controlField008" select="marc:controlfield[@tag='008']"/>
89                 <xsl:variable name="typeOf008">
90                         <xsl:choose>
91                                 <xsl:when test="$leader6='a'">
92                                         <xsl:choose>
93                                                 <xsl:when test="$leader7='a' or $leader7='c' or $leader7='d' or $leader7='m'">BK</xsl:when>
94                                                 <xsl:when test="$leader7='b' or $leader7='i' or $leader7='s'">SE</xsl:when>
95                                         </xsl:choose>
96                                 </xsl:when>
97                                 <xsl:when test="$leader6='t'">BK</xsl:when>
98                                 <xsl:when test="$leader6='p'">MM</xsl:when>
99                                 <xsl:when test="$leader6='m'">CF</xsl:when>
100                                 <xsl:when test="$leader6='e' or $leader6='f'">MP</xsl:when>
101                                 <xsl:when test="$leader6='g' or $leader6='k' or $leader6='o' or $leader6='r'">VM</xsl:when>
102                                 <xsl:when test="$leader6='c' or $leader6='d' or $leader6='i' or $leader6='j'">MU</xsl:when>
103                         </xsl:choose>
104                 </xsl:variable>
105                 <xsl:for-each select="marc:datafield[@tag='245']">
106                         <titleInfo>
107                                 <xsl:variable name="title">
108                                         <xsl:choose>
109                                                 <xsl:when test="marc:subfield[@code='b']">
110                                                         <xsl:call-template name="specialSubfieldSelect">
111                                                                 <xsl:with-param name="axis">b</xsl:with-param>
112                                                                 <xsl:with-param name="beforeCodes">afgk</xsl:with-param>
113                                                         </xsl:call-template>
114                                                 </xsl:when>
115                                                 <xsl:otherwise>
116                                                         <xsl:call-template name="subfieldSelect">
117                                                                 <xsl:with-param name="codes">abfgk</xsl:with-param>
118                                                         </xsl:call-template>
119                                                 </xsl:otherwise>
120                                         </xsl:choose>
121                                 </xsl:variable>
122                                 <xsl:variable name="titleChop">
123                                         <xsl:call-template name="chopPunctuation">
124                                                 <xsl:with-param name="chopString">
125                                                         <xsl:value-of select="$title"/>
126                                                 </xsl:with-param>
127                                         </xsl:call-template>
128                                 </xsl:variable>
129                                 <xsl:choose>
130                                         <xsl:when test="@ind2>0">
131                                                 <nonSort>
132                                                         <xsl:value-of select="substring($titleChop,1,@ind2)"/>
133                                                 </nonSort>
134                                                 <title>
135                                                         <xsl:value-of select="substring($titleChop,@ind2+1)"/>
136                                                 </title>
137                                         </xsl:when>
138                                         <xsl:otherwise>
139                                                 <title>
140                                                         <xsl:value-of select="$titleChop"/>
141                                                 </title>
142                                         </xsl:otherwise>
143                                 </xsl:choose>
144                                 <xsl:if test="marc:subfield[@code='b']">
145                                         <subTitle>
146                                                 <xsl:call-template name="chopPunctuation">
147                                                         <xsl:with-param name="chopString">
148                                                                 <xsl:call-template name="specialSubfieldSelect">
149                                                                         <xsl:with-param name="axis">b</xsl:with-param>
150                                                                         <xsl:with-param name="anyCodes">b</xsl:with-param>
151                                                                         <xsl:with-param name="afterCodes">afgk</xsl:with-param>
152                                                                 </xsl:call-template>
153                                                         </xsl:with-param>
154                                                 </xsl:call-template>
155                                         </subTitle>
156                                 </xsl:if>
157                                 <xsl:call-template name="part"></xsl:call-template>
158                         </titleInfo>
159                         <!-- A form of title that ignores non-filing characters; useful
160                                  for not converting "L'Oreal" into "L' Oreal" at index time -->
161                         <titleNonfiling>
162                                 <xsl:variable name="title">
163                                         <xsl:choose>
164                                                 <xsl:when test="marc:subfield[@code='b']">
165                                                         <xsl:call-template name="specialSubfieldSelect">
166                                                                 <xsl:with-param name="axis">b</xsl:with-param>
167                                                                 <xsl:with-param name="beforeCodes">afgk</xsl:with-param>
168                                                         </xsl:call-template>
169                                                 </xsl:when>
170                                                 <xsl:otherwise>
171                                                         <xsl:call-template name="subfieldSelect">
172                                                                 <xsl:with-param name="codes">abfgk</xsl:with-param>
173                                                         </xsl:call-template>
174                                                 </xsl:otherwise>
175                                         </xsl:choose>
176                                 </xsl:variable>
177                                 <title>
178                                         <xsl:value-of select="$title"/>
179                                 </title>
180                                 <xsl:if test="marc:subfield[@code='b']">
181                                         <subTitle>
182                                                 <xsl:call-template name="chopPunctuation">
183                                                         <xsl:with-param name="chopString">
184                                                                 <xsl:call-template name="specialSubfieldSelect">
185                                                                         <xsl:with-param name="axis">b</xsl:with-param>
186                                                                         <xsl:with-param name="anyCodes">b</xsl:with-param>
187                                                                         <xsl:with-param name="afterCodes">afgk</xsl:with-param>
188                                                                 </xsl:call-template>
189                                                         </xsl:with-param>
190                                                 </xsl:call-template>
191                                         </subTitle>
192                                 </xsl:if>
193                                 <xsl:call-template name="part"></xsl:call-template>
194                         </titleNonfiling>
195                 </xsl:for-each>
196                 <xsl:for-each select="marc:datafield[@tag='210']">
197                         <titleInfo type="abbreviated">
198                                 <title>
199                                         <xsl:call-template name="chopPunctuation">
200                                                 <xsl:with-param name="chopString">
201                                                         <xsl:call-template name="subfieldSelect">
202                                                                 <xsl:with-param name="codes">a</xsl:with-param>
203                                                         </xsl:call-template>
204                                                 </xsl:with-param>
205                                         </xsl:call-template>
206                                 </title>
207                                 <xsl:call-template name="subtitle"/>
208                         </titleInfo>
209                 </xsl:for-each>
210                 <xsl:for-each select="marc:datafield[@tag='242']">
211                         <titleInfo type="translated">
212                                 <!--09/01/04 Added subfield $y-->
213                                 <xsl:for-each select="marc:subfield[@code='y']">
214                                         <xsl:attribute name="lang">
215                                                 <xsl:value-of select="text()"/>
216                                         </xsl:attribute>
217                                 </xsl:for-each>
218                                 <title>
219                                         <xsl:call-template name="chopPunctuation">
220                                                 <xsl:with-param name="chopString">
221                                                         <xsl:call-template name="subfieldSelect">
222                                                                 <!-- 1/04 removed $h, b -->
223                                                                 <xsl:with-param name="codes">a</xsl:with-param>
224                                                         </xsl:call-template>
225                                                 </xsl:with-param>
226                                         </xsl:call-template>
227                                 </title>
228                                 <!-- 1/04 fix -->
229                                 <xsl:call-template name="subtitle"/>
230                                 <xsl:call-template name="part"/>
231                         </titleInfo>
232                 </xsl:for-each>
233                 <xsl:for-each select="marc:datafield[@tag='246']">
234                         <titleInfo type="alternative">
235                                 <xsl:for-each select="marc:subfield[@code='i']">
236                                         <xsl:attribute name="displayLabel">
237                                                 <xsl:value-of select="text()"/>
238                                         </xsl:attribute>
239                                 </xsl:for-each>
240                                 <title>
241                                         <xsl:call-template name="chopPunctuation">
242                                                 <xsl:with-param name="chopString">
243                                                         <xsl:call-template name="subfieldSelect">
244                                                                 <!-- 1/04 removed $h, $b -->
245                                                                 <xsl:with-param name="codes">af</xsl:with-param>
246                                                         </xsl:call-template>
247                                                 </xsl:with-param>
248                                         </xsl:call-template>
249                                 </title>
250                                 <xsl:call-template name="subtitle"/>
251                                 <xsl:call-template name="part"/>
252                         </titleInfo>
253                 </xsl:for-each>
254                 <xsl:for-each select="marc:datafield[@tag='130']|marc:datafield[@tag='240']|marc:datafield[@tag='730'][@ind2!='2']">
255                         <titleInfo type="uniform">
256                                 <title>
257                                         <xsl:variable name="str">
258                                                 <xsl:for-each select="marc:subfield">
259                                                         <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'])))">
260                                                                 <xsl:value-of select="text()"/>
261                                                                 <xsl:text> </xsl:text>
262                                                         </xsl:if>
263                                                 </xsl:for-each>
264                                         </xsl:variable>
265                                         <xsl:call-template name="chopPunctuation">
266                                                 <xsl:with-param name="chopString">
267                                                         <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
268                                                 </xsl:with-param>
269                                         </xsl:call-template>
270                                 </title>
271                                 <xsl:call-template name="part"/>
272                         </titleInfo>
273                 </xsl:for-each>
274                 <xsl:for-each select="marc:datafield[@tag='740'][@ind2!='2']">
275                         <titleInfo type="alternative">
276                                 <title>
277                                         <xsl:call-template name="chopPunctuation">
278                                                 <xsl:with-param name="chopString">
279                                                         <xsl:call-template name="subfieldSelect">
280                                                                 <xsl:with-param name="codes">ah</xsl:with-param>
281                                                         </xsl:call-template>
282                                                 </xsl:with-param>
283                                         </xsl:call-template>
284                                 </title>
285                                 <xsl:call-template name="part"/>
286                         </titleInfo>
287                 </xsl:for-each>
288                 <xsl:for-each select="marc:datafield[@tag='100']">
289                         <name type="personal">
290                                 <xsl:call-template name="nameABCDQ"/>
291                                 <xsl:call-template name="affiliation"/>
292                                 <role>
293                                         <roleTerm authority="marcrelator" type="text">creator</roleTerm>
294                                 </role>
295                                 <xsl:call-template name="role"/>
296                         </name>
297                 </xsl:for-each>
298                 <xsl:for-each select="marc:datafield[@tag='110']">
299                         <name type="corporate">
300                                 <xsl:call-template name="nameABCDN"/>
301                                 <role>
302                                         <roleTerm authority="marcrelator" type="text">creator</roleTerm>
303                                 </role>
304                                 <xsl:call-template name="role"/>
305                         </name>
306                 </xsl:for-each>
307                 <xsl:for-each select="marc:datafield[@tag='111']">
308                         <name type="conference">
309                                 <xsl:call-template name="nameACDEQ"/>
310                                 <role>
311                                         <roleTerm authority="marcrelator" type="text">creator</roleTerm>
312                                 </role>
313                                 <xsl:call-template name="role"/>
314                         </name>
315                 </xsl:for-each>
316                 <xsl:for-each select="marc:datafield[@tag='700'][not(marc:subfield[@code='t'])]">
317                         <name type="personal">
318                                 <xsl:call-template name="nameABCDQ"/>
319                                 <xsl:call-template name="affiliation"/>
320                                 <xsl:call-template name="role"/>
321                         </name>
322                 </xsl:for-each>
323                 <xsl:for-each select="marc:datafield[@tag='710'][not(marc:subfield[@code='t'])]">
324                         <name type="corporate">
325                                 <xsl:call-template name="nameABCDN"/>
326                                 <xsl:call-template name="role"/>
327                         </name>
328                 </xsl:for-each>
329                 <xsl:for-each select="marc:datafield[@tag='711'][not(marc:subfield[@code='t'])]">
330                         <name type="conference">
331                                 <xsl:call-template name="nameACDEQ"/>
332                                 <xsl:call-template name="role"/>
333                         </name>
334                 </xsl:for-each>
335                 <xsl:for-each select="marc:datafield[@tag='720'][not(marc:subfield[@code='t'])]">
336                         <name>
337                                 <xsl:if test="@ind1=1">
338                                         <xsl:attribute name="type">
339                                                 <xsl:text>personal</xsl:text>
340                                         </xsl:attribute>
341                                 </xsl:if>
342                                 <namePart>
343                                         <xsl:value-of select="marc:subfield[@code='a']"/>
344                                 </namePart>
345                                 <xsl:call-template name="role"/>
346                         </name>
347                 </xsl:for-each>
348                 <typeOfResource>
349                         <xsl:if test="$leader7='c'">
350                                 <xsl:attribute name="collection">yes</xsl:attribute>
351                         </xsl:if>
352                         <xsl:if test="$leader6='d' or $leader6='f' or $leader6='p' or $leader6='t'">
353                                 <xsl:attribute name="manuscript">yes</xsl:attribute>
354                         </xsl:if>
355                         <xsl:choose>
356                                 <xsl:when test="$leader6='a' or $leader6='t'">text</xsl:when>
357                                 <xsl:when test="$leader6='e' or $leader6='f'">cartographic</xsl:when>
358                                 <xsl:when test="$leader6='c' or $leader6='d'">notated music</xsl:when>
359                                 <xsl:when test="$leader6='i'">sound recording-nonmusical</xsl:when>
360                                 <xsl:when test="$leader6='j'">sound recording-musical</xsl:when>
361                                 <xsl:when test="$leader6='k'">still image</xsl:when>
362                                 <xsl:when test="$leader6='g'">moving image</xsl:when>
363                                 <xsl:when test="$leader6='r'">three dimensional object</xsl:when>
364                                 <xsl:when test="$leader6='m'">software, multimedia</xsl:when>
365                                 <xsl:when test="$leader6='p'">mixed material</xsl:when>
366                         </xsl:choose>
367                 </typeOfResource>
368                 <xsl:if test="substring($controlField008,26,1)='d'">
369                         <genre authority="marc">globe</genre>
370                 </xsl:if>
371                 <xsl:if test="marc:controlfield[@tag='007'][substring(text(),1,1)='a'][substring(text(),2,1)='r']">
372                         <genre authority="marc">remote sensing image</genre>
373                 </xsl:if>
374                 <xsl:if test="$typeOf008='MP'">
375                         <xsl:variable name="controlField008-25" select="substring($controlField008,26,1)"></xsl:variable>
376                         <xsl:choose>
377                                 <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']">
378                                         <genre authority="marc">map</genre>
379                                 </xsl:when>
380                                 <xsl:when test="$controlField008-25='e' or marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='d']">
381                                         <genre authority="marc">atlas</genre>
382                                 </xsl:when>
383                         </xsl:choose>
384                 </xsl:if>
385                 <xsl:if test="$typeOf008='SE'">
386                         <xsl:variable name="controlField008-21" select="substring($controlField008,22,1)"></xsl:variable>
387                         <xsl:choose>
388                                 <xsl:when test="$controlField008-21='d'">
389                                         <genre authority="marc">database</genre>
390                                 </xsl:when>
391                                 <xsl:when test="$controlField008-21='l'">
392                                         <genre authority="marc">loose-leaf</genre>
393                                 </xsl:when>
394                                 <xsl:when test="$controlField008-21='m'">
395                                         <genre authority="marc">series</genre>
396                                 </xsl:when>
397                                 <xsl:when test="$controlField008-21='n'">
398                                         <genre authority="marc">newspaper</genre>
399                                 </xsl:when>
400                                 <xsl:when test="$controlField008-21='p'">
401                                         <genre authority="marc">periodical</genre>
402                                 </xsl:when>
403                                 <xsl:when test="$controlField008-21='w'">
404                                         <genre authority="marc">web site</genre>
405                                 </xsl:when>
406                         </xsl:choose>
407                 </xsl:if>
408                 <xsl:if test="$typeOf008='BK' or $typeOf008='SE'">
409                         <xsl:variable name="controlField008-24" select="substring($controlField008,25,4)"></xsl:variable>
410                         <xsl:choose>
411                                 <xsl:when test="contains($controlField008-24,'a')">
412                                         <genre authority="marc">abstract or summary</genre>
413                                 </xsl:when>
414                                 <xsl:when test="contains($controlField008-24,'b')">
415                                         <genre authority="marc">bibliography</genre>
416                                 </xsl:when>
417                                 <xsl:when test="contains($controlField008-24,'c')">
418                                         <genre authority="marc">catalog</genre>
419                                 </xsl:when>
420                                 <xsl:when test="contains($controlField008-24,'d')">
421                                         <genre authority="marc">dictionary</genre>
422                                 </xsl:when>
423                                 <xsl:when test="contains($controlField008-24,'e')">
424                                         <genre authority="marc">encyclopedia</genre>
425                                 </xsl:when>
426                                 <xsl:when test="contains($controlField008-24,'f')">
427                                         <genre authority="marc">handbook</genre>
428                                 </xsl:when>
429                                 <xsl:when test="contains($controlField008-24,'g')">
430                                         <genre authority="marc">legal article</genre>
431                                 </xsl:when>
432                                 <xsl:when test="contains($controlField008-24,'i')">
433                                         <genre authority="marc">index</genre>
434                                 </xsl:when>
435                                 <xsl:when test="contains($controlField008-24,'k')">
436                                         <genre authority="marc">discography</genre>
437                                 </xsl:when>
438                                 <xsl:when test="contains($controlField008-24,'l')">
439                                         <genre authority="marc">legislation</genre>
440                                 </xsl:when>
441                                 <xsl:when test="contains($controlField008-24,'m')">
442                                         <genre authority="marc">theses</genre>
443                                 </xsl:when>
444                                 <xsl:when test="contains($controlField008-24,'n')">
445                                         <genre authority="marc">survey of literature</genre>
446                                 </xsl:when>
447                                 <xsl:when test="contains($controlField008-24,'o')">
448                                         <genre authority="marc">review</genre>
449                                 </xsl:when>
450                                 <xsl:when test="contains($controlField008-24,'p')">
451                                         <genre authority="marc">programmed text</genre>
452                                 </xsl:when>
453                                 <xsl:when test="contains($controlField008-24,'q')">
454                                         <genre authority="marc">filmography</genre>
455                                 </xsl:when>
456                                 <xsl:when test="contains($controlField008-24,'r')">
457                                         <genre authority="marc">directory</genre>
458                                 </xsl:when>
459                                 <xsl:when test="contains($controlField008-24,'s')">
460                                         <genre authority="marc">statistics</genre>
461                                 </xsl:when>
462                                 <xsl:when test="contains($controlField008-24,'t')">
463                                         <genre authority="marc">technical report</genre>
464                                 </xsl:when>
465                                 <xsl:when test="contains($controlField008-24,'v')">
466                                         <genre authority="marc">legal case and case notes</genre>
467                                 </xsl:when>
468                                 <xsl:when test="contains($controlField008-24,'w')">
469                                         <genre authority="marc">law report or digest</genre>
470                                 </xsl:when>
471                                 <xsl:when test="contains($controlField008-24,'z')">
472                                         <genre authority="marc">treaty</genre>
473                                 </xsl:when>
474                         </xsl:choose>
475                         <xsl:variable name="controlField008-29" select="substring($controlField008,30,1)"></xsl:variable>
476                         <xsl:choose>
477                                 <xsl:when test="$controlField008-29='1'">
478                                         <genre authority="marc">conference publication</genre>
479                                 </xsl:when>
480                         </xsl:choose>
481                 </xsl:if>
482                 <xsl:if test="$typeOf008='CF'">
483                         <xsl:variable name="controlField008-26" select="substring($controlField008,27,1)"></xsl:variable>
484                         <xsl:choose>
485                                 <xsl:when test="$controlField008-26='a'">
486                                         <genre authority="marc">numeric data</genre>
487                                 </xsl:when>
488                                 <xsl:when test="$controlField008-26='e'">
489                                         <genre authority="marc">database</genre>
490                                 </xsl:when>
491                                 <xsl:when test="$controlField008-26='f'">
492                                         <genre authority="marc">font</genre>
493                                 </xsl:when>
494                                 <xsl:when test="$controlField008-26='g'">
495                                         <genre authority="marc">game</genre>
496                                 </xsl:when>
497                         </xsl:choose>
498                 </xsl:if>
499                 <xsl:if test="$typeOf008='BK'">
500                         <xsl:if test="substring($controlField008,25,1)='j'">
501                                 <genre authority="marc">patent</genre>
502                         </xsl:if>
503                         <xsl:if test="substring($controlField008,31,1)='1'">
504                                 <genre authority="marc">festschrift</genre>
505                         </xsl:if>
506                         <xsl:variable name="controlField008-34" select="substring($controlField008,35,1)"></xsl:variable>
507                         <xsl:if test="$controlField008-34='a' or $controlField008-34='b' or $controlField008-34='c' or $controlField008-34='d'">
508                                 <genre authority="marc">biography</genre>
509                         </xsl:if>
510                         <xsl:variable name="controlField008-33" select="substring($controlField008,34,1)"></xsl:variable>
511                         <xsl:choose>
512                                 <xsl:when test="$controlField008-33='e'">
513                                         <genre authority="marc">essay</genre>
514                                 </xsl:when>
515                                 <xsl:when test="$controlField008-33='d'">
516                                         <genre authority="marc">drama</genre>
517                                 </xsl:when>
518                                 <xsl:when test="$controlField008-33='c'">
519                                         <genre authority="marc">comic strip</genre>
520                                 </xsl:when>
521                                 <xsl:when test="$controlField008-33='l'">
522                                         <genre authority="marc">fiction</genre>
523                                 </xsl:when>
524                                 <xsl:when test="$controlField008-33='h'">
525                                         <genre authority="marc">humor, satire</genre>
526                                 </xsl:when>
527                                 <xsl:when test="$controlField008-33='i'">
528                                         <genre authority="marc">letter</genre>
529                                 </xsl:when>
530                                 <xsl:when test="$controlField008-33='f'">
531                                         <genre authority="marc">novel</genre>
532                                 </xsl:when>
533                                 <xsl:when test="$controlField008-33='j'">
534                                         <genre authority="marc">short story</genre>
535                                 </xsl:when>
536                                 <xsl:when test="$controlField008-33='s'">
537                                         <genre authority="marc">speech</genre>
538                                 </xsl:when>
539                         </xsl:choose>
540                 </xsl:if>
541                 <xsl:if test="$typeOf008='MU'">
542                         <xsl:variable name="controlField008-30-31" select="substring($controlField008,31,2)"></xsl:variable>
543                         <xsl:if test="contains($controlField008-30-31,'b')">
544                                 <genre authority="marc">biography</genre>
545                         </xsl:if>
546                         <xsl:if test="contains($controlField008-30-31,'c')">
547                                 <genre authority="marc">conference publication</genre>
548                         </xsl:if>
549                         <xsl:if test="contains($controlField008-30-31,'d')">
550                                 <genre authority="marc">drama</genre>
551                         </xsl:if>
552                         <xsl:if test="contains($controlField008-30-31,'e')">
553                                 <genre authority="marc">essay</genre>
554                         </xsl:if>
555                         <xsl:if test="contains($controlField008-30-31,'f')">
556                                 <genre authority="marc">fiction</genre>
557                         </xsl:if>
558                         <xsl:if test="contains($controlField008-30-31,'o')">
559                                 <genre authority="marc">folktale</genre>
560                         </xsl:if>
561                         <xsl:if test="contains($controlField008-30-31,'h')">
562                                 <genre authority="marc">history</genre>
563                         </xsl:if>
564                         <xsl:if test="contains($controlField008-30-31,'k')">
565                                 <genre authority="marc">humor, satire</genre>
566                         </xsl:if>
567                         <xsl:if test="contains($controlField008-30-31,'m')">
568                                 <genre authority="marc">memoir</genre>
569                         </xsl:if>
570                         <xsl:if test="contains($controlField008-30-31,'p')">
571                                 <genre authority="marc">poetry</genre>
572                         </xsl:if>
573                         <xsl:if test="contains($controlField008-30-31,'r')">
574                                 <genre authority="marc">rehearsal</genre>
575                         </xsl:if>
576                         <xsl:if test="contains($controlField008-30-31,'g')">
577                                 <genre authority="marc">reporting</genre>
578                         </xsl:if>
579                         <xsl:if test="contains($controlField008-30-31,'s')">
580                                 <genre authority="marc">sound</genre>
581                         </xsl:if>
582                         <xsl:if test="contains($controlField008-30-31,'l')">
583                                 <genre authority="marc">speech</genre>
584                         </xsl:if>
585                 </xsl:if>
586                 <xsl:if test="$typeOf008='VM'">
587                         <xsl:variable name="controlField008-33" select="substring($controlField008,34,1)"></xsl:variable>
588                         <xsl:choose>
589                                 <xsl:when test="$controlField008-33='a'">
590                                         <genre authority="marc">art original</genre>
591                                 </xsl:when>
592                                 <xsl:when test="$controlField008-33='b'">
593                                         <genre authority="marc">kit</genre>
594                                 </xsl:when>
595                                 <xsl:when test="$controlField008-33='c'">
596                                         <genre authority="marc">art reproduction</genre>
597                                 </xsl:when>
598                                 <xsl:when test="$controlField008-33='d'">
599                                         <genre authority="marc">diorama</genre>
600                                 </xsl:when>
601                                 <xsl:when test="$controlField008-33='f'">
602                                         <genre authority="marc">filmstrip</genre>
603                                 </xsl:when>
604                                 <xsl:when test="$controlField008-33='g'">
605                                         <genre authority="marc">legal article</genre>
606                                 </xsl:when>
607                                 <xsl:when test="$controlField008-33='i'">
608                                         <genre authority="marc">picture</genre>
609                                 </xsl:when>
610                                 <xsl:when test="$controlField008-33='k'">
611                                         <genre authority="marc">graphic</genre>
612                                 </xsl:when>
613                                 <xsl:when test="$controlField008-33='l'">
614                                         <genre authority="marc">technical drawing</genre>
615                                 </xsl:when>
616                                 <xsl:when test="$controlField008-33='m'">
617                                         <genre authority="marc">motion picture</genre>
618                                 </xsl:when>
619                                 <xsl:when test="$controlField008-33='n'">
620                                         <genre authority="marc">chart</genre>
621                                 </xsl:when>
622                                 <xsl:when test="$controlField008-33='o'">
623                                         <genre authority="marc">flash card</genre>
624                                 </xsl:when>
625                                 <xsl:when test="$controlField008-33='p'">
626                                         <genre authority="marc">microscope slide</genre>
627                                 </xsl:when>
628                                 <xsl:when test="$controlField008-33='q' or marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='q']">
629                                         <genre authority="marc">model</genre>
630                                 </xsl:when>
631                                 <xsl:when test="$controlField008-33='r'">
632                                         <genre authority="marc">realia</genre>
633                                 </xsl:when>
634                                 <xsl:when test="$controlField008-33='s'">
635                                         <genre authority="marc">slide</genre>
636                                 </xsl:when>
637                                 <xsl:when test="$controlField008-33='t'">
638                                         <genre authority="marc">transparency</genre>
639                                 </xsl:when>
640                                 <xsl:when test="$controlField008-33='v'">
641                                         <genre authority="marc">videorecording</genre>
642                                 </xsl:when>
643                                 <xsl:when test="$controlField008-33='w'">
644                                         <genre authority="marc">toy</genre>
645                                 </xsl:when>
646                         </xsl:choose>
647                 </xsl:if>
648                 <xsl:for-each select="marc:datafield[@tag=655]">
649                         <genre authority="marc">
650                                 <xsl:attribute name="authority">
651                                         <xsl:value-of select="marc:subfield[@code='2']"/>
652                                 </xsl:attribute>
653                                 <xsl:call-template name="subfieldSelect">
654                                         <xsl:with-param name="codes">abvxyz</xsl:with-param>
655                                         <xsl:with-param name="delimeter">-</xsl:with-param>
656                                 </xsl:call-template>
657                         </genre>
658                 </xsl:for-each>
659                 <originInfo>
660                         <xsl:variable name="MARCpublicationCode" select="normalize-space(substring($controlField008,16,3))"></xsl:variable>
661                         <xsl:if test="translate($MARCpublicationCode,'|','')">
662                                 <place>
663                                         <placeTerm>
664                                                 <xsl:attribute name="type">code</xsl:attribute>
665                                                 <xsl:attribute name="authority">marccountry</xsl:attribute>
666                                                 <xsl:value-of select="$MARCpublicationCode"/>
667                                         </placeTerm>
668                                 </place>
669                         </xsl:if>
670                         <xsl:for-each select="marc:datafield[@tag=044]/marc:subfield[@code='c']">
671                                 <place>
672                                         <placeTerm>
673                                                 <xsl:attribute name="type">code</xsl:attribute>
674                                                 <xsl:attribute name="authority">iso3166</xsl:attribute>
675                                                 <xsl:value-of select="."/>
676                                         </placeTerm>
677                                 </place>
678                         </xsl:for-each>
679                         <xsl:for-each select="marc:datafield[@tag=260]/marc:subfield[@code='a']">
680                                 <place>
681                                         <placeTerm>
682                                                 <xsl:attribute name="type">text</xsl:attribute>
683                                                 <xsl:call-template name="chopPunctuationFront">
684                                                         <xsl:with-param name="chopString">
685                                                                 <xsl:call-template name="chopPunctuation">
686                                                                         <xsl:with-param name="chopString" select="."/>
687                                                                 </xsl:call-template>
688                                                         </xsl:with-param>
689                                                 </xsl:call-template>
690                                         </placeTerm>
691                                 </place>
692                         </xsl:for-each>
693                         <xsl:for-each select="marc:datafield[@tag=046]/marc:subfield[@code='m']">
694                                 <dateValid point="start">
695                                         <xsl:value-of select="."/>
696                                 </dateValid>
697                         </xsl:for-each>
698                         <xsl:for-each select="marc:datafield[@tag=046]/marc:subfield[@code='n']">
699                                 <dateValid point="end">
700                                         <xsl:value-of select="."/>
701                                 </dateValid>
702                         </xsl:for-each>
703                         <xsl:for-each select="marc:datafield[@tag=046]/marc:subfield[@code='j']">
704                                 <dateModified>
705                                         <xsl:value-of select="."/>
706                                 </dateModified>
707                         </xsl:for-each>
708                         <xsl:for-each select="marc:datafield[@tag=260]/marc:subfield[@code='b' or @code='c' or @code='g']">
709                                 <xsl:choose>
710                                         <xsl:when test="@code='b'">
711                                                 <publisher>
712                                                         <xsl:call-template name="chopPunctuation">
713                                                                 <xsl:with-param name="chopString" select="."/>
714                                                                 <xsl:with-param name="punctuation">
715                                                                         <xsl:text>:,;/ </xsl:text>
716                                                                 </xsl:with-param>
717                                                         </xsl:call-template>
718                                                 </publisher>
719                                         </xsl:when>
720                                         <xsl:when test="@code='c'">
721                                                 <dateIssued>
722                                                         <xsl:call-template name="chopPunctuation">
723                                                                 <xsl:with-param name="chopString" select="."/>
724                                                         </xsl:call-template>
725                                                 </dateIssued>
726                                         </xsl:when>
727                                         <xsl:when test="@code='g'">
728                                                 <dateCreated>
729                                                         <xsl:value-of select="."/>
730                                                 </dateCreated>
731                                         </xsl:when>
732                                 </xsl:choose>
733                         </xsl:for-each>
734                         <xsl:variable name="dataField260c">
735                                 <xsl:call-template name="chopPunctuation">
736                                         <xsl:with-param name="chopString" select="marc:datafield[@tag=260]/marc:subfield[@code='c']"></xsl:with-param>
737                                 </xsl:call-template>
738                         </xsl:variable>
739                         <xsl:variable name="controlField008-7-10" select="normalize-space(substring($controlField008, 8, 4))"></xsl:variable>
740                         <xsl:variable name="controlField008-11-14" select="normalize-space(substring($controlField008, 12, 4))"></xsl:variable>
741                         <xsl:variable name="controlField008-6" select="normalize-space(substring($controlField008, 7, 1))"></xsl:variable>
742                         <xsl:if test="$controlField008-6='e' or $controlField008-6='p' or $controlField008-6='r' or $controlField008-6='t' or $controlField008-6='s'">
743                                 <xsl:if test="$controlField008-7-10 and ($controlField008-7-10 != $dataField260c)">
744                                         <dateIssued encoding="marc">
745                                                 <xsl:value-of select="$controlField008-7-10"/>
746                                         </dateIssued>
747                                 </xsl:if>
748                         </xsl:if>
749                         <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'">
750                                 <xsl:if test="$controlField008-7-10">
751                                         <dateIssued encoding="marc" point="start">
752                                                 <xsl:value-of select="$controlField008-7-10"/>
753                                         </dateIssued>
754                                 </xsl:if>
755                         </xsl:if>
756                         <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'">
757                                 <xsl:if test="$controlField008-11-14">
758                                         <dateIssued encoding="marc" point="end">
759                                                 <xsl:value-of select="$controlField008-11-14"/>
760                                         </dateIssued>
761                                 </xsl:if>
762                         </xsl:if>
763                         <xsl:if test="$controlField008-6='q'">
764                                 <xsl:if test="$controlField008-7-10">
765                                         <dateIssued encoding="marc" point="start" qualifier="questionable">
766                                                 <xsl:value-of select="$controlField008-7-10"/>
767                                         </dateIssued>
768                                 </xsl:if>
769                         </xsl:if>
770                         <xsl:if test="$controlField008-6='q'">
771                                 <xsl:if test="$controlField008-11-14">
772                                         <dateIssued encoding="marc" point="end" qualifier="questionable">
773                                                 <xsl:value-of select="$controlField008-11-14"/>
774                                         </dateIssued>
775                                 </xsl:if>
776                         </xsl:if>
777                         <xsl:if test="$controlField008-6='t'">
778                                 <xsl:if test="$controlField008-11-14">
779                                         <copyrightDate encoding="marc">
780                                                 <xsl:value-of select="$controlField008-11-14"/>
781                                         </copyrightDate>
782                                 </xsl:if>
783                         </xsl:if>
784                         <xsl:for-each select="marc:datafield[@tag=033][@ind1=0 or @ind1=1]/marc:subfield[@code='a']">
785                                 <dateCaptured encoding="iso8601">
786                                         <xsl:value-of select="."/>
787                                 </dateCaptured>
788                         </xsl:for-each>
789                         <xsl:for-each select="marc:datafield[@tag=033][@ind1=2]/marc:subfield[@code='a'][1]">
790                                 <dateCaptured encoding="iso8601" point="start">
791                                         <xsl:value-of select="."/>
792                                 </dateCaptured>
793                         </xsl:for-each>
794                         <xsl:for-each select="marc:datafield[@tag=033][@ind1=2]/marc:subfield[@code='a'][2]">
795                                 <dateCaptured encoding="iso8601" point="end">
796                                         <xsl:value-of select="."/>
797                                 </dateCaptured>
798                         </xsl:for-each>
799                         <xsl:for-each select="marc:datafield[@tag=250]/marc:subfield[@code='a']">
800                                 <edition>
801                                         <xsl:value-of select="."/>
802                                 </edition>
803                         </xsl:for-each>
804                         <xsl:for-each select="marc:leader">
805                                 <issuance>
806                                         <xsl:choose>
807                                                 <xsl:when test="$leader7='a' or $leader7='c' or $leader7='d' or $leader7='m'">monographic</xsl:when>
808                                                 <xsl:when test="$leader7='b' or $leader7='i' or $leader7='s'">continuing</xsl:when>
809                                         </xsl:choose>
810                                 </issuance>
811                         </xsl:for-each>
812                         <xsl:for-each select="marc:datafield[@tag=310]|marc:datafield[@tag=321]">
813                                 <frequency>
814                                         <xsl:call-template name="subfieldSelect">
815                                                 <xsl:with-param name="codes">ab</xsl:with-param>
816                                         </xsl:call-template>
817                                 </frequency>
818                         </xsl:for-each>
819                 </originInfo>
820                 <xsl:variable name="controlField008-35-37" select="normalize-space(translate(substring($controlField008,36,3),'|#',''))"></xsl:variable>
821                 <xsl:if test="$controlField008-35-37">
822                         <language>
823                                 <languageTerm authority="iso639-2b" type="code">
824                                         <xsl:value-of select="substring($controlField008,36,3)"/>
825                                 </languageTerm>
826                         </language>
827                 </xsl:if>
828                 <xsl:for-each select="marc:datafield[@tag=041]">
829                         <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']">
830                                 <xsl:variable name="langCodes" select="."/>
831                                 <xsl:choose>
832                                         <xsl:when test="../marc:subfield[@code='2']='rfc3066'">
833                                                 <!-- not stacked but could be repeated -->
834                                                 <xsl:call-template name="rfcLanguages">
835                                                         <xsl:with-param name="nodeNum">
836                                                                 <xsl:value-of select="1"/>
837                                                         </xsl:with-param>
838                                                         <xsl:with-param name="usedLanguages">
839                                                                 <xsl:text></xsl:text>
840                                                         </xsl:with-param>
841                                                         <xsl:with-param name="controlField008-35-37">
842                                                                 <xsl:value-of select="$controlField008-35-37"></xsl:value-of>
843                                                         </xsl:with-param>
844                                                 </xsl:call-template>
845                                         </xsl:when>
846                                         <xsl:otherwise>
847                                                 <!-- iso -->
848                                                 <xsl:variable name="allLanguages">
849                                                         <xsl:copy-of select="$langCodes"></xsl:copy-of>
850                                                 </xsl:variable>
851                                                 <xsl:variable name="currentLanguage">
852                                                         <xsl:value-of select="substring($allLanguages,1,3)"></xsl:value-of>
853                                                 </xsl:variable>
854                                                 <xsl:call-template name="isoLanguage">
855                                                         <xsl:with-param name="currentLanguage">
856                                                                 <xsl:value-of select="substring($allLanguages,1,3)"></xsl:value-of>
857                                                         </xsl:with-param>
858                                                         <xsl:with-param name="remainingLanguages">
859                                                                 <xsl:value-of select="substring($allLanguages,4,string-length($allLanguages)-3)"></xsl:value-of>
860                                                         </xsl:with-param>
861                                                         <xsl:with-param name="usedLanguages">
862                                                                 <xsl:if test="$controlField008-35-37">
863                                                                         <xsl:value-of select="$controlField008-35-37"></xsl:value-of>
864                                                                 </xsl:if>
865                                                         </xsl:with-param>
866                                                 </xsl:call-template>
867                                         </xsl:otherwise>
868                                 </xsl:choose>
869                         </xsl:for-each>
870                 </xsl:for-each>
871                 <xsl:variable name="physicalDescription">
872                         <!--3.2 change tmee 007/11 -->
873                         <xsl:if test="$typeOf008='CF' and marc:controlfield[@tag=007][substring(.,12,1)='a']">
874                                 <digitalOrigin>reformatted digital</digitalOrigin>
875                         </xsl:if>
876                         <xsl:if test="$typeOf008='CF' and marc:controlfield[@tag=007][substring(.,12,1)='b']">
877                                 <digitalOrigin>digitized microfilm</digitalOrigin>
878                         </xsl:if>
879                         <xsl:if test="$typeOf008='CF' and marc:controlfield[@tag=007][substring(.,12,1)='d']">
880                                 <digitalOrigin>digitized other analog</digitalOrigin>
881                         </xsl:if>
882                         <xsl:variable name="controlField008-23" select="substring($controlField008,24,1)"></xsl:variable>
883                         <xsl:variable name="controlField008-29" select="substring($controlField008,30,1)"></xsl:variable>
884                         <xsl:variable name="check008-23">
885                                 <xsl:if test="$typeOf008='BK' or $typeOf008='MU' or $typeOf008='SE' or $typeOf008='MM'">
886                                         <xsl:value-of select="true()"></xsl:value-of>
887                                 </xsl:if>
888                         </xsl:variable>
889                         <xsl:variable name="check008-29">
890                                 <xsl:if test="$typeOf008='MP' or $typeOf008='VM'">
891                                         <xsl:value-of select="true()"></xsl:value-of>
892                                 </xsl:if>
893                         </xsl:variable>
894                         <xsl:choose>
895                                 <xsl:when test="($check008-23 and $controlField008-23='f') or ($check008-29 and $controlField008-29='f')">
896                                         <form authority="marcform">braille</form>
897                                 </xsl:when>
898                                 <xsl:when test="($controlField008-23=' ' and ($leader6='c' or $leader6='d')) or (($typeOf008='BK' or $typeOf008='SE') and ($controlField008-23=' ' or $controlField008='r'))">
899                                         <form authority="marcform">print</form>
900                                 </xsl:when>
901                                 <xsl:when test="$leader6 = 'm' or ($check008-23 and $controlField008-23='s') or ($check008-29 and $controlField008-29='s')">
902                                         <form authority="marcform">electronic</form>
903                                 </xsl:when>
904                                 <xsl:when test="($check008-23 and $controlField008-23='b') or ($check008-29 and $controlField008-29='b')">
905                                         <form authority="marcform">microfiche</form>
906                                 </xsl:when>
907                                 <xsl:when test="($check008-23 and $controlField008-23='a') or ($check008-29 and $controlField008-29='a')">
908                                         <form authority="marcform">microfilm</form>
909                                 </xsl:when>
910                         </xsl:choose>
911                         <!-- 1/04 fix -->
912                         <xsl:if test="marc:datafield[@tag=130]/marc:subfield[@code='h']">
913                                 <form authority="gmd">
914                                         <xsl:call-template name="chopBrackets">
915                                                 <xsl:with-param name="chopString">
916                                                         <xsl:value-of select="marc:datafield[@tag=130]/marc:subfield[@code='h']"></xsl:value-of>
917                                                 </xsl:with-param>
918                                         </xsl:call-template>
919                                 </form>
920                         </xsl:if>
921                         <xsl:if test="marc:datafield[@tag=240]/marc:subfield[@code='h']">
922                                 <form authority="gmd">
923                                         <xsl:call-template name="chopBrackets">
924                                                 <xsl:with-param name="chopString">
925                                                         <xsl:value-of select="marc:datafield[@tag=240]/marc:subfield[@code='h']"></xsl:value-of>
926                                                 </xsl:with-param>
927                                         </xsl:call-template>
928                                 </form>
929                         </xsl:if>
930                         <xsl:if test="marc:datafield[@tag=242]/marc:subfield[@code='h']">
931                                 <form authority="gmd">
932                                         <xsl:call-template name="chopBrackets">
933                                                 <xsl:with-param name="chopString">
934                                                         <xsl:value-of select="marc:datafield[@tag=242]/marc:subfield[@code='h']"></xsl:value-of>
935                                                 </xsl:with-param>
936                                         </xsl:call-template>
937                                 </form>
938                         </xsl:if>
939                         <xsl:if test="marc:datafield[@tag=245]/marc:subfield[@code='h']">
940                                 <form authority="gmd">
941                                         <xsl:call-template name="chopBrackets">
942                                                 <xsl:with-param name="chopString">
943                                                         <xsl:value-of select="marc:datafield[@tag=245]/marc:subfield[@code='h']"></xsl:value-of>
944                                                 </xsl:with-param>
945                                         </xsl:call-template>
946                                 </form>
947                         </xsl:if>
948                         <xsl:if test="marc:datafield[@tag=246]/marc:subfield[@code='h']">
949                                 <form authority="gmd">
950                                         <xsl:call-template name="chopBrackets">
951                                                 <xsl:with-param name="chopString">
952                                                         <xsl:value-of select="marc:datafield[@tag=246]/marc:subfield[@code='h']"></xsl:value-of>
953                                                 </xsl:with-param>
954                                         </xsl:call-template>
955                                 </form>
956                         </xsl:if>
957                         <xsl:if test="marc:datafield[@tag=730]/marc:subfield[@code='h']">
958                                 <form authority="gmd">
959                                         <xsl:call-template name="chopBrackets">
960                                                 <xsl:with-param name="chopString">
961                                                         <xsl:value-of select="marc:datafield[@tag=730]/marc:subfield[@code='h']"></xsl:value-of>
962                                                 </xsl:with-param>
963                                         </xsl:call-template>
964                                 </form>
965                         </xsl:if>
966                         <xsl:for-each select="marc:datafield[@tag=256]/marc:subfield[@code='a']">
967                                 <form>
968                                         <xsl:value-of select="."></xsl:value-of>
969                                 </form>
970                         </xsl:for-each>
971                         <xsl:for-each select="marc:controlfield[@tag=007][substring(text(),1,1)='c']">
972                                 <xsl:choose>
973                                         <xsl:when test="substring(text(),14,1)='a'">
974                                                 <reformattingQuality>access</reformattingQuality>
975                                         </xsl:when>
976                                         <xsl:when test="substring(text(),14,1)='p'">
977                                                 <reformattingQuality>preservation</reformattingQuality>
978                                         </xsl:when>
979                                         <xsl:when test="substring(text(),14,1)='r'">
980                                                 <reformattingQuality>replacement</reformattingQuality>
981                                         </xsl:when>
982                                 </xsl:choose>
983                         </xsl:for-each>
984                         <!--3.2 change tmee 007/01 -->
985                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='b']">
986                                 <form authority="smd">chip cartridge</form>
987                         </xsl:if>
988                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='c']">
989                                 <form authority="smd">computer optical disc cartridge</form>
990                         </xsl:if>
991                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='j']">
992                                 <form authority="smd">magnetic disc</form>
993                         </xsl:if>
994                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='m']">
995                                 <form authority="smd">magneto-optical disc</form>
996                         </xsl:if>
997                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='o']">
998                                 <form authority="smd">optical disc</form>
999                         </xsl:if>
1000                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='r']">
1001                                 <form authority="smd">remote</form>
1002                         </xsl:if>
1003                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='a']">
1004                                 <form authority="smd">tape cartridge</form>
1005                         </xsl:if>
1006                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='f']">
1007                                 <form authority="smd">tape cassette</form>
1008                         </xsl:if>
1009                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='c'][substring(text(),2,1)='h']">
1010                                 <form authority="smd">tape reel</form>
1011                         </xsl:if>
1012                         
1013                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='d'][substring(text(),2,1)='a']">
1014                                 <form authority="smd">celestial globe</form>
1015                         </xsl:if>
1016                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='d'][substring(text(),2,1)='e']">
1017                                 <form authority="smd">earth moon globe</form>
1018                         </xsl:if>
1019                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='d'][substring(text(),2,1)='b']">
1020                                 <form authority="smd">planetary or lunar globe</form>
1021                         </xsl:if>
1022                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='d'][substring(text(),2,1)='c']">
1023                                 <form authority="smd">terrestrial globe</form>
1024                         </xsl:if>
1025                         
1026                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='o'][substring(text(),2,1)='o']">
1027                                 <form authority="smd">kit</form>
1028                         </xsl:if>
1029                         
1030                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='d']">
1031                                 <form authority="smd">atlas</form>
1032                         </xsl:if>
1033                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='g']">
1034                                 <form authority="smd">diagram</form>
1035                         </xsl:if>
1036                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='j']">
1037                                 <form authority="smd">map</form>
1038                         </xsl:if>
1039                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='q']">
1040                                 <form authority="smd">model</form>
1041                         </xsl:if>
1042                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='k']">
1043                                 <form authority="smd">profile</form>
1044                         </xsl:if>
1045                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='r']">
1046                                 <form authority="smd">remote-sensing image</form>
1047                         </xsl:if>
1048                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='s']">
1049                                 <form authority="smd">section</form>
1050                         </xsl:if>
1051                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='a'][substring(text(),2,1)='y']">
1052                                 <form authority="smd">view</form>
1053                         </xsl:if>
1054                         
1055                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='a']">
1056                                 <form authority="smd">aperture card</form>
1057                         </xsl:if>
1058                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='e']">
1059                                 <form authority="smd">microfiche</form>
1060                         </xsl:if>
1061                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='f']">
1062                                 <form authority="smd">microfiche cassette</form>
1063                         </xsl:if>
1064                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='b']">
1065                                 <form authority="smd">microfilm cartridge</form>
1066                         </xsl:if>
1067                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='c']">
1068                                 <form authority="smd">microfilm cassette</form>
1069                         </xsl:if>
1070                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='d']">
1071                                 <form authority="smd">microfilm reel</form>
1072                         </xsl:if>
1073                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='h'][substring(text(),2,1)='g']">
1074                                 <form authority="smd">microopaque</form>
1075                         </xsl:if>
1076                         
1077                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='m'][substring(text(),2,1)='c']">
1078                                 <form authority="smd">film cartridge</form>
1079                         </xsl:if>
1080                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='m'][substring(text(),2,1)='f']">
1081                                 <form authority="smd">film cassette</form>
1082                         </xsl:if>
1083                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='m'][substring(text(),2,1)='r']">
1084                                 <form authority="smd">film reel</form>
1085                         </xsl:if>
1086                         
1087                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='n']">
1088                                 <form authority="smd">chart</form>
1089                         </xsl:if>
1090                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='c']">
1091                                 <form authority="smd">collage</form>
1092                         </xsl:if>
1093                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='d']">
1094                                 <form authority="smd">drawing</form>
1095                         </xsl:if>
1096                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='o']">
1097                                 <form authority="smd">flash card</form>
1098                         </xsl:if>
1099                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='e']">
1100                                 <form authority="smd">painting</form>
1101                         </xsl:if>
1102                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='f']">
1103                                 <form authority="smd">photomechanical print</form>
1104                         </xsl:if>
1105                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='g']">
1106                                 <form authority="smd">photonegative</form>
1107                         </xsl:if>
1108                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='h']">
1109                                 <form authority="smd">photoprint</form>
1110                         </xsl:if>
1111                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='i']">
1112                                 <form authority="smd">picture</form>
1113                         </xsl:if>
1114                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='j']">
1115                                 <form authority="smd">print</form>
1116                         </xsl:if>
1117                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='k'][substring(text(),2,1)='l']">
1118                                 <form authority="smd">technical drawing</form>
1119                         </xsl:if>
1120                         
1121                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='q'][substring(text(),2,1)='q']">
1122                                 <form authority="smd">notated music</form>
1123                         </xsl:if>
1124                         
1125                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='d']">
1126                                 <form authority="smd">filmslip</form>
1127                         </xsl:if>
1128                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='c']">
1129                                 <form authority="smd">filmstrip cartridge</form>
1130                         </xsl:if>
1131                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='o']">
1132                                 <form authority="smd">filmstrip roll</form>
1133                         </xsl:if>
1134                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='f']">
1135                                 <form authority="smd">other filmstrip type</form>
1136                         </xsl:if>
1137                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='s']">
1138                                 <form authority="smd">slide</form>
1139                         </xsl:if>
1140                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='g'][substring(text(),2,1)='t']">
1141                                 <form authority="smd">transparency</form>
1142                         </xsl:if>
1143                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='r'][substring(text(),2,1)='r']">
1144                                 <form authority="smd">remote-sensing image</form>
1145                         </xsl:if>
1146                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='e']">
1147                                 <form authority="smd">cylinder</form>
1148                         </xsl:if>
1149                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='q']">
1150                                 <form authority="smd">roll</form>
1151                         </xsl:if>
1152                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='g']">
1153                                 <form authority="smd">sound cartridge</form>
1154                         </xsl:if>
1155                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='s']">
1156                                 <form authority="smd">sound cassette</form>
1157                         </xsl:if>
1158                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='d']">
1159                                 <form authority="smd">sound disc</form>
1160                         </xsl:if>
1161                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='t']">
1162                                 <form authority="smd">sound-tape reel</form>
1163                         </xsl:if>
1164                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='i']">
1165                                 <form authority="smd">sound-track film</form>
1166                         </xsl:if>
1167                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='s'][substring(text(),2,1)='w']">
1168                                 <form authority="smd">wire recording</form>
1169                         </xsl:if>
1170                         
1171                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='f'][substring(text(),2,1)='c']">
1172                                 <form authority="smd">braille</form>
1173                         </xsl:if>
1174                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='f'][substring(text(),2,1)='b']">
1175                                 <form authority="smd">combination</form>
1176                         </xsl:if>
1177                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='f'][substring(text(),2,1)='a']">
1178                                 <form authority="smd">moon</form>
1179                         </xsl:if>
1180                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='f'][substring(text(),2,1)='d']">
1181                                 <form authority="smd">tactile, with no writing system</form>
1182                         </xsl:if>
1183                         
1184                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='t'][substring(text(),2,1)='c']">
1185                                 <form authority="smd">braille</form>
1186                         </xsl:if>
1187                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='t'][substring(text(),2,1)='b']">
1188                                 <form authority="smd">large print</form>
1189                         </xsl:if>
1190                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='t'][substring(text(),2,1)='a']">
1191                                 <form authority="smd">regular print</form>
1192                         </xsl:if>
1193                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='t'][substring(text(),2,1)='d']">
1194                                 <form authority="smd">text in looseleaf binder</form>
1195                         </xsl:if>
1196                         
1197                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='v'][substring(text(),2,1)='c']">
1198                                 <form authority="smd">videocartridge</form>
1199                         </xsl:if>
1200                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='v'][substring(text(),2,1)='f']">
1201                                 <form authority="smd">videocassette</form>
1202                         </xsl:if>
1203                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='v'][substring(text(),2,1)='d']">
1204                                 <form authority="smd">videodisc</form>
1205                         </xsl:if>
1206                         <xsl:if test="marc:controlfield[@tag=007][substring(text(),1,1)='v'][substring(text(),2,1)='r']">
1207                                 <form authority="smd">videoreel</form>
1208                         </xsl:if>
1209                         
1210                         <xsl:for-each select="marc:datafield[@tag=856]/marc:subfield[@code='q'][string-length(.)>1]">
1211                                 <internetMediaType>
1212                                         <xsl:value-of select="."></xsl:value-of>
1213                                 </internetMediaType>
1214                         </xsl:for-each>
1215                         <xsl:for-each select="marc:datafield[@tag=300]">
1216                                 <extent>
1217                                         <xsl:call-template name="subfieldSelect">
1218                                                 <xsl:with-param name="codes">abce</xsl:with-param>
1219                                         </xsl:call-template>
1220                                 </extent>
1221                         </xsl:for-each>
1222                 </xsl:variable>
1223                 <xsl:if test="string-length(normalize-space($physicalDescription))">
1224                         <physicalDescription>
1225                                 <xsl:copy-of select="$physicalDescription"></xsl:copy-of>
1226                         </physicalDescription>
1227                 </xsl:if>
1228                 <xsl:for-each select="marc:datafield[@tag=520]">
1229                         <abstract>
1230                                 <xsl:call-template name="uri"></xsl:call-template>
1231                                 <xsl:call-template name="subfieldSelect">
1232                                         <xsl:with-param name="codes">ab</xsl:with-param>
1233                                 </xsl:call-template>
1234                         </abstract>
1235                 </xsl:for-each>
1236                 <xsl:for-each select="marc:datafield[@tag=505]">
1237                         <tableOfContents>
1238                                 <xsl:call-template name="uri"></xsl:call-template>
1239                                 <xsl:call-template name="subfieldSelect">
1240                                         <xsl:with-param name="codes">agrt</xsl:with-param>
1241                                 </xsl:call-template>
1242                         </tableOfContents>
1243                 </xsl:for-each>
1244                 <xsl:for-each select="marc:datafield[@tag=521]">
1245                         <targetAudience>
1246                                 <xsl:call-template name="subfieldSelect">
1247                                         <xsl:with-param name="codes">ab</xsl:with-param>
1248                                 </xsl:call-template>
1249                         </targetAudience>
1250                 </xsl:for-each>
1251                 <xsl:if test="$typeOf008='BK' or $typeOf008='CF' or $typeOf008='MU' or $typeOf008='VM'">
1252                         <xsl:variable name="controlField008-22" select="substring($controlField008,23,1)"></xsl:variable>
1253                         <xsl:choose>
1254                                 <!-- 01/04 fix -->
1255                                 <xsl:when test="$controlField008-22='d'">
1256                                         <targetAudience authority="marctarget">adolescent</targetAudience>
1257                                 </xsl:when>
1258                                 <xsl:when test="$controlField008-22='e'">
1259                                         <targetAudience authority="marctarget">adult</targetAudience>
1260                                 </xsl:when>
1261                                 <xsl:when test="$controlField008-22='g'">
1262                                         <targetAudience authority="marctarget">general</targetAudience>
1263                                 </xsl:when>
1264                                 <xsl:when test="$controlField008-22='b' or $controlField008-22='c' or $controlField008-22='j'">
1265                                         <targetAudience authority="marctarget">juvenile</targetAudience>
1266                                 </xsl:when>
1267                                 <xsl:when test="$controlField008-22='a'">
1268                                         <targetAudience authority="marctarget">preschool</targetAudience>
1269                                 </xsl:when>
1270                                 <xsl:when test="$controlField008-22='f'">
1271                                         <targetAudience authority="marctarget">specialized</targetAudience>
1272                                 </xsl:when>
1273                         </xsl:choose>
1274                 </xsl:if>
1275                 <xsl:for-each select="marc:datafield[@tag=245]/marc:subfield[@code='c']">
1276                         <note type="statement of responsibility">
1277                                 <xsl:value-of select="."></xsl:value-of>
1278                         </note>
1279                 </xsl:for-each>
1280                 <xsl:for-each select="marc:datafield[@tag=500]">
1281                         <note>
1282                                 <xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
1283                                 <xsl:call-template name="uri"></xsl:call-template>
1284                         </note>
1285                 </xsl:for-each>
1286                 
1287                 <!--3.2 change tmee additional note fields-->
1288                 
1289                 <xsl:for-each select="marc:datafield[@tag=506]">
1290                         <note type="restrictions">
1291                                 <xsl:call-template name="uri"></xsl:call-template>
1292                                 <xsl:variable name="str">
1293                                         <xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
1294                                                 <xsl:value-of select="."></xsl:value-of>
1295                                                 <xsl:text> </xsl:text>
1296                                         </xsl:for-each>
1297                                 </xsl:variable>
1298                                 <xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
1299                         </note>
1300                 </xsl:for-each>
1301                 
1302                 <xsl:for-each select="marc:datafield[@tag=510]">
1303                         <note  type="citation/reference">
1304                                 <xsl:call-template name="uri"></xsl:call-template>
1305                                 <xsl:variable name="str">
1306                                         <xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
1307                                                 <xsl:value-of select="."></xsl:value-of>
1308                                                 <xsl:text> </xsl:text>
1309                                         </xsl:for-each>
1310                                 </xsl:variable>
1311                                 <xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
1312                         </note>
1313                 </xsl:for-each>
1314                 
1315                         
1316                 <xsl:for-each select="marc:datafield[@tag=511]">
1317                         <note type="performers">
1318                                 <xsl:call-template name="uri"></xsl:call-template>
1319                                 <xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
1320                         </note>
1321                 </xsl:for-each>
1322                 <xsl:for-each select="marc:datafield[@tag=518]">
1323                         <note type="venue">
1324                                 <xsl:call-template name="uri"></xsl:call-template>
1325                                 <xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
1326                         </note>
1327                 </xsl:for-each>
1328                 
1329                 <xsl:for-each select="marc:datafield[@tag=530]">
1330                         <note  type="additional physical form">
1331                                 <xsl:call-template name="uri"></xsl:call-template>
1332                                 <xsl:variable name="str">
1333                                         <xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
1334                                                 <xsl:value-of select="."></xsl:value-of>
1335                                                 <xsl:text> </xsl:text>
1336                                         </xsl:for-each>
1337                                 </xsl:variable>
1338                                 <xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
1339                         </note>
1340                 </xsl:for-each>
1341                 
1342                 <xsl:for-each select="marc:datafield[@tag=533]">
1343                         <note  type="reproduction">
1344                                 <xsl:call-template name="uri"></xsl:call-template>
1345                                 <xsl:variable name="str">
1346                                         <xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
1347                                                 <xsl:value-of select="."></xsl:value-of>
1348                                                 <xsl:text> </xsl:text>
1349                                         </xsl:for-each>
1350                                 </xsl:variable>
1351                                 <xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
1352                         </note>
1353                 </xsl:for-each>
1354                 
1355                 <xsl:for-each select="marc:datafield[@tag=534]">
1356                         <note  type="original version">
1357                                 <xsl:call-template name="uri"></xsl:call-template>
1358                                 <xsl:variable name="str">
1359                                         <xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
1360                                                 <xsl:value-of select="."></xsl:value-of>
1361                                                 <xsl:text> </xsl:text>
1362                                         </xsl:for-each>
1363                                 </xsl:variable>
1364                                 <xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
1365                         </note>
1366                 </xsl:for-each>
1367                 
1368                 <xsl:for-each select="marc:datafield[@tag=538]">
1369                         <note  type="system details">
1370                                 <xsl:call-template name="uri"></xsl:call-template>
1371                                 <xsl:variable name="str">
1372                                         <xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
1373                                                 <xsl:value-of select="."></xsl:value-of>
1374                                                 <xsl:text> </xsl:text>
1375                                         </xsl:for-each>
1376                                 </xsl:variable>
1377                                 <xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
1378                         </note>
1379                 </xsl:for-each>
1380                 
1381                 <xsl:for-each select="marc:datafield[@tag=583]">
1382                         <note type="action">
1383                                 <xsl:call-template name="uri"></xsl:call-template>
1384                                 <xsl:variable name="str">
1385                                         <xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
1386                                                 <xsl:value-of select="."></xsl:value-of>
1387                                                 <xsl:text> </xsl:text>
1388                                         </xsl:for-each>
1389                                 </xsl:variable>
1390                                 <xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
1391                         </note>
1392                 </xsl:for-each>
1393                 
1394
1395                 
1396                 
1397                 
1398                 <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]">
1399                         <note>
1400                                 <xsl:call-template name="uri"></xsl:call-template>
1401                                 <xsl:variable name="str">
1402                                         <xsl:for-each select="marc:subfield[@code!='6' or @code!='8']">
1403                                                 <xsl:value-of select="."></xsl:value-of>
1404                                                 <xsl:text> </xsl:text>
1405                                         </xsl:for-each>
1406                                 </xsl:variable>
1407                                 <xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
1408                         </note>
1409                 </xsl:for-each>
1410                 <xsl:for-each select="marc:datafield[@tag=034][marc:subfield[@code='d' or @code='e' or @code='f' or @code='g']]">
1411                         <subject>
1412                                 <cartographics>
1413                                         <coordinates>
1414                                                 <xsl:call-template name="subfieldSelect">
1415                                                         <xsl:with-param name="codes">defg</xsl:with-param>
1416                                                 </xsl:call-template>
1417                                         </coordinates>
1418                                 </cartographics>
1419                         </subject>
1420                 </xsl:for-each>
1421                 <xsl:for-each select="marc:datafield[@tag=043]">
1422                         <subject>
1423                                 <xsl:for-each select="marc:subfield[@code='a' or @code='b' or @code='c']">
1424                                         <geographicCode>
1425                                                 <xsl:attribute name="authority">
1426                                                         <xsl:if test="@code='a'">
1427                                                                 <xsl:text>marcgac</xsl:text>
1428                                                         </xsl:if>
1429                                                         <xsl:if test="@code='b'">
1430                                                                 <xsl:value-of select="following-sibling::marc:subfield[@code=2]"></xsl:value-of>
1431                                                         </xsl:if>
1432                                                         <xsl:if test="@code='c'">
1433                                                                 <xsl:text>iso3166</xsl:text>
1434                                                         </xsl:if>
1435                                                 </xsl:attribute>
1436                                                 <xsl:value-of select="self::marc:subfield"></xsl:value-of>
1437                                         </geographicCode>
1438                                 </xsl:for-each>
1439                         </subject>
1440                 </xsl:for-each>
1441                 <!-- tmee 2006/11/27 -->
1442                 <xsl:for-each select="marc:datafield[@tag=255]">
1443                         <subject>
1444                                 <xsl:for-each select="marc:subfield[@code='a' or @code='b' or @code='c']">
1445                                 <cartographics>
1446                                         <xsl:if test="@code='a'">
1447                                                 <scale>
1448                                                         <xsl:value-of select="."></xsl:value-of>
1449                                                 </scale>
1450                                         </xsl:if>
1451                                         <xsl:if test="@code='b'">
1452                                                 <projection>
1453                                                         <xsl:value-of select="."></xsl:value-of>
1454                                                 </projection>
1455                                         </xsl:if>
1456                                         <xsl:if test="@code='c'">
1457                                                 <coordinates>
1458                                                         <xsl:value-of select="."></xsl:value-of>
1459                                                 </coordinates>
1460                                         </xsl:if>
1461                                 </cartographics>
1462                                 </xsl:for-each>
1463                         </subject>
1464                 </xsl:for-each>
1465                                 
1466                 <xsl:apply-templates select="marc:datafield[653 >= @tag and @tag >= 600]"></xsl:apply-templates>
1467                 <xsl:apply-templates select="marc:datafield[@tag=656]"></xsl:apply-templates>
1468                 <xsl:for-each select="marc:datafield[@tag=752]">
1469                         <subject>
1470                                 <hierarchicalGeographic>
1471                                         <xsl:for-each select="marc:subfield[@code='a']">
1472                                                 <country>
1473                                                         <xsl:call-template name="chopPunctuation">
1474                                                                 <xsl:with-param name="chopString" select="."></xsl:with-param>
1475                                                         </xsl:call-template>
1476                                                 </country>
1477                                         </xsl:for-each>
1478                                         <xsl:for-each select="marc:subfield[@code='b']">
1479                                                 <state>
1480                                                         <xsl:call-template name="chopPunctuation">
1481                                                                 <xsl:with-param name="chopString" select="."></xsl:with-param>
1482                                                         </xsl:call-template>
1483                                                 </state>
1484                                         </xsl:for-each>
1485                                         <xsl:for-each select="marc:subfield[@code='c']">
1486                                                 <county>
1487                                                         <xsl:call-template name="chopPunctuation">
1488                                                                 <xsl:with-param name="chopString" select="."></xsl:with-param>
1489                                                         </xsl:call-template>
1490                                                 </county>
1491                                         </xsl:for-each>
1492                                         <xsl:for-each select="marc:subfield[@code='d']">
1493                                                 <city>
1494                                                         <xsl:call-template name="chopPunctuation">
1495                                                                 <xsl:with-param name="chopString" select="."></xsl:with-param>
1496                                                         </xsl:call-template>
1497                                                 </city>
1498                                         </xsl:for-each>
1499                                 </hierarchicalGeographic>
1500                         </subject>
1501                 </xsl:for-each>
1502                 <xsl:for-each select="marc:datafield[@tag=045][marc:subfield[@code='b']]">
1503                         <subject>
1504                                 <xsl:choose>
1505                                         <xsl:when test="@ind1=2">
1506                                                 <temporal encoding="iso8601" point="start">
1507                                                         <xsl:call-template name="chopPunctuation">
1508                                                                 <xsl:with-param name="chopString">
1509                                                                         <xsl:value-of select="marc:subfield[@code='b'][1]"></xsl:value-of>
1510                                                                 </xsl:with-param>
1511                                                         </xsl:call-template>
1512                                                 </temporal>
1513                                                 <temporal encoding="iso8601" point="end">
1514                                                         <xsl:call-template name="chopPunctuation">
1515                                                                 <xsl:with-param name="chopString">
1516                                                                         <xsl:value-of select="marc:subfield[@code='b'][2]"></xsl:value-of>
1517                                                                 </xsl:with-param>
1518                                                         </xsl:call-template>
1519                                                 </temporal>
1520                                         </xsl:when>
1521                                         <xsl:otherwise>
1522                                                 <xsl:for-each select="marc:subfield[@code='b']">
1523                                                         <temporal encoding="iso8601">
1524                                                                 <xsl:call-template name="chopPunctuation">
1525                                                                         <xsl:with-param name="chopString" select="."></xsl:with-param>
1526                                                                 </xsl:call-template>
1527                                                         </temporal>
1528                                                 </xsl:for-each>
1529                                         </xsl:otherwise>
1530                                 </xsl:choose>
1531                         </subject>
1532                 </xsl:for-each>
1533                 <xsl:for-each select="marc:datafield[@tag=050]">
1534                         <xsl:for-each select="marc:subfield[@code='b']">
1535                                 <classification authority="lcc">
1536                                         <xsl:if test="../marc:subfield[@code='3']">
1537                                                 <xsl:attribute name="displayLabel">
1538                                                         <xsl:value-of select="../marc:subfield[@code='3']"></xsl:value-of>
1539                                                 </xsl:attribute>
1540                                         </xsl:if>
1541                                         <xsl:value-of select="preceding-sibling::marc:subfield[@code='a'][1]"></xsl:value-of>
1542                                         <xsl:text> </xsl:text>
1543                                         <xsl:value-of select="text()"></xsl:value-of>
1544                                 </classification>
1545                         </xsl:for-each>
1546                         <xsl:for-each select="marc:subfield[@code='a'][not(following-sibling::marc:subfield[@code='b'])]">
1547                                 <classification authority="lcc">
1548                                         <xsl:if test="../marc:subfield[@code='3']">
1549                                                 <xsl:attribute name="displayLabel">
1550                                                         <xsl:value-of select="../marc:subfield[@code='3']"></xsl:value-of>
1551                                                 </xsl:attribute>
1552                                         </xsl:if>
1553                                         <xsl:value-of select="text()"></xsl:value-of>
1554                                 </classification>
1555                         </xsl:for-each>
1556                 </xsl:for-each>
1557                 <xsl:for-each select="marc:datafield[@tag=082]">
1558                         <classification authority="ddc">
1559                                 <xsl:if test="marc:subfield[@code='2']">
1560                                         <xsl:attribute name="edition">
1561                                                 <xsl:value-of select="marc:subfield[@code='2']"></xsl:value-of>
1562                                         </xsl:attribute>
1563                                 </xsl:if>
1564                                 <xsl:call-template name="subfieldSelect">
1565                                         <xsl:with-param name="codes">ab</xsl:with-param>
1566                                 </xsl:call-template>
1567                         </classification>
1568                 </xsl:for-each>
1569                 <xsl:for-each select="marc:datafield[@tag=080]">
1570                         <classification authority="udc">
1571                                 <xsl:call-template name="subfieldSelect">
1572                                         <xsl:with-param name="codes">abx</xsl:with-param>
1573                                 </xsl:call-template>
1574                         </classification>
1575                 </xsl:for-each>
1576                 <xsl:for-each select="marc:datafield[@tag=060]">
1577                         <classification authority="nlm">
1578                                 <xsl:call-template name="subfieldSelect">
1579                                         <xsl:with-param name="codes">ab</xsl:with-param>
1580                                 </xsl:call-template>
1581                         </classification>
1582                 </xsl:for-each>
1583                 <xsl:for-each select="marc:datafield[@tag=086][@ind1=0]">
1584                         <classification authority="sudocs">
1585                                 <xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
1586                         </classification>
1587                 </xsl:for-each>
1588                 <xsl:for-each select="marc:datafield[@tag=086][@ind1=1]">
1589                         <classification authority="candoc">
1590                                 <xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
1591                         </classification>
1592                 </xsl:for-each>
1593                 <xsl:for-each select="marc:datafield[@tag=086]">
1594                         <classification>
1595                                 <xsl:attribute name="authority">
1596                                         <xsl:value-of select="marc:subfield[@code='2']"></xsl:value-of>
1597                                 </xsl:attribute>
1598                                 <xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
1599                         </classification>
1600                 </xsl:for-each>
1601                 <xsl:for-each select="marc:datafield[@tag=084]">
1602                         <classification>
1603                                 <xsl:attribute name="authority">
1604                                         <xsl:value-of select="marc:subfield[@code='2']"></xsl:value-of>
1605                                 </xsl:attribute>
1606                                 <xsl:call-template name="subfieldSelect">
1607                                         <xsl:with-param name="codes">ab</xsl:with-param>
1608                                 </xsl:call-template>
1609                         </classification>
1610                 </xsl:for-each>
1611                 <xsl:for-each select="marc:datafield[@tag=440]">
1612                         <relatedItem type="series">
1613                                 <titleInfo>
1614                                         <title>
1615                                                 <xsl:call-template name="chopPunctuation">
1616                                                         <xsl:with-param name="chopString">
1617                                                                 <xsl:call-template name="subfieldSelect">
1618                                                                         <xsl:with-param name="codes">av</xsl:with-param>
1619                                                                 </xsl:call-template>
1620                                                         </xsl:with-param>
1621                                                 </xsl:call-template>
1622                                         </title>
1623                                         <xsl:call-template name="part"></xsl:call-template>
1624                                 </titleInfo>
1625                         </relatedItem>
1626                 </xsl:for-each>
1627                 <xsl:for-each select="marc:datafield[@tag=490][@ind1=0]">
1628                         <relatedItem type="series">
1629                                 <titleInfo>
1630                                         <title>
1631                                                 <xsl:call-template name="chopPunctuation">
1632                                                         <xsl:with-param name="chopString">
1633                                                                 <xsl:call-template name="subfieldSelect">
1634                                                                         <xsl:with-param name="codes">av</xsl:with-param>
1635                                                                 </xsl:call-template>
1636                                                         </xsl:with-param>
1637                                                 </xsl:call-template>
1638                                         </title>
1639                                         <xsl:call-template name="part"></xsl:call-template>
1640                                 </titleInfo>
1641                         </relatedItem>
1642                 </xsl:for-each>
1643                 <xsl:for-each select="marc:datafield[@tag=510]">
1644                         <relatedItem type="isReferencedBy">
1645                                 <note>
1646                                         <xsl:call-template name="subfieldSelect">
1647                                                 <xsl:with-param name="codes">abcx3</xsl:with-param>
1648                                         </xsl:call-template>
1649                                 </note>
1650                         </relatedItem>
1651                 </xsl:for-each>
1652                 <xsl:for-each select="marc:datafield[@tag=534]">
1653                         <relatedItem type="original">
1654                                 <xsl:call-template name="relatedTitle"></xsl:call-template>
1655                                 <xsl:call-template name="relatedName"></xsl:call-template>
1656                                 <xsl:if test="marc:subfield[@code='b' or @code='c']">
1657                                         <originInfo>
1658                                                 <xsl:for-each select="marc:subfield[@code='c']">
1659                                                         <publisher>
1660                                                                 <xsl:value-of select="."></xsl:value-of>
1661                                                         </publisher>
1662                                                 </xsl:for-each>
1663                                                 <xsl:for-each select="marc:subfield[@code='b']">
1664                                                         <edition>
1665                                                                 <xsl:value-of select="."></xsl:value-of>
1666                                                         </edition>
1667                                                 </xsl:for-each>
1668                                         </originInfo>
1669                                 </xsl:if>
1670                                 <xsl:call-template name="relatedIdentifierISSN"></xsl:call-template>
1671                                 <xsl:for-each select="marc:subfield[@code='z']">
1672                                         <identifier type="isbn">
1673                                                 <xsl:value-of select="."></xsl:value-of>
1674                                         </identifier>
1675                                 </xsl:for-each>
1676                                 <xsl:call-template name="relatedNote"></xsl:call-template>
1677                         </relatedItem>
1678                 </xsl:for-each>
1679                 <xsl:for-each select="marc:datafield[@tag=700][marc:subfield[@code='t']]">
1680                         <relatedItem>
1681                                 <xsl:call-template name="constituentOrRelatedType"></xsl:call-template>
1682                                 <titleInfo>
1683                                         <title>
1684                                                 <xsl:call-template name="chopPunctuation">
1685                                                         <xsl:with-param name="chopString">
1686                                                                 <xsl:call-template name="specialSubfieldSelect">
1687                                                                         <xsl:with-param name="anyCodes">tfklmorsv</xsl:with-param>
1688                                                                         <xsl:with-param name="axis">t</xsl:with-param>
1689                                                                         <xsl:with-param name="afterCodes">g</xsl:with-param>
1690                                                                 </xsl:call-template>
1691                                                         </xsl:with-param>
1692                                                 </xsl:call-template>
1693                                         </title>
1694                                         <xsl:call-template name="part"></xsl:call-template>
1695                                 </titleInfo>
1696                                 <name type="personal">
1697                                         <namePart>
1698                                                 <xsl:call-template name="specialSubfieldSelect">
1699                                                         <xsl:with-param name="anyCodes">aq</xsl:with-param>
1700                                                         <xsl:with-param name="axis">t</xsl:with-param>
1701                                                         <xsl:with-param name="beforeCodes">g</xsl:with-param>
1702                                                 </xsl:call-template>
1703                                         </namePart>
1704                                         <xsl:call-template name="termsOfAddress"></xsl:call-template>
1705                                         <xsl:call-template name="nameDate"></xsl:call-template>
1706                                         <xsl:call-template name="role"></xsl:call-template>
1707                                 </name>
1708                                 <xsl:call-template name="relatedForm"></xsl:call-template>
1709                                 <xsl:call-template name="relatedIdentifierISSN"></xsl:call-template>
1710                         </relatedItem>
1711                 </xsl:for-each>
1712                 <xsl:for-each select="marc:datafield[@tag=710][marc:subfield[@code='t']]">
1713                         <relatedItem>
1714                                 <xsl:call-template name="constituentOrRelatedType"></xsl:call-template>
1715                                 <titleInfo>
1716                                         <title>
1717                                                 <xsl:call-template name="chopPunctuation">
1718                                                         <xsl:with-param name="chopString">
1719                                                                 <xsl:call-template name="specialSubfieldSelect">
1720                                                                         <xsl:with-param name="anyCodes">tfklmorsv</xsl:with-param>
1721                                                                         <xsl:with-param name="axis">t</xsl:with-param>
1722                                                                         <xsl:with-param name="afterCodes">dg</xsl:with-param>
1723                                                                 </xsl:call-template>
1724                                                         </xsl:with-param>
1725                                                 </xsl:call-template>
1726                                         </title>
1727                                         <xsl:call-template name="relatedPartNumName"></xsl:call-template>
1728                                 </titleInfo>
1729                                 <name type="corporate">
1730                                         <xsl:for-each select="marc:subfield[@code='a']">
1731                                                 <namePart>
1732                                                         <xsl:value-of select="."></xsl:value-of>
1733                                                 </namePart>
1734                                         </xsl:for-each>
1735                                         <xsl:for-each select="marc:subfield[@code='b']">
1736                                                 <namePart>
1737                                                         <xsl:value-of select="."></xsl:value-of>
1738                                                 </namePart>
1739                                         </xsl:for-each>
1740                                         <xsl:variable name="tempNamePart">
1741                                                 <xsl:call-template name="specialSubfieldSelect">
1742                                                         <xsl:with-param name="anyCodes">c</xsl:with-param>
1743                                                         <xsl:with-param name="axis">t</xsl:with-param>
1744                                                         <xsl:with-param name="beforeCodes">dgn</xsl:with-param>
1745                                                 </xsl:call-template>
1746                                         </xsl:variable>
1747                                         <xsl:if test="normalize-space($tempNamePart)">
1748                                                 <namePart>
1749                                                         <xsl:value-of select="$tempNamePart"></xsl:value-of>
1750                                                 </namePart>
1751                                         </xsl:if>
1752                                         <xsl:call-template name="role"></xsl:call-template>
1753                                 </name>
1754                                 <xsl:call-template name="relatedForm"></xsl:call-template>
1755                                 <xsl:call-template name="relatedIdentifierISSN"></xsl:call-template>
1756                         </relatedItem>
1757                 </xsl:for-each>
1758                 <xsl:for-each select="marc:datafield[@tag=711][marc:subfield[@code='t']]">
1759                         <relatedItem>
1760                                 <xsl:call-template name="constituentOrRelatedType"></xsl:call-template>
1761                                 <titleInfo>
1762                                         <title>
1763                                                 <xsl:call-template name="chopPunctuation">
1764                                                         <xsl:with-param name="chopString">
1765                                                                 <xsl:call-template name="specialSubfieldSelect">
1766                                                                         <xsl:with-param name="anyCodes">tfklsv</xsl:with-param>
1767                                                                         <xsl:with-param name="axis">t</xsl:with-param>
1768                                                                         <xsl:with-param name="afterCodes">g</xsl:with-param>
1769                                                                 </xsl:call-template>
1770                                                         </xsl:with-param>
1771                                                 </xsl:call-template>
1772                                         </title>
1773                                         <xsl:call-template name="relatedPartNumName"></xsl:call-template>
1774                                 </titleInfo>
1775                                 <name type="conference">
1776                                         <namePart>
1777                                                 <xsl:call-template name="specialSubfieldSelect">
1778                                                         <xsl:with-param name="anyCodes">aqdc</xsl:with-param>
1779                                                         <xsl:with-param name="axis">t</xsl:with-param>
1780                                                         <xsl:with-param name="beforeCodes">gn</xsl:with-param>
1781                                                 </xsl:call-template>
1782                                         </namePart>
1783                                 </name>
1784                                 <xsl:call-template name="relatedForm"></xsl:call-template>
1785                                 <xsl:call-template name="relatedIdentifierISSN"></xsl:call-template>
1786                         </relatedItem>
1787                 </xsl:for-each>
1788                 <xsl:for-each select="marc:datafield[@tag=730][@ind2=2]">
1789                         <relatedItem>
1790                                 <xsl:call-template name="constituentOrRelatedType"></xsl:call-template>
1791                                 <titleInfo>
1792                                         <title>
1793                                                 <xsl:call-template name="chopPunctuation">
1794                                                         <xsl:with-param name="chopString">
1795                                                                 <xsl:call-template name="subfieldSelect">
1796                                                                         <xsl:with-param name="codes">adfgklmorsv</xsl:with-param>
1797                                                                 </xsl:call-template>
1798                                                         </xsl:with-param>
1799                                                 </xsl:call-template>
1800                                         </title>
1801                                         <xsl:call-template name="part"></xsl:call-template>
1802                                 </titleInfo>
1803                                 <xsl:call-template name="relatedForm"></xsl:call-template>
1804                                 <xsl:call-template name="relatedIdentifierISSN"></xsl:call-template>
1805                         </relatedItem>
1806                 </xsl:for-each>
1807                 <xsl:for-each select="marc:datafield[@tag=740][@ind2=2]">
1808                         <relatedItem>
1809                                 <xsl:call-template name="constituentOrRelatedType"></xsl:call-template>
1810                                 <titleInfo>
1811                                         <title>
1812                                                 <xsl:call-template name="chopPunctuation">
1813                                                         <xsl:with-param name="chopString">
1814                                                                 <xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
1815                                                         </xsl:with-param>
1816                                                 </xsl:call-template>
1817                                         </title>
1818                                         <xsl:call-template name="part"></xsl:call-template>
1819                                 </titleInfo>
1820                                 <xsl:call-template name="relatedForm"></xsl:call-template>
1821                         </relatedItem>
1822                 </xsl:for-each>
1823                 <xsl:for-each select="marc:datafield[@tag=760]|marc:datafield[@tag=762]">
1824                         <relatedItem type="series">
1825                                 <xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
1826                         </relatedItem>
1827                 </xsl:for-each>
1828                 <xsl:for-each select="marc:datafield[@tag=765]|marc:datafield[@tag=767]|marc:datafield[@tag=777]|marc:datafield[@tag=787]">
1829                         <relatedItem>
1830                                 <xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
1831                         </relatedItem>
1832                 </xsl:for-each>
1833                 <xsl:for-each select="marc:datafield[@tag=775]">
1834                         <relatedItem type="otherVersion">
1835                                 <xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
1836                         </relatedItem>
1837                 </xsl:for-each>
1838                 <xsl:for-each select="marc:datafield[@tag=770]|marc:datafield[@tag=774]">
1839                         <relatedItem type="constituent">
1840                                 <xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
1841                         </relatedItem>
1842                 </xsl:for-each>
1843                 <xsl:for-each select="marc:datafield[@tag=772]|marc:datafield[@tag=773]">
1844                         <relatedItem type="host">
1845                                 <xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
1846                         </relatedItem>
1847                 </xsl:for-each>
1848                 <xsl:for-each select="marc:datafield[@tag=776]">
1849                         <relatedItem type="otherFormat">
1850                                 <xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
1851                         </relatedItem>
1852                 </xsl:for-each>
1853                 <xsl:for-each select="marc:datafield[@tag=780]">
1854                         <relatedItem type="preceding">
1855                                 <xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
1856                         </relatedItem>
1857                 </xsl:for-each>
1858                 <xsl:for-each select="marc:datafield[@tag=785]">
1859                         <relatedItem type="succeeding">
1860                                 <xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
1861                         </relatedItem>
1862                 </xsl:for-each>
1863                 <xsl:for-each select="marc:datafield[@tag=786]">
1864                         <relatedItem type="original">
1865                                 <xsl:call-template name="relatedItem76X-78X"></xsl:call-template>
1866                         </relatedItem>
1867                 </xsl:for-each>
1868                 <xsl:for-each select="marc:datafield[@tag=800]">
1869                         <relatedItem type="series">
1870                                 <titleInfo>
1871                                         <title>
1872                                                 <xsl:call-template name="chopPunctuation">
1873                                                         <xsl:with-param name="chopString">
1874                                                                 <xsl:call-template name="specialSubfieldSelect">
1875                                                                         <xsl:with-param name="anyCodes">tfklmorsv</xsl:with-param>
1876                                                                         <xsl:with-param name="axis">t</xsl:with-param>
1877                                                                         <xsl:with-param name="afterCodes">g</xsl:with-param>
1878                                                                 </xsl:call-template>
1879                                                         </xsl:with-param>
1880                                                 </xsl:call-template>
1881                                         </title>
1882                                         <xsl:call-template name="part"></xsl:call-template>
1883                                 </titleInfo>
1884                                 <name type="personal">
1885                                         <namePart>
1886                                                 <xsl:call-template name="chopPunctuation">
1887                                                         <xsl:with-param name="chopString">
1888                                                                 <xsl:call-template name="specialSubfieldSelect">
1889                                                                         <xsl:with-param name="anyCodes">aq</xsl:with-param>
1890                                                                         <xsl:with-param name="axis">t</xsl:with-param>
1891                                                                         <xsl:with-param name="beforeCodes">g</xsl:with-param>
1892                                                                 </xsl:call-template>
1893                                                         </xsl:with-param>
1894                                                 </xsl:call-template>
1895                                         </namePart>
1896                                         <xsl:call-template name="termsOfAddress"></xsl:call-template>
1897                                         <xsl:call-template name="nameDate"></xsl:call-template>
1898                                         <xsl:call-template name="role"></xsl:call-template>
1899                                 </name>
1900                                 <xsl:call-template name="relatedForm"></xsl:call-template>
1901                         </relatedItem>
1902                 </xsl:for-each>
1903                 <xsl:for-each select="marc:datafield[@tag=810]">
1904                         <relatedItem type="series">
1905                                 <titleInfo>
1906                                         <title>
1907                                                 <xsl:call-template name="chopPunctuation">
1908                                                         <xsl:with-param name="chopString">
1909                                                                 <xsl:call-template name="specialSubfieldSelect">
1910                                                                         <xsl:with-param name="anyCodes">tfklmorsv</xsl:with-param>
1911                                                                         <xsl:with-param name="axis">t</xsl:with-param>
1912                                                                         <xsl:with-param name="afterCodes">dg</xsl:with-param>
1913                                                                 </xsl:call-template>
1914                                                         </xsl:with-param>
1915                                                 </xsl:call-template>
1916                                         </title>
1917                                         <xsl:call-template name="relatedPartNumName"></xsl:call-template>
1918                                 </titleInfo>
1919                                 <name type="corporate">
1920                                         <xsl:for-each select="marc:subfield[@code='a']">
1921                                                 <namePart>
1922                                                         <xsl:value-of select="."></xsl:value-of>
1923                                                 </namePart>
1924                                         </xsl:for-each>
1925                                         <xsl:for-each select="marc:subfield[@code='b']">
1926                                                 <namePart>
1927                                                         <xsl:value-of select="."></xsl:value-of>
1928                                                 </namePart>
1929                                         </xsl:for-each>
1930                                         <namePart>
1931                                                 <xsl:call-template name="specialSubfieldSelect">
1932                                                         <xsl:with-param name="anyCodes">c</xsl:with-param>
1933                                                         <xsl:with-param name="axis">t</xsl:with-param>
1934                                                         <xsl:with-param name="beforeCodes">dgn</xsl:with-param>
1935                                                 </xsl:call-template>
1936                                         </namePart>
1937                                         <xsl:call-template name="role"></xsl:call-template>
1938                                 </name>
1939                                 <xsl:call-template name="relatedForm"></xsl:call-template>
1940                         </relatedItem>
1941                 </xsl:for-each>
1942                 <xsl:for-each select="marc:datafield[@tag=811]">
1943                         <relatedItem type="series">
1944                                 <titleInfo>
1945                                         <title>
1946                                                 <xsl:call-template name="chopPunctuation">
1947                                                         <xsl:with-param name="chopString">
1948                                                                 <xsl:call-template name="specialSubfieldSelect">
1949                                                                         <xsl:with-param name="anyCodes">tfklsv</xsl:with-param>
1950                                                                         <xsl:with-param name="axis">t</xsl:with-param>
1951                                                                         <xsl:with-param name="afterCodes">g</xsl:with-param>
1952                                                                 </xsl:call-template>
1953                                                         </xsl:with-param>
1954                                                 </xsl:call-template>
1955                                         </title>
1956                                         <xsl:call-template name="relatedPartNumName"/>
1957                                 </titleInfo>
1958                                 <name type="conference">
1959                                         <namePart>
1960                                                 <xsl:call-template name="specialSubfieldSelect">
1961                                                         <xsl:with-param name="anyCodes">aqdc</xsl:with-param>
1962                                                         <xsl:with-param name="axis">t</xsl:with-param>
1963                                                         <xsl:with-param name="beforeCodes">gn</xsl:with-param>
1964                                                 </xsl:call-template>
1965                                         </namePart>
1966                                         <xsl:call-template name="role"/>
1967                                 </name>
1968                                 <xsl:call-template name="relatedForm"/>
1969                         </relatedItem>
1970                 </xsl:for-each>
1971                 <xsl:for-each select="marc:datafield[@tag='830']">
1972                         <relatedItem type="series">
1973                                 <titleInfo>
1974                                         <title>
1975                                                 <xsl:call-template name="chopPunctuation">
1976                                                         <xsl:with-param name="chopString">
1977                                                                 <xsl:call-template name="subfieldSelect">
1978                                                                         <xsl:with-param name="codes">adfgklmorsv</xsl:with-param>
1979                                                                 </xsl:call-template>
1980                                                         </xsl:with-param>
1981                                                 </xsl:call-template>
1982                                         </title>
1983                                         <xsl:call-template name="part"/>
1984                                 </titleInfo>
1985                                 <xsl:call-template name="relatedForm"/>
1986                         </relatedItem>
1987                 </xsl:for-each>
1988                 <xsl:for-each select="marc:datafield[@tag='856'][@ind2='2']/marc:subfield[@code='q']">
1989                         <relatedItem>
1990                                 <internetMediaType>
1991                                         <xsl:value-of select="."/>
1992                                 </internetMediaType>
1993                         </relatedItem>
1994                 </xsl:for-each>
1995                 <xsl:for-each select="marc:datafield[@tag='020']">
1996                         <xsl:call-template name="isInvalid">
1997                                 <xsl:with-param name="type">isbn</xsl:with-param>
1998                         </xsl:call-template>
1999                         <xsl:if test="marc:subfield[@code='a']">
2000                                 <identifier type="isbn">
2001                                         <xsl:value-of select="marc:subfield[@code='a']"/>
2002                                 </identifier>
2003                         </xsl:if>
2004                 </xsl:for-each>
2005                 <xsl:for-each select="marc:datafield[@tag='024'][@ind1='0']">
2006                         <xsl:call-template name="isInvalid">
2007                                 <xsl:with-param name="type">isrc</xsl:with-param>
2008                         </xsl:call-template>
2009                         <xsl:if test="marc:subfield[@code='a']">
2010                                 <identifier type="isrc">
2011                                         <xsl:value-of select="marc:subfield[@code='a']"/>
2012                                 </identifier>
2013                         </xsl:if>
2014                 </xsl:for-each>
2015                 <xsl:for-each select="marc:datafield[@tag='024'][@ind1='2']">
2016                         <xsl:call-template name="isInvalid">
2017                                 <xsl:with-param name="type">ismn</xsl:with-param>
2018                         </xsl:call-template>
2019                         <xsl:if test="marc:subfield[@code='a']">
2020                                 <identifier type="ismn">
2021                                         <xsl:value-of select="marc:subfield[@code='a']"/>
2022                                 </identifier>
2023                         </xsl:if>
2024                 </xsl:for-each>
2025                 <xsl:for-each select="marc:datafield[@tag='024'][@ind1='4']">
2026                         <xsl:call-template name="isInvalid">
2027                                 <xsl:with-param name="type">sici</xsl:with-param>
2028                         </xsl:call-template>
2029                         <identifier type="sici">
2030                                 <xsl:call-template name="subfieldSelect">
2031                                         <xsl:with-param name="codes">ab</xsl:with-param>
2032                                 </xsl:call-template>
2033                         </identifier>
2034                 </xsl:for-each>
2035                 <xsl:for-each select="marc:datafield[@tag='022']">
2036                         <xsl:call-template name="isInvalid">
2037                                 <xsl:with-param name="type">issn</xsl:with-param>
2038                         </xsl:call-template>
2039                         <identifier type="issn">
2040                                 <xsl:value-of select="marc:subfield[@code='a']"/>
2041                         </identifier>
2042                 </xsl:for-each>
2043                 <xsl:for-each select="marc:datafield[@tag='010']">
2044                         <xsl:call-template name="isInvalid">
2045                                 <xsl:with-param name="type">lccn</xsl:with-param>
2046                         </xsl:call-template>
2047                         <identifier type="lccn">
2048                                 <xsl:value-of select="normalize-space(marc:subfield[@code='a'])"/>
2049                         </identifier>
2050                 </xsl:for-each>
2051                 <xsl:for-each select="marc:datafield[@tag='028']">
2052                         <identifier>
2053                                 <xsl:attribute name="type">
2054                                         <xsl:choose>
2055                                                 <xsl:when test="@ind1='0'">issue number</xsl:when>
2056                                                 <xsl:when test="@ind1='1'">matrix number</xsl:when>
2057                                                 <xsl:when test="@ind1='2'">music plate</xsl:when>
2058                                                 <xsl:when test="@ind1='3'">music publisher</xsl:when>
2059                                                 <xsl:when test="@ind1='4'">videorecording identifier</xsl:when>
2060                                         </xsl:choose>
2061                                 </xsl:attribute>
2062                                 <!--<xsl:call-template name="isInvalid"/>--> <!-- no $z in 028 -->
2063                                 <xsl:call-template name="subfieldSelect">
2064                                         <xsl:with-param name="codes">
2065                                                 <xsl:choose>
2066                                                         <xsl:when test="@ind1='0'">ba</xsl:when>
2067                                                         <xsl:otherwise>ab</xsl:otherwise>
2068                                                 </xsl:choose>
2069                                         </xsl:with-param>
2070                                 </xsl:call-template>
2071                         </identifier>
2072                 </xsl:for-each>
2073                 <xsl:for-each select="marc:datafield[@tag='037']">
2074                         <identifier type="stock number">
2075                                 <!--<xsl:call-template name="isInvalid"/>--> <!-- no $z in 037 -->
2076                                 <xsl:call-template name="subfieldSelect">
2077                                         <xsl:with-param name="codes">ab</xsl:with-param>
2078                                 </xsl:call-template>
2079                         </identifier>
2080                 </xsl:for-each>
2081                 <xsl:for-each select="marc:datafield[@tag='856'][marc:subfield[@code='u']]">
2082                         <identifier>
2083                                 <xsl:attribute name="type">
2084                                         <xsl:choose>
2085                                                 <xsl:when test="starts-with(marc:subfield[@code='u'],'urn:doi') or starts-with(marc:subfield[@code='u'],'doi')">doi</xsl:when>
2086                                                 <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>
2087                                                 <xsl:otherwise>uri</xsl:otherwise>
2088                                         </xsl:choose>
2089                                 </xsl:attribute>
2090                                 <xsl:choose>
2091                                         <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') ">
2092                                                 <xsl:value-of select="concat('hdl:',substring-after(marc:subfield[@code='u'],'http://hdl.loc.gov/'))"></xsl:value-of>
2093                                         </xsl:when>
2094                                         <xsl:otherwise>
2095                                                 <xsl:value-of select="marc:subfield[@code='u']"></xsl:value-of>
2096                                         </xsl:otherwise>
2097                                 </xsl:choose>
2098                         </identifier>
2099                         <xsl:if test="starts-with(marc:subfield[@code='u'],'urn:hdl') or starts-with(marc:subfield[@code='u'],'hdl')">
2100                                 <identifier type="hdl">
2101                                         <xsl:if test="marc:subfield[@code='y' or @code='3' or @code='z']">
2102                                                 <xsl:attribute name="displayLabel">
2103                                                         <xsl:call-template name="subfieldSelect">
2104                                                                 <xsl:with-param name="codes">y3z</xsl:with-param>
2105                                                         </xsl:call-template>
2106                                                 </xsl:attribute>
2107                                         </xsl:if>
2108                                         <xsl:value-of select="concat('hdl:',substring-after(marc:subfield[@code='u'],'http://hdl.loc.gov/'))"></xsl:value-of>
2109                                 </identifier>
2110                         </xsl:if>
2111                 </xsl:for-each>
2112                 <xsl:for-each select="marc:datafield[@tag=024][@ind1=1]">
2113                         <identifier type="upc">
2114                                 <xsl:call-template name="isInvalid"/>
2115                                 <xsl:value-of select="marc:subfield[@code='a']"/>
2116                         </identifier>
2117                 </xsl:for-each>
2118                 <!-- 1/04 fix added $y -->
2119                 <xsl:for-each select="marc:datafield[@tag=856][marc:subfield[@code='u']]">
2120                         <location>
2121                                 <url>
2122                                         <xsl:if test="marc:subfield[@code='y' or @code='3']">
2123                                                 <xsl:attribute name="displayLabel">
2124                                                         <xsl:call-template name="subfieldSelect">
2125                                                                 <xsl:with-param name="codes">y3</xsl:with-param>
2126                                                         </xsl:call-template>
2127                                                 </xsl:attribute>
2128                                         </xsl:if>
2129                                         <xsl:if test="marc:subfield[@code='z' ]">
2130                                                 <xsl:attribute name="note">
2131                                                         <xsl:call-template name="subfieldSelect">
2132                                                                 <xsl:with-param name="codes">z</xsl:with-param>
2133                                                         </xsl:call-template>
2134                                                 </xsl:attribute>
2135                                         </xsl:if>
2136                                         <xsl:value-of select="marc:subfield[@code='u']"></xsl:value-of>
2137
2138                                 </url>
2139                         </location>
2140                 </xsl:for-each>
2141                         
2142                         <!-- 3.2 change tmee 856z  -->
2143
2144                 
2145                 <xsl:for-each select="marc:datafield[@tag=852]">
2146                         <location>
2147                                 <physicalLocation>
2148                                         <xsl:call-template name="displayLabel"></xsl:call-template>
2149                                         <xsl:call-template name="subfieldSelect">
2150                                                 <xsl:with-param name="codes">abje</xsl:with-param>
2151                                         </xsl:call-template>
2152                                 </physicalLocation>
2153                         </location>
2154                 </xsl:for-each>
2155                 <xsl:for-each select="marc:datafield[@tag=506]">
2156                         <accessCondition type="restrictionOnAccess">
2157                                 <xsl:call-template name="subfieldSelect">
2158                                         <xsl:with-param name="codes">abcd35</xsl:with-param>
2159                                 </xsl:call-template>
2160                         </accessCondition>
2161                 </xsl:for-each>
2162                 <xsl:for-each select="marc:datafield[@tag=540]">
2163                         <accessCondition type="useAndReproduction">
2164                                 <xsl:call-template name="subfieldSelect">
2165                                         <xsl:with-param name="codes">abcde35</xsl:with-param>
2166                                 </xsl:call-template>
2167                         </accessCondition>
2168                 </xsl:for-each>
2169                 <recordInfo>
2170                         <xsl:for-each select="marc:datafield[@tag=040]">
2171                                 <recordContentSource authority="marcorg">
2172                                         <xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
2173                                 </recordContentSource>
2174                         </xsl:for-each>
2175                         <xsl:for-each select="marc:controlfield[@tag=008]">
2176                                 <recordCreationDate encoding="marc">
2177                                         <xsl:value-of select="substring(.,1,6)"></xsl:value-of>
2178                                 </recordCreationDate>
2179                         </xsl:for-each>
2180                         <xsl:for-each select="marc:controlfield[@tag=005]">
2181                                 <recordChangeDate encoding="iso8601">
2182                                         <xsl:value-of select="."></xsl:value-of>
2183                                 </recordChangeDate>
2184                         </xsl:for-each>
2185                         <xsl:for-each select="marc:controlfield[@tag=001]">
2186                                 <recordIdentifier>
2187                                         <xsl:if test="../marc:controlfield[@tag=003]">
2188                                                 <xsl:attribute name="source">
2189                                                         <xsl:value-of select="../marc:controlfield[@tag=003]"></xsl:value-of>
2190                                                 </xsl:attribute>
2191                                         </xsl:if>
2192                                         <xsl:value-of select="."></xsl:value-of>
2193                                 </recordIdentifier>
2194                         </xsl:for-each>
2195                         <xsl:for-each select="marc:datafield[@tag=040]/marc:subfield[@code='b']">
2196                                 <languageOfCataloging>
2197                                         <languageTerm authority="iso639-2b" type="code">
2198                                                 <xsl:value-of select="."></xsl:value-of>
2199                                         </languageTerm>
2200                                 </languageOfCataloging>
2201                         </xsl:for-each>
2202                 </recordInfo>
2203         </xsl:template>
2204         <xsl:template name="displayForm">
2205                 <xsl:for-each select="marc:subfield[@code='c']">
2206                         <displayForm>
2207                                 <xsl:value-of select="."></xsl:value-of>
2208                         </displayForm>
2209                 </xsl:for-each>
2210         </xsl:template>
2211         <xsl:template name="affiliation">
2212                 <xsl:for-each select="marc:subfield[@code='u']">
2213                         <affiliation>
2214                                 <xsl:value-of select="."></xsl:value-of>
2215                         </affiliation>
2216                 </xsl:for-each>
2217         </xsl:template>
2218         <xsl:template name="uri">
2219                 <xsl:for-each select="marc:subfield[@code='u']">
2220                         <xsl:attribute name="xlink:href">
2221                                 <xsl:value-of select="."></xsl:value-of>
2222                         </xsl:attribute>
2223                 </xsl:for-each>
2224         </xsl:template>
2225         <xsl:template name="role">
2226                 <xsl:for-each select="marc:subfield[@code='e']">
2227                         <role>
2228                                 <roleTerm type="text">
2229                                         <xsl:value-of select="."></xsl:value-of>
2230                                 </roleTerm>
2231                         </role>
2232                 </xsl:for-each>
2233                 <xsl:for-each select="marc:subfield[@code='4']">
2234                         <role>
2235                                 <roleTerm authority="marcrelator" type="code">
2236                                         <xsl:value-of select="."></xsl:value-of>
2237                                 </roleTerm>
2238                         </role>
2239                 </xsl:for-each>
2240         </xsl:template>
2241         <xsl:template name="part">
2242                 <xsl:variable name="partNumber">
2243                         <xsl:call-template name="specialSubfieldSelect">
2244                                 <xsl:with-param name="axis">n</xsl:with-param>
2245                                 <xsl:with-param name="anyCodes">n</xsl:with-param>
2246                                 <xsl:with-param name="afterCodes">fgkdlmor</xsl:with-param>
2247                         </xsl:call-template>
2248                 </xsl:variable>
2249                 <xsl:variable name="partName">
2250                         <xsl:call-template name="specialSubfieldSelect">
2251                                 <xsl:with-param name="axis">p</xsl:with-param>
2252                                 <xsl:with-param name="anyCodes">p</xsl:with-param>
2253                                 <xsl:with-param name="afterCodes">fgkdlmor</xsl:with-param>
2254                         </xsl:call-template>
2255                 </xsl:variable>
2256                 <xsl:if test="string-length(normalize-space($partNumber))">
2257                         <partNumber>
2258                                 <xsl:call-template name="chopPunctuation">
2259                                         <xsl:with-param name="chopString" select="$partNumber"></xsl:with-param>
2260                                 </xsl:call-template>
2261                         </partNumber>
2262                 </xsl:if>
2263                 <xsl:if test="string-length(normalize-space($partName))">
2264                         <partName>
2265                                 <xsl:call-template name="chopPunctuation">
2266                                         <xsl:with-param name="chopString" select="$partName"></xsl:with-param>
2267                                 </xsl:call-template>
2268                         </partName>
2269                 </xsl:if>
2270         </xsl:template>
2271         <xsl:template name="relatedPart">
2272                 <xsl:if test="@tag=773">
2273                         <xsl:for-each select="marc:subfield[@code='g']">
2274                                 <part>
2275                                         <text>
2276                                                 <xsl:value-of select="."></xsl:value-of>
2277                                         </text>
2278                                 </part>
2279                         </xsl:for-each>
2280                         <xsl:for-each select="marc:subfield[@code='q']">
2281                                 <part>
2282                                         <xsl:call-template name="parsePart"></xsl:call-template>
2283                                 </part>
2284                         </xsl:for-each>
2285                 </xsl:if>
2286         </xsl:template>
2287         <xsl:template name="relatedPartNumName">
2288                 <xsl:variable name="partNumber">
2289                         <xsl:call-template name="specialSubfieldSelect">
2290                                 <xsl:with-param name="axis">g</xsl:with-param>
2291                                 <xsl:with-param name="anyCodes">g</xsl:with-param>
2292                                 <xsl:with-param name="afterCodes">pst</xsl:with-param>
2293                         </xsl:call-template>
2294                 </xsl:variable>
2295                 <xsl:variable name="partName">
2296                         <xsl:call-template name="specialSubfieldSelect">
2297                                 <xsl:with-param name="axis">p</xsl:with-param>
2298                                 <xsl:with-param name="anyCodes">p</xsl:with-param>
2299                                 <xsl:with-param name="afterCodes">fgkdlmor</xsl:with-param>
2300                         </xsl:call-template>
2301                 </xsl:variable>
2302                 <xsl:if test="string-length(normalize-space($partNumber))">
2303                         <partNumber>
2304                                 <xsl:value-of select="$partNumber"></xsl:value-of>
2305                         </partNumber>
2306                 </xsl:if>
2307                 <xsl:if test="string-length(normalize-space($partName))">
2308                         <partName>
2309                                 <xsl:value-of select="$partName"></xsl:value-of>
2310                         </partName>
2311                 </xsl:if>
2312         </xsl:template>
2313         <xsl:template name="relatedName">
2314                 <xsl:for-each select="marc:subfield[@code='a']">
2315                         <name>
2316                                 <namePart>
2317                                         <xsl:value-of select="."></xsl:value-of>
2318                                 </namePart>
2319                         </name>
2320                 </xsl:for-each>
2321         </xsl:template>
2322         <xsl:template name="relatedForm">
2323                 <xsl:for-each select="marc:subfield[@code='h']">
2324                         <physicalDescription>
2325                                 <form>
2326                                         <xsl:value-of select="."></xsl:value-of>
2327                                 </form>
2328                         </physicalDescription>
2329                 </xsl:for-each>
2330         </xsl:template>
2331         <xsl:template name="relatedExtent">
2332                 <xsl:for-each select="marc:subfield[@code='h']">
2333                         <physicalDescription>
2334                                 <extent>
2335                                         <xsl:value-of select="."></xsl:value-of>
2336                                 </extent>
2337                         </physicalDescription>
2338                 </xsl:for-each>
2339         </xsl:template>
2340         <xsl:template name="relatedNote">
2341                 <xsl:for-each select="marc:subfield[@code='n']">
2342                         <note>
2343                                 <xsl:value-of select="."></xsl:value-of>
2344                         </note>
2345                 </xsl:for-each>
2346         </xsl:template>
2347         <xsl:template name="relatedSubject">
2348                 <xsl:for-each select="marc:subfield[@code='j']">
2349                         <subject>
2350                                 <temporal encoding="iso8601">
2351                                         <xsl:call-template name="chopPunctuation">
2352                                                 <xsl:with-param name="chopString" select="."></xsl:with-param>
2353                                         </xsl:call-template>
2354                                 </temporal>
2355                         </subject>
2356                 </xsl:for-each>
2357         </xsl:template>
2358         <xsl:template name="relatedIdentifierISSN">
2359                 <xsl:for-each select="marc:subfield[@code='x']">
2360                         <identifier type="issn">
2361                                 <xsl:value-of select="."></xsl:value-of>
2362                         </identifier>
2363                 </xsl:for-each>
2364         </xsl:template>
2365         <xsl:template name="relatedIdentifierLocal">
2366                 <xsl:for-each select="marc:subfield[@code='w']">
2367                         <identifier type="local">
2368                                 <xsl:value-of select="."></xsl:value-of>
2369                         </identifier>
2370                 </xsl:for-each>
2371         </xsl:template>
2372         <xsl:template name="relatedIdentifier">
2373                 <xsl:for-each select="marc:subfield[@code='o']">
2374                         <identifier>
2375                                 <xsl:value-of select="."></xsl:value-of>
2376                         </identifier>
2377                 </xsl:for-each>
2378         </xsl:template>
2379         <xsl:template name="relatedItem76X-78X">
2380                 <xsl:call-template name="displayLabel"></xsl:call-template>
2381                 <xsl:call-template name="relatedTitle76X-78X"></xsl:call-template>
2382                 <xsl:call-template name="relatedName"></xsl:call-template>
2383                 <xsl:call-template name="relatedOriginInfo"></xsl:call-template>
2384                 <xsl:call-template name="relatedLanguage"></xsl:call-template>
2385                 <xsl:call-template name="relatedExtent"></xsl:call-template>
2386                 <xsl:call-template name="relatedNote"></xsl:call-template>
2387                 <xsl:call-template name="relatedSubject"></xsl:call-template>
2388                 <xsl:call-template name="relatedIdentifier"></xsl:call-template>
2389                 <xsl:call-template name="relatedIdentifierISSN"></xsl:call-template>
2390                 <xsl:call-template name="relatedIdentifierLocal"></xsl:call-template>
2391                 <xsl:call-template name="relatedPart"></xsl:call-template>
2392         </xsl:template>
2393         <xsl:template name="subjectGeographicZ">
2394                 <geographic>
2395                         <xsl:call-template name="chopPunctuation">
2396                                 <xsl:with-param name="chopString" select="."></xsl:with-param>
2397                         </xsl:call-template>
2398                 </geographic>
2399         </xsl:template>
2400         <xsl:template name="subjectTemporalY">
2401                 <temporal>
2402                         <xsl:call-template name="chopPunctuation">
2403                                 <xsl:with-param name="chopString" select="."></xsl:with-param>
2404                         </xsl:call-template>
2405                 </temporal>
2406         </xsl:template>
2407         <xsl:template name="subjectTopic">
2408                 <topic>
2409                         <xsl:call-template name="chopPunctuation">
2410                                 <xsl:with-param name="chopString" select="."></xsl:with-param>
2411                         </xsl:call-template>
2412                 </topic>
2413         </xsl:template> 
2414         <!-- 3.2 change tmee 6xx $v genre -->
2415         <xsl:template name="subjectGenre">
2416                 <genre>
2417                         <xsl:call-template name="chopPunctuation">
2418                                 <xsl:with-param name="chopString" select="."></xsl:with-param>
2419                         </xsl:call-template>
2420                 </genre>
2421         </xsl:template>
2422         
2423         <xsl:template name="nameABCDN">
2424                 <xsl:for-each select="marc:subfield[@code='a']">
2425                         <namePart>
2426                                 <xsl:call-template name="chopPunctuation">
2427                                         <xsl:with-param name="chopString" select="."></xsl:with-param>
2428                                 </xsl:call-template>
2429                         </namePart>
2430                 </xsl:for-each>
2431                 <xsl:for-each select="marc:subfield[@code='b']">
2432                         <namePart>
2433                                 <xsl:value-of select="."></xsl:value-of>
2434                         </namePart>
2435                 </xsl:for-each>
2436                 <xsl:if test="marc:subfield[@code='c'] or marc:subfield[@code='d'] or marc:subfield[@code='n']">
2437                         <namePart>
2438                                 <xsl:call-template name="subfieldSelect">
2439                                         <xsl:with-param name="codes">cdn</xsl:with-param>
2440                                 </xsl:call-template>
2441                         </namePart>
2442                 </xsl:if>
2443         </xsl:template>
2444         <xsl:template name="nameABCDQ">
2445                 <namePart>
2446                         <xsl:call-template name="chopPunctuation">
2447                                 <xsl:with-param name="chopString">
2448                                         <xsl:call-template name="subfieldSelect">
2449                                                 <xsl:with-param name="codes">aq</xsl:with-param>
2450                                         </xsl:call-template>
2451                                 </xsl:with-param>
2452                                 <xsl:with-param name="punctuation">
2453                                         <xsl:text>:,;/ </xsl:text>
2454                                 </xsl:with-param>
2455                         </xsl:call-template>
2456                 </namePart>
2457                 <xsl:call-template name="termsOfAddress"></xsl:call-template>
2458                 <xsl:call-template name="nameDate"></xsl:call-template>
2459         </xsl:template>
2460         <xsl:template name="nameACDEQ">
2461                 <namePart>
2462                         <xsl:call-template name="subfieldSelect">
2463                                 <xsl:with-param name="codes">acdeq</xsl:with-param>
2464                         </xsl:call-template>
2465                 </namePart>
2466         </xsl:template>
2467         <xsl:template name="constituentOrRelatedType">
2468                 <xsl:if test="@ind2=2">
2469                         <xsl:attribute name="type">constituent</xsl:attribute>
2470                 </xsl:if>
2471         </xsl:template>
2472         <xsl:template name="relatedTitle">
2473                 <xsl:for-each select="marc:subfield[@code='t']">
2474                         <titleInfo>
2475                                 <title>
2476                                         <xsl:call-template name="chopPunctuation">
2477                                                 <xsl:with-param name="chopString">
2478                                                         <xsl:value-of select="."></xsl:value-of>
2479                                                 </xsl:with-param>
2480                                         </xsl:call-template>
2481                                 </title>
2482                         </titleInfo>
2483                 </xsl:for-each>
2484         </xsl:template>
2485         <xsl:template name="relatedTitle76X-78X">
2486                 <xsl:for-each select="marc:subfield[@code='t']">
2487                         <titleInfo>
2488                                 <title>
2489                                         <xsl:call-template name="chopPunctuation">
2490                                                 <xsl:with-param name="chopString">
2491                                                         <xsl:value-of select="."></xsl:value-of>
2492                                                 </xsl:with-param>
2493                                         </xsl:call-template>
2494                                 </title>
2495                                 <xsl:if test="marc:datafield[@tag!=773]and marc:subfield[@code='g']">
2496                                         <xsl:call-template name="relatedPartNumName"></xsl:call-template>
2497                                 </xsl:if>
2498                         </titleInfo>
2499                 </xsl:for-each>
2500                 <xsl:for-each select="marc:subfield[@code='p']">
2501                         <titleInfo type="abbreviated">
2502                                 <title>
2503                                         <xsl:call-template name="chopPunctuation">
2504                                                 <xsl:with-param name="chopString">
2505                                                         <xsl:value-of select="."></xsl:value-of>
2506                                                 </xsl:with-param>
2507                                         </xsl:call-template>
2508                                 </title>
2509                                 <xsl:if test="marc:datafield[@tag!=773]and marc:subfield[@code='g']">
2510                                         <xsl:call-template name="relatedPartNumName"></xsl:call-template>
2511                                 </xsl:if>
2512                         </titleInfo>
2513                 </xsl:for-each>
2514                 <xsl:for-each select="marc:subfield[@code='s']">
2515                         <titleInfo type="uniform">
2516                                 <title>
2517                                         <xsl:call-template name="chopPunctuation">
2518                                                 <xsl:with-param name="chopString">
2519                                                         <xsl:value-of select="."></xsl:value-of>
2520                                                 </xsl:with-param>
2521                                         </xsl:call-template>
2522                                 </title>
2523                                 <xsl:if test="marc:datafield[@tag!=773]and marc:subfield[@code='g']">
2524                                         <xsl:call-template name="relatedPartNumName"></xsl:call-template>
2525                                 </xsl:if>
2526                         </titleInfo>
2527                 </xsl:for-each>
2528         </xsl:template>
2529         <xsl:template name="relatedOriginInfo">
2530                 <xsl:if test="marc:subfield[@code='b' or @code='d'] or marc:subfield[@code='f']">
2531                         <originInfo>
2532                                 <xsl:if test="@tag=775">
2533                                         <xsl:for-each select="marc:subfield[@code='f']">
2534                                                 <place>
2535                                                         <placeTerm>
2536                                                                 <xsl:attribute name="type">code</xsl:attribute>
2537                                                                 <xsl:attribute name="authority">marcgac</xsl:attribute>
2538                                                                 <xsl:value-of select="."></xsl:value-of>
2539                                                         </placeTerm>
2540                                                 </place>
2541                                         </xsl:for-each>
2542                                 </xsl:if>
2543                                 <xsl:for-each select="marc:subfield[@code='d']">
2544                                         <publisher>
2545                                                 <xsl:value-of select="."></xsl:value-of>
2546                                         </publisher>
2547                                 </xsl:for-each>
2548                                 <xsl:for-each select="marc:subfield[@code='b']">
2549                                         <edition>
2550                                                 <xsl:value-of select="."></xsl:value-of>
2551                                         </edition>
2552                                 </xsl:for-each>
2553                         </originInfo>
2554                 </xsl:if>
2555         </xsl:template>
2556         <xsl:template name="relatedLanguage">
2557                 <xsl:for-each select="marc:subfield[@code='e']">
2558                         <xsl:call-template name="getLanguage">
2559                                 <xsl:with-param name="langString">
2560                                         <xsl:value-of select="."></xsl:value-of>
2561                                 </xsl:with-param>
2562                         </xsl:call-template>
2563                 </xsl:for-each>
2564         </xsl:template>
2565         <xsl:template name="nameDate">
2566                 <xsl:for-each select="marc:subfield[@code='d']">
2567                         <namePart type="date">
2568                                 <xsl:call-template name="chopPunctuation">
2569                                         <xsl:with-param name="chopString" select="."></xsl:with-param>
2570                                 </xsl:call-template>
2571                         </namePart>
2572                 </xsl:for-each>
2573         </xsl:template>
2574         <xsl:template name="subjectAuthority">
2575                 <xsl:if test="@ind2!=4">
2576                         <xsl:if test="@ind2!=' '">
2577                                 <xsl:if test="@ind2!=8">
2578                                         <xsl:if test="@ind2!=9">
2579                                                 <xsl:attribute name="authority">
2580                                                         <xsl:choose>
2581                                                                 <xsl:when test="@ind2=0">lcsh</xsl:when>
2582                                                                 <xsl:when test="@ind2=1">lcshac</xsl:when>
2583                                                                 <xsl:when test="@ind2=2">mesh</xsl:when>
2584                                                                 <!-- 1/04 fix -->
2585                                                                 <xsl:when test="@ind2=3">nal</xsl:when>
2586                                                                 <xsl:when test="@ind2=5">csh</xsl:when>
2587                                                                 <xsl:when test="@ind2=6">rvm</xsl:when>
2588                                                                 <xsl:when test="@ind2=7">
2589                                                                         <xsl:value-of select="marc:subfield[@code='2']"></xsl:value-of>
2590                                                                 </xsl:when>
2591                                                         </xsl:choose>
2592                                                 </xsl:attribute>
2593                                         </xsl:if>
2594                                 </xsl:if>
2595                         </xsl:if>
2596                 </xsl:if>
2597         </xsl:template>
2598         <xsl:template name="subjectAnyOrder">
2599                 <xsl:for-each select="marc:subfield[@code='v' or @code='x' or @code='y' or @code='z']">
2600                         <xsl:choose>
2601                                 <xsl:when test="@code='v'">
2602                                         <xsl:call-template name="subjectGenre"></xsl:call-template>
2603                                 </xsl:when>
2604                                 <xsl:when test="@code='x'">
2605                                         <xsl:call-template name="subjectTopic"></xsl:call-template>
2606                                 </xsl:when>
2607                                 <xsl:when test="@code='y'">
2608                                         <xsl:call-template name="subjectTemporalY"></xsl:call-template>
2609                                 </xsl:when>
2610                                 <xsl:when test="@code='z'">
2611                                         <xsl:call-template name="subjectGeographicZ"></xsl:call-template>
2612                                 </xsl:when>
2613                         </xsl:choose>
2614                 </xsl:for-each>
2615         </xsl:template>
2616         <xsl:template name="specialSubfieldSelect">
2617                 <xsl:param name="anyCodes"></xsl:param>
2618                 <xsl:param name="axis"></xsl:param>
2619                 <xsl:param name="beforeCodes"></xsl:param>
2620                 <xsl:param name="afterCodes"></xsl:param>
2621                 <xsl:variable name="str">
2622                         <xsl:for-each select="marc:subfield">
2623                                 <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])">
2624                                         <xsl:value-of select="text()"></xsl:value-of>
2625                                         <xsl:text> </xsl:text>
2626                                 </xsl:if>
2627                         </xsl:for-each>
2628                 </xsl:variable>
2629                 <xsl:value-of select="substring($str,1,string-length($str)-1)"></xsl:value-of>
2630         </xsl:template>
2631         
2632         <!-- 3.2 change tmee 6xx $v genre -->
2633         <xsl:template match="marc:datafield[@tag=600]">
2634                 <subject>
2635                         <xsl:call-template name="subjectAuthority"></xsl:call-template>
2636                         <name type="personal">
2637                                 <xsl:call-template name="termsOfAddress"></xsl:call-template>
2638                                 <namePart>
2639                                         <xsl:call-template name="chopPunctuation">
2640                                                 <xsl:with-param name="chopString">
2641                                                         <xsl:call-template name="subfieldSelect">
2642                                                                 <xsl:with-param name="codes">aq</xsl:with-param>
2643                                                         </xsl:call-template>
2644                                                 </xsl:with-param>
2645                                         </xsl:call-template>
2646                                 </namePart>
2647                                 <xsl:call-template name="nameDate"></xsl:call-template>
2648                                 <xsl:call-template name="affiliation"></xsl:call-template>
2649                                 <xsl:call-template name="role"></xsl:call-template>
2650                         </name>
2651                         <xsl:call-template name="subjectAnyOrder"></xsl:call-template>
2652                 </subject>
2653         </xsl:template>
2654         <xsl:template match="marc:datafield[@tag=610]">
2655                 <subject>
2656                         <xsl:call-template name="subjectAuthority"></xsl:call-template>
2657                         <name type="corporate">
2658                                 <xsl:for-each select="marc:subfield[@code='a']">
2659                                         <namePart>
2660                                                 <xsl:value-of select="."></xsl:value-of>
2661                                         </namePart>
2662                                 </xsl:for-each>
2663                                 <xsl:for-each select="marc:subfield[@code='b']">
2664                                         <namePart>
2665                                                 <xsl:value-of select="."></xsl:value-of>
2666                                         </namePart>
2667                                 </xsl:for-each>
2668                                 <xsl:if test="marc:subfield[@code='c' or @code='d' or @code='n' or @code='p']">
2669                                         <namePart>
2670                                                 <xsl:call-template name="subfieldSelect">
2671                                                         <xsl:with-param name="codes">cdnp</xsl:with-param>
2672                                                 </xsl:call-template>
2673                                         </namePart>
2674                                 </xsl:if>
2675                                 <xsl:call-template name="role"></xsl:call-template>
2676                         </name>
2677                         <xsl:call-template name="subjectAnyOrder"></xsl:call-template>
2678                 </subject>
2679         </xsl:template>
2680         <xsl:template match="marc:datafield[@tag=611]">
2681                 <subject>
2682                         <xsl:call-template name="subjectAuthority"></xsl:call-template>
2683                         <name type="conference">
2684                                 <namePart>
2685                                         <xsl:call-template name="subfieldSelect">
2686                                                 <xsl:with-param name="codes">abcdeqnp</xsl:with-param>
2687                                         </xsl:call-template>
2688                                 </namePart>
2689                                 <xsl:for-each select="marc:subfield[@code='4']">
2690                                         <role>
2691                                                 <roleTerm authority="marcrelator" type="code">
2692                                                         <xsl:value-of select="."></xsl:value-of>
2693                                                 </roleTerm>
2694                                         </role>
2695                                 </xsl:for-each>
2696                         </name>
2697                         <xsl:call-template name="subjectAnyOrder"></xsl:call-template>
2698                 </subject>
2699         </xsl:template>
2700         <xsl:template match="marc:datafield[@tag=630]">
2701                 <subject>
2702                         <xsl:call-template name="subjectAuthority"></xsl:call-template>
2703                         <titleInfo>
2704                                 <title>
2705                                         <xsl:call-template name="chopPunctuation">
2706                                                 <xsl:with-param name="chopString">
2707                                                         <xsl:call-template name="subfieldSelect">
2708                                                                 <xsl:with-param name="codes">adfhklor</xsl:with-param>
2709                                                         </xsl:call-template>
2710                                                 </xsl:with-param>
2711                                         </xsl:call-template>
2712                                         <xsl:call-template name="part"></xsl:call-template>
2713                                 </title>
2714                         </titleInfo>
2715                         <xsl:call-template name="subjectAnyOrder"></xsl:call-template>
2716                 </subject>
2717         </xsl:template>
2718         <xsl:template match="marc:datafield[@tag=650]">
2719                 <subject>
2720                         <xsl:call-template name="subjectAuthority"></xsl:call-template>
2721                         <topic>
2722                                 <xsl:call-template name="chopPunctuation">
2723                                         <xsl:with-param name="chopString">
2724                                                 <xsl:call-template name="subfieldSelect">
2725                                                         <xsl:with-param name="codes">abcd</xsl:with-param>
2726                                                 </xsl:call-template>
2727                                         </xsl:with-param>
2728                                 </xsl:call-template>
2729                         </topic>
2730                         <xsl:call-template name="subjectAnyOrder"></xsl:call-template>
2731                 </subject>
2732         </xsl:template>
2733         <xsl:template match="marc:datafield[@tag=651]">
2734                 <subject>
2735                         <xsl:call-template name="subjectAuthority"></xsl:call-template>
2736                         <xsl:for-each select="marc:subfield[@code='a']">
2737                                 <geographic>
2738                                         <xsl:call-template name="chopPunctuation">
2739                                                 <xsl:with-param name="chopString" select="."></xsl:with-param>
2740                                         </xsl:call-template>
2741                                 </geographic>
2742                         </xsl:for-each>
2743                         <xsl:call-template name="subjectAnyOrder"></xsl:call-template>
2744                 </subject>
2745         </xsl:template>
2746         <xsl:template match="marc:datafield[@tag=653]">
2747                 <subject>
2748                         <xsl:for-each select="marc:subfield[@code='a']">
2749                                 <topic>
2750                                         <xsl:value-of select="."></xsl:value-of>
2751                                 </topic>
2752                         </xsl:for-each>
2753                 </subject>
2754         </xsl:template>
2755         <xsl:template match="marc:datafield[@tag=656]">
2756                 <subject>
2757                         <xsl:if test="marc:subfield[@code=2]">
2758                                 <xsl:attribute name="authority">
2759                                         <xsl:value-of select="marc:subfield[@code=2]"></xsl:value-of>
2760                                 </xsl:attribute>
2761                         </xsl:if>
2762                         <occupation>
2763                                 <xsl:call-template name="chopPunctuation">
2764                                         <xsl:with-param name="chopString">
2765                                                 <xsl:value-of select="marc:subfield[@code='a']"></xsl:value-of>
2766                                         </xsl:with-param>
2767                                 </xsl:call-template>
2768                         </occupation>
2769                 </subject>
2770         </xsl:template>
2771         <xsl:template name="termsOfAddress">
2772                 <xsl:if test="marc:subfield[@code='b' or @code='c']">
2773                         <namePart type="termsOfAddress">
2774                                 <xsl:call-template name="chopPunctuation">
2775                                         <xsl:with-param name="chopString">
2776                                                 <xsl:call-template name="subfieldSelect">
2777                                                         <xsl:with-param name="codes">bc</xsl:with-param>
2778                                                 </xsl:call-template>
2779                                         </xsl:with-param>
2780                                 </xsl:call-template>
2781                         </namePart>
2782                 </xsl:if>
2783         </xsl:template>
2784         <xsl:template name="displayLabel">
2785                 <xsl:if test="marc:subfield[@code='i']">
2786                         <xsl:attribute name="displayLabel">
2787                                 <xsl:value-of select="marc:subfield[@code='i']"></xsl:value-of>
2788                         </xsl:attribute>
2789                 </xsl:if>
2790                 <xsl:if test="marc:subfield[@code='3']">
2791                         <xsl:attribute name="displayLabel">
2792                                 <xsl:value-of select="marc:subfield[@code='3']"></xsl:value-of>
2793                         </xsl:attribute>
2794                 </xsl:if>
2795         </xsl:template>
2796         <xsl:template name="isInvalid">
2797                 <xsl:param name="type"/>
2798                 <xsl:if test="marc:subfield[@code='z'] or marc:subfield[@code='y']">
2799                         <identifier>
2800                                 <xsl:attribute name="type">
2801                                         <xsl:value-of select="$type"/>
2802                                 </xsl:attribute>
2803                                 <xsl:attribute name="invalid">
2804                                         <xsl:text>yes</xsl:text>
2805                                 </xsl:attribute>
2806                                 <xsl:if test="marc:subfield[@code='z']">
2807                                         <xsl:value-of select="marc:subfield[@code='z']"/>
2808                                 </xsl:if>
2809                                 <xsl:if test="marc:subfield[@code='y']">
2810                                         <xsl:value-of select="marc:subfield[@code='y']"/>
2811                                 </xsl:if>
2812                         </identifier>
2813                 </xsl:if>
2814         </xsl:template>
2815         <xsl:template name="subtitle">
2816                 <xsl:if test="marc:subfield[@code='b']">
2817                         <subTitle>
2818                                 <xsl:call-template name="chopPunctuation">
2819                                         <xsl:with-param name="chopString">
2820                                                 <xsl:value-of select="marc:subfield[@code='b']"/>
2821                                                 <!--<xsl:call-template name="subfieldSelect">
2822                                                         <xsl:with-param name="codes">b</xsl:with-param>                                                                 
2823                                                 </xsl:call-template>-->
2824                                         </xsl:with-param>
2825                                 </xsl:call-template>
2826                         </subTitle>
2827                 </xsl:if>
2828         </xsl:template>
2829         <xsl:template name="script">
2830                 <xsl:param name="scriptCode"></xsl:param>
2831                 <xsl:attribute name="script">
2832                         <xsl:choose>
2833                                 <xsl:when test="$scriptCode='(3'">Arabic</xsl:when>
2834                                 <xsl:when test="$scriptCode='(B'">Latin</xsl:when>
2835                                 <xsl:when test="$scriptCode='$1'">Chinese, Japanese, Korean</xsl:when>
2836                                 <xsl:when test="$scriptCode='(N'">Cyrillic</xsl:when>
2837                                 <xsl:when test="$scriptCode='(2'">Hebrew</xsl:when>
2838                                 <xsl:when test="$scriptCode='(S'">Greek</xsl:when>
2839                         </xsl:choose>
2840                 </xsl:attribute>
2841         </xsl:template>
2842         <xsl:template name="parsePart">
2843                 <!-- assumes 773$q= 1:2:3<4
2844                      with up to 3 levels and one optional start page
2845                 -->
2846                 <xsl:variable name="level1">
2847                         <xsl:choose>
2848                                 <xsl:when test="contains(text(),':')">
2849                                         <!-- 1:2 -->
2850                                         <xsl:value-of select="substring-before(text(),':')"></xsl:value-of>
2851                                 </xsl:when>
2852                                 <xsl:when test="not(contains(text(),':'))">
2853                                         <!-- 1 or 1<3 -->
2854                                         <xsl:if test="contains(text(),'&lt;')">
2855                                                 <!-- 1<3 -->
2856                                                 <xsl:value-of select="substring-before(text(),'&lt;')"></xsl:value-of>
2857                                         </xsl:if>
2858                                         <xsl:if test="not(contains(text(),'&lt;'))">
2859                                                 <!-- 1 -->
2860                                                 <xsl:value-of select="text()"></xsl:value-of>
2861                                         </xsl:if>
2862                                 </xsl:when>
2863                         </xsl:choose>
2864                 </xsl:variable>
2865                 <xsl:variable name="sici2">
2866                         <xsl:choose>
2867                                 <xsl:when test="starts-with(substring-after(text(),$level1),':')">
2868                                         <xsl:value-of select="substring(substring-after(text(),$level1),2)"></xsl:value-of>
2869                                 </xsl:when>
2870                                 <xsl:otherwise>
2871                                         <xsl:value-of select="substring-after(text(),$level1)"></xsl:value-of>
2872                                 </xsl:otherwise>
2873                         </xsl:choose>
2874                 </xsl:variable>
2875                 <xsl:variable name="level2">
2876                         <xsl:choose>
2877                                 <xsl:when test="contains($sici2,':')">
2878                                         <!--  2:3<4  -->
2879                                         <xsl:value-of select="substring-before($sici2,':')"></xsl:value-of>
2880                                 </xsl:when>
2881                                 <xsl:when test="contains($sici2,'&lt;')">
2882                                         <!-- 1: 2<4 -->
2883                                         <xsl:value-of select="substring-before($sici2,'&lt;')"></xsl:value-of>
2884                                 </xsl:when>
2885                                 <xsl:otherwise>
2886                                         <xsl:value-of select="$sici2"></xsl:value-of>
2887                                         <!-- 1:2 -->
2888                                 </xsl:otherwise>
2889                         </xsl:choose>
2890                 </xsl:variable>
2891                 <xsl:variable name="sici3">
2892                         <xsl:choose>
2893                                 <xsl:when test="starts-with(substring-after($sici2,$level2),':')">
2894                                         <xsl:value-of select="substring(substring-after($sici2,$level2),2)"></xsl:value-of>
2895                                 </xsl:when>
2896                                 <xsl:otherwise>
2897                                         <xsl:value-of select="substring-after($sici2,$level2)"></xsl:value-of>
2898                                 </xsl:otherwise>
2899                         </xsl:choose>
2900                 </xsl:variable>
2901                 <xsl:variable name="level3">
2902                         <xsl:choose>
2903                                 <xsl:when test="contains($sici3,'&lt;')">
2904                                         <!-- 2<4 -->
2905                                         <xsl:value-of select="substring-before($sici3,'&lt;')"></xsl:value-of>
2906                                 </xsl:when>
2907                                 <xsl:otherwise>
2908                                         <xsl:value-of select="$sici3"></xsl:value-of>
2909                                         <!-- 3 -->
2910                                 </xsl:otherwise>
2911                         </xsl:choose>
2912                 </xsl:variable>
2913                 <xsl:variable name="page">
2914                         <xsl:if test="contains(text(),'&lt;')">
2915                                 <xsl:value-of select="substring-after(text(),'&lt;')"></xsl:value-of>
2916                         </xsl:if>
2917                 </xsl:variable>
2918                 <xsl:if test="$level1">
2919                         <detail level="1">
2920                                 <number>
2921                                         <xsl:value-of select="$level1"></xsl:value-of>
2922                                 </number>
2923                         </detail>
2924                 </xsl:if>
2925                 <xsl:if test="$level2">
2926                         <detail level="2">
2927                                 <number>
2928                                         <xsl:value-of select="$level2"></xsl:value-of>
2929                                 </number>
2930                         </detail>
2931                 </xsl:if>
2932                 <xsl:if test="$level3">
2933                         <detail level="3">
2934                                 <number>
2935                                         <xsl:value-of select="$level3"></xsl:value-of>
2936                                 </number>
2937                         </detail>
2938                 </xsl:if>
2939                 <xsl:if test="$page">
2940                         <extent unit="page">
2941                                 <start>
2942                                         <xsl:value-of select="$page"></xsl:value-of>
2943                                 </start>
2944                         </extent>
2945                 </xsl:if>
2946         </xsl:template>
2947         <xsl:template name="getLanguage">
2948                 <xsl:param name="langString"></xsl:param>
2949                 <xsl:param name="controlField008-35-37"></xsl:param>
2950                 <xsl:variable name="length" select="string-length($langString)"></xsl:variable>
2951                 <xsl:choose>
2952                         <xsl:when test="$length=0"></xsl:when>
2953                         <xsl:when test="$controlField008-35-37=substring($langString,1,3)">
2954                                 <xsl:call-template name="getLanguage">
2955                                         <xsl:with-param name="langString" select="substring($langString,4,$length)"></xsl:with-param>
2956                                         <xsl:with-param name="controlField008-35-37" select="$controlField008-35-37"></xsl:with-param>
2957                                 </xsl:call-template>
2958                         </xsl:when>
2959                         <xsl:otherwise>
2960                                 <language>
2961                                         <languageTerm authority="iso639-2b" type="code">
2962                                                 <xsl:value-of select="substring($langString,1,3)"></xsl:value-of>
2963                                         </languageTerm>
2964                                 </language>
2965                                 <xsl:call-template name="getLanguage">
2966                                         <xsl:with-param name="langString" select="substring($langString,4,$length)"></xsl:with-param>
2967                                         <xsl:with-param name="controlField008-35-37" select="$controlField008-35-37"></xsl:with-param>
2968                                 </xsl:call-template>
2969                         </xsl:otherwise>
2970                 </xsl:choose>
2971         </xsl:template>
2972         <xsl:template name="isoLanguage">
2973                 <xsl:param name="currentLanguage"></xsl:param>
2974                 <xsl:param name="usedLanguages"></xsl:param>
2975                 <xsl:param name="remainingLanguages"></xsl:param>
2976                 <xsl:choose>
2977                         <xsl:when test="string-length($currentLanguage)=0"></xsl:when>
2978                         <xsl:when test="not(contains($usedLanguages, $currentLanguage))">
2979                                 <language>
2980                                         <xsl:if test="@code!='a'">
2981                                                 <xsl:attribute name="objectPart">
2982                                                         <xsl:choose>
2983                                                                 <xsl:when test="@code='b'">summary or subtitle</xsl:when>
2984                                                                 <xsl:when test="@code='d'">sung or spoken text</xsl:when>
2985                                                                 <xsl:when test="@code='e'">libretto</xsl:when>
2986                                                                 <xsl:when test="@code='f'">table of contents</xsl:when>
2987                                                                 <xsl:when test="@code='g'">accompanying material</xsl:when>
2988                                                                 <xsl:when test="@code='h'">translation</xsl:when>
2989                                                         </xsl:choose>
2990                                                 </xsl:attribute>
2991                                         </xsl:if>
2992                                         <languageTerm authority="iso639-2b" type="code">
2993                                                 <xsl:value-of select="$currentLanguage"></xsl:value-of>
2994                                         </languageTerm>
2995                                 </language>
2996                                 <xsl:call-template name="isoLanguage">
2997                                         <xsl:with-param name="currentLanguage">
2998                                                 <xsl:value-of select="substring($remainingLanguages,1,3)"></xsl:value-of>
2999                                         </xsl:with-param>
3000                                         <xsl:with-param name="usedLanguages">
3001                                                 <xsl:value-of select="concat($usedLanguages,$currentLanguage)"></xsl:value-of>
3002                                         </xsl:with-param>
3003                                         <xsl:with-param name="remainingLanguages">
3004                                                 <xsl:value-of select="substring($remainingLanguages,4,string-length($remainingLanguages))"></xsl:value-of>
3005                                         </xsl:with-param>
3006                                 </xsl:call-template>
3007                         </xsl:when>
3008                         <xsl:otherwise>
3009                                 <xsl:call-template name="isoLanguage">
3010                                         <xsl:with-param name="currentLanguage">
3011                                                 <xsl:value-of select="substring($remainingLanguages,1,3)"></xsl:value-of>
3012                                         </xsl:with-param>
3013                                         <xsl:with-param name="usedLanguages">
3014                                                 <xsl:value-of select="concat($usedLanguages,$currentLanguage)"></xsl:value-of>
3015                                         </xsl:with-param>
3016                                         <xsl:with-param name="remainingLanguages">
3017                                                 <xsl:value-of select="substring($remainingLanguages,4,string-length($remainingLanguages))"></xsl:value-of>
3018                                         </xsl:with-param>
3019                                 </xsl:call-template>
3020                         </xsl:otherwise>
3021                 </xsl:choose>
3022         </xsl:template>
3023         <xsl:template name="chopBrackets">
3024                 <xsl:param name="chopString"></xsl:param>
3025                 <xsl:variable name="string">
3026                         <xsl:call-template name="chopPunctuation">
3027                                 <xsl:with-param name="chopString" select="$chopString"></xsl:with-param>
3028                         </xsl:call-template>
3029                 </xsl:variable>
3030                 <xsl:if test="substring($string, 1,1)='['">
3031                         <xsl:value-of select="substring($string,2, string-length($string)-2)"></xsl:value-of>
3032                 </xsl:if>
3033                 <xsl:if test="substring($string, 1,1)!='['">
3034                         <xsl:value-of select="$string"></xsl:value-of>
3035                 </xsl:if>
3036         </xsl:template>
3037         <xsl:template name="rfcLanguages">
3038                 <xsl:param name="nodeNum"></xsl:param>
3039                 <xsl:param name="usedLanguages"></xsl:param>
3040                 <xsl:param name="controlField008-35-37"></xsl:param>
3041                 <xsl:variable name="currentLanguage" select="."></xsl:variable>
3042                 <xsl:choose>
3043                         <xsl:when test="not($currentLanguage)"></xsl:when>
3044                         <xsl:when test="$currentLanguage!=$controlField008-35-37 and $currentLanguage!='rfc3066'">
3045                                 <xsl:if test="not(contains($usedLanguages,$currentLanguage))">
3046                                         <language>
3047                                                 <xsl:if test="@code!='a'">
3048                                                         <xsl:attribute name="objectPart">
3049                                                                 <xsl:choose>
3050                                                                         <xsl:when test="@code='b'">summary or subtitle</xsl:when>
3051                                                                         <xsl:when test="@code='d'">sung or spoken text</xsl:when>
3052                                                                         <xsl:when test="@code='e'">libretto</xsl:when>
3053                                                                         <xsl:when test="@code='f'">table of contents</xsl:when>
3054                                                                         <xsl:when test="@code='g'">accompanying material</xsl:when>
3055                                                                         <xsl:when test="@code='h'">translation</xsl:when>
3056                                                                 </xsl:choose>
3057                                                         </xsl:attribute>
3058                                                 </xsl:if>
3059                                                 <languageTerm authority="rfc3066" type="code">
3060                                                         <xsl:value-of select="$currentLanguage"/>
3061                                                 </languageTerm>
3062                                         </language>
3063                                 </xsl:if>
3064                         </xsl:when>
3065                         <xsl:otherwise>
3066                         </xsl:otherwise>
3067                 </xsl:choose>
3068         </xsl:template>
3069         <xsl:template name="datafield">
3070                 <xsl:param name="tag"/>
3071                 <xsl:param name="ind1"><xsl:text> </xsl:text></xsl:param>
3072                 <xsl:param name="ind2"><xsl:text> </xsl:text></xsl:param>
3073                 <xsl:param name="subfields"/>
3074                 <xsl:element name="marc:datafield">
3075                         <xsl:attribute name="tag">
3076                                 <xsl:value-of select="$tag"/>
3077                         </xsl:attribute>
3078                         <xsl:attribute name="ind1">
3079                                 <xsl:value-of select="$ind1"/>
3080                         </xsl:attribute>
3081                         <xsl:attribute name="ind2">
3082                                 <xsl:value-of select="$ind2"/>
3083                         </xsl:attribute>
3084                         <xsl:copy-of select="$subfields"/>
3085                 </xsl:element>
3086         </xsl:template>
3087
3088         <xsl:template name="subfieldSelect">
3089                 <xsl:param name="codes"/>
3090                 <xsl:param name="delimeter"><xsl:text> </xsl:text></xsl:param>
3091                 <xsl:variable name="str">
3092                         <xsl:for-each select="marc:subfield">
3093                                 <xsl:if test="contains($codes, @code)">
3094                                         <xsl:value-of select="text()"/><xsl:value-of select="$delimeter"/>
3095                                 </xsl:if>
3096                         </xsl:for-each>
3097                 </xsl:variable>
3098                 <xsl:value-of select="substring($str,1,string-length($str)-string-length($delimeter))"/>
3099         </xsl:template>
3100
3101         <xsl:template name="buildSpaces">
3102                 <xsl:param name="spaces"/>
3103                 <xsl:param name="char"><xsl:text> </xsl:text></xsl:param>
3104                 <xsl:if test="$spaces>0">
3105                         <xsl:value-of select="$char"/>
3106                         <xsl:call-template name="buildSpaces">
3107                                 <xsl:with-param name="spaces" select="$spaces - 1"/>
3108                                 <xsl:with-param name="char" select="$char"/>
3109                         </xsl:call-template>
3110                 </xsl:if>
3111         </xsl:template>
3112
3113         <xsl:template name="chopPunctuation">
3114                 <xsl:param name="chopString"/>
3115                 <xsl:param name="punctuation"><xsl:text>.:,;/ </xsl:text></xsl:param>
3116                 <xsl:variable name="length" select="string-length($chopString)"/>
3117                 <xsl:choose>
3118                         <xsl:when test="$length=0"/>
3119                         <xsl:when test="contains($punctuation, substring($chopString,$length,1))">
3120                                 <xsl:call-template name="chopPunctuation">
3121                                         <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
3122                                         <xsl:with-param name="punctuation" select="$punctuation"/>
3123                                 </xsl:call-template>
3124                         </xsl:when>
3125                         <xsl:when test="not($chopString)"/>
3126                         <xsl:otherwise><xsl:value-of select="$chopString"/></xsl:otherwise>
3127                 </xsl:choose>
3128         </xsl:template>
3129
3130         <xsl:template name="chopPunctuationFront">
3131                 <xsl:param name="chopString"/>
3132                 <xsl:variable name="length" select="string-length($chopString)"/>
3133                 <xsl:choose>
3134                         <xsl:when test="$length=0"/>
3135                         <xsl:when test="contains('.:,;/[ ', substring($chopString,1,1))">
3136                                 <xsl:call-template name="chopPunctuationFront">
3137                                         <xsl:with-param name="chopString" select="substring($chopString,2,$length - 1)"/>
3138                                 </xsl:call-template>
3139                         </xsl:when>
3140                         <xsl:when test="not($chopString)"/>
3141                         <xsl:otherwise><xsl:value-of select="$chopString"/></xsl:otherwise>
3142                 </xsl:choose>
3143         </xsl:template>
3144 </xsl:stylesheet>$$ WHERE name = 'mods32';
3145
3146 -- Currently, the only difference from naco_normalize is that search_normalize
3147 -- turns apostrophes into spaces, while naco_normalize collapses them.
3148 CREATE OR REPLACE FUNCTION public.search_normalize( TEXT, TEXT ) RETURNS TEXT AS $func$
3149
3150     use strict;
3151     use Unicode::Normalize;
3152     use Encode;
3153
3154     my $str = decode_utf8(shift);
3155     my $sf = shift;
3156
3157     # Apply NACO normalization to input string; based on
3158     # http://www.loc.gov/catdir/pcc/naco/SCA_PccNormalization_Final_revised.pdf
3159     #
3160     # Note that unlike a strict reading of the NACO normalization rules,
3161     # output is returned as lowercase instead of uppercase for compatibility
3162     # with previous versions of the Evergreen naco_normalize routine.
3163
3164     # Convert to upper-case first; even though final output will be lowercase, doing this will
3165     # ensure that the German eszett (ß) and certain ligatures (ff, fi, ffl, etc.) will be handled correctly.
3166     # If there are any bugs in Perl's implementation of upcasing, they will be passed through here.
3167     $str = uc $str;
3168
3169     # remove non-filing strings
3170     $str =~ s/\x{0098}.*?\x{009C}//g;
3171
3172     $str = NFKD($str);
3173
3174     # additional substitutions - 3.6.
3175     $str =~ s/\x{00C6}/AE/g;
3176     $str =~ s/\x{00DE}/TH/g;
3177     $str =~ s/\x{0152}/OE/g;
3178     $str =~ tr/\x{0110}\x{00D0}\x{00D8}\x{0141}\x{2113}\x{02BB}\x{02BC}][/DDOLl/d;
3179
3180     # transformations based on Unicode category codes
3181     $str =~ s/[\p{Cc}\p{Cf}\p{Co}\p{Cs}\p{Lm}\p{Mc}\p{Me}\p{Mn}]//g;
3182
3183         if ($sf && $sf =~ /^a/o) {
3184                 my $commapos = index($str, ',');
3185                 if ($commapos > -1) {
3186                         if ($commapos != length($str) - 1) {
3187                 $str =~ s/,/\x07/; # preserve first comma
3188                         }
3189                 }
3190         }
3191
3192     # since we've stripped out the control characters, we can now
3193     # use a few as placeholders temporarily
3194     $str =~ tr/+&@\x{266D}\x{266F}#/\x01\x02\x03\x04\x05\x06/;
3195     $str =~ s/[\p{Pc}\p{Pd}\p{Pe}\p{Pf}\p{Pi}\p{Po}\p{Ps}\p{Sk}\p{Sm}\p{So}\p{Zl}\p{Zp}\p{Zs}]/ /g;
3196     $str =~ tr/\x01\x02\x03\x04\x05\x06\x07/+&@\x{266D}\x{266F}#,/;
3197
3198     # decimal digits
3199     $str =~ tr/\x{0660}-\x{0669}\x{06F0}-\x{06F9}\x{07C0}-\x{07C9}\x{0966}-\x{096F}\x{09E6}-\x{09EF}\x{0A66}-\x{0A6F}\x{0AE6}-\x{0AEF}\x{0B66}-\x{0B6F}\x{0BE6}-\x{0BEF}\x{0C66}-\x{0C6F}\x{0CE6}-\x{0CEF}\x{0D66}-\x{0D6F}\x{0E50}-\x{0E59}\x{0ED0}-\x{0ED9}\x{0F20}-\x{0F29}\x{1040}-\x{1049}\x{1090}-\x{1099}\x{17E0}-\x{17E9}\x{1810}-\x{1819}\x{1946}-\x{194F}\x{19D0}-\x{19D9}\x{1A80}-\x{1A89}\x{1A90}-\x{1A99}\x{1B50}-\x{1B59}\x{1BB0}-\x{1BB9}\x{1C40}-\x{1C49}\x{1C50}-\x{1C59}\x{A620}-\x{A629}\x{A8D0}-\x{A8D9}\x{A900}-\x{A909}\x{A9D0}-\x{A9D9}\x{AA50}-\x{AA59}\x{ABF0}-\x{ABF9}\x{FF10}-\x{FF19}/0-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-90-9/;
3200
3201     # intentionally skipping step 8 of the NACO algorithm; if the string
3202     # gets normalized away, that's fine.
3203
3204     # leading and trailing spaces
3205     $str =~ s/\s+/ /g;
3206     $str =~ s/^\s+//;
3207     $str =~ s/\s+$//g;
3208
3209     return lc $str;
3210 $func$ LANGUAGE 'plperlu' STRICT IMMUTABLE;
3211
3212 CREATE OR REPLACE FUNCTION public.search_normalize_keep_comma( TEXT ) RETURNS TEXT AS $func$
3213         SELECT public.search_normalize($1,'a');
3214 $func$ LANGUAGE SQL STRICT IMMUTABLE;
3215
3216 CREATE OR REPLACE FUNCTION public.search_normalize( TEXT ) RETURNS TEXT AS $func$
3217         SELECT public.search_normalize($1,'');
3218 $func$ LANGUAGE 'sql' STRICT IMMUTABLE;
3219
3220 INSERT INTO config.index_normalizer (name, description, func, param_count) VALUES (
3221         'Search Normalize',
3222         'Apply search normalization rules to the extracted text. A less extreme version of NACO normalization.',
3223         'search_normalize',
3224         0
3225 );
3226
3227 UPDATE config.metabib_field_index_norm_map
3228     SET norm = (
3229         SELECT id FROM config.index_normalizer WHERE func = 'search_normalize'
3230     )
3231     WHERE norm = (
3232         SELECT id FROM config.index_normalizer WHERE func = 'naco_normalize'
3233     )
3234 ;
3235
3236 COMMIT;
3237
3238 -- This could take a long time if you have a very non-English bib database
3239 -- Run it outside of a transaction to avoid lock escalation
3240 SELECT metabib.reingest_metabib_field_entries(record)
3241     FROM metabib.full_rec
3242     WHERE tag = '245'
3243     AND subfield = 'a'
3244     AND value LIKE '%''%'
3245 ;