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