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