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