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