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