Merge remote-tracking branch 'origin/new/bug_8382'
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / xslt / MARC21slim2MADS.xsl
1 <?xml version="1.0" encoding="UTF-8"?>
2 <xsl:stylesheet version="1.0" xmlns:mads="http://www.loc.gov/mads/v2"
3     xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:marc="http://www.loc.gov/MARC21/slim"
4     xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="marc">
5
6     <xsl:include href="http://www.loc.gov/marcxml/xslt/MARC21slimUtils.xsl"/>
7     <xsl:output method="xml" indent="yes" encoding="UTF-8"/>
8     <xsl:strip-space elements="*"/>
9     <!-- Stylesheet copyright (c) 2011 Library of Congress
10     -->
11
12     <!--
13 2.10    fixed type=other and type=otherType for mads:related                                tmee 09/16/2011
14 2.09    fixed professionTerm and genreTerm empty tag error                                    tmee 09/16/2011
15 2.08    fixed marc:subfield @code='i' matching error                                        tmee 09/16/2011
16 2.07    fixed 555 duplication error                                                            tmee 08/10/2011
17 2.06    fixed topic subfield error                                                            tmee 08/10/2011
18 2.05    fixed title subfield error                                                            tmee 06/20/2011
19 2.04    fixed geographicSubdivision mapping for authority element                            tmee 06/16/2011
20 2.03    added classification for 053, 055, 060, 065, 070, 080, 082, 083, 086, 087            tmee 06/03/2011
21 2.02    added descriptionStandard for 008/10                                                tmee 04/27/2011
22 2.01    added extensions for 046, 336, 370, 374, 375, 376                                    tmee 04/08/2011
23 2.00    redefined imported MODS elements in version 1.0 to MADS elements in version 2.0        tmee 02/08/2011
24 1.08    added 372 subfields $a $s $t for <fieldOfActivity>                                    tmee 06/24/2010
25 1.07    removed role/roleTerm 100, 110, 111, 400, 410, 411, 500, 510, 511, 700, 710, 711    tmee 06/24/2010
26 1.06    added strip-space                                                                    tmee 06/24/2010
27 1.05    added subfield $a for 130, 430, 530                                                    tmee 06/21/2010
28 1.04    fixed 550 z omission                                                                ntra 08/11/2008
29 1.03    removed duplication of 550 $a text                                                    tmee 11/01/2006
30 1.02    fixed namespace references between mads and mods                                    ntra 10/06/2006
31 1.01    revised                                                                                rgue/jrad 11/29/05
32 1.00    adapted from MARC21Slim2MODS3.xsl                                                ntra 07/06/05
33 -->
34
35     <!-- authority attribute defaults to 'naf' if not set using this authority parameter, for <authority> descriptors: name, titleInfo, geographic -->
36     <xsl:param name="authority"/>
37     <xsl:variable name="auth">
38         <xsl:choose>
39             <xsl:when test="$authority">
40                 <xsl:value-of select="$authority"/>
41             </xsl:when>
42             <xsl:otherwise>naf</xsl:otherwise>
43         </xsl:choose>
44     </xsl:variable>
45     <xsl:variable name="controlField008" select="marc:controlfield[@tag='008']"/>
46     <xsl:variable name="controlField008-06"
47         select="substring(descendant-or-self::marc:controlfield[@tag=008],7,1)"/>
48     <xsl:variable name="controlField008-11"
49         select="substring(descendant-or-self::marc:controlfield[@tag=008],12,1)"/>
50     <xsl:variable name="controlField008-14"
51         select="substring(descendant-or-self::marc:controlfield[@tag=008],15,1)"/>
52     <xsl:template match="/">
53         <xsl:choose>
54             <xsl:when test="descendant-or-self::marc:collection">
55                 <mads:madsCollection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
56                     xsi:schemaLocation="http://www.loc.gov/mads/v2 http://www.loc.gov/standards/mads/v2/mads-2-0.xsd">
57                     <xsl:for-each select="descendant-or-self::marc:collection/marc:record">
58                         <mads:mads version="2.0">
59                             <xsl:call-template name="marcRecord"/>
60                         </mads:mads>
61                     </xsl:for-each>
62                 </mads:madsCollection>
63             </xsl:when>
64             <xsl:otherwise>
65                 <mads:mads version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
66                     xsi:schemaLocation="http://www.loc.gov/mads/v2 http://www.loc.gov/standards/mads/mads-2-0.xsd">
67                     <xsl:for-each select="descendant-or-self::marc:record">
68                         <xsl:call-template name="marcRecord"/>
69                     </xsl:for-each>
70                 </mads:mads>
71             </xsl:otherwise>
72         </xsl:choose>
73     </xsl:template>
74
75     <xsl:template name="marcRecord">
76         <mads:authority>
77             <!-- 2.04 -->
78             <xsl:choose>
79                 <xsl:when test="$controlField008-06='d'">
80                     <xsl:attribute name="geographicSubdivision">
81                         <xsl:text>direct</xsl:text>
82                     </xsl:attribute>
83                 </xsl:when>
84                 <xsl:when test="$controlField008-06='i'">
85                     <xsl:attribute name="geographicSubdivision">
86                         <xsl:text>indirect</xsl:text>
87                     </xsl:attribute>
88                 </xsl:when>
89                 <xsl:when test="$controlField008-06='n'">
90                     <xsl:attribute name="geographicSubdivision">
91                         <xsl:text>not applicable</xsl:text>
92                     </xsl:attribute>
93                 </xsl:when>
94             </xsl:choose>
95
96             <xsl:apply-templates select="marc:datafield[100 &lt;= @tag  and @tag &lt; 200]"/>
97         </mads:authority>
98
99         <!-- related -->
100         <xsl:apply-templates
101             select="marc:datafield[500 &lt;= @tag and @tag &lt;= 585]|marc:datafield[700 &lt;= @tag and @tag &lt;= 785]"/>
102
103         <!-- variant -->
104         <xsl:apply-templates select="marc:datafield[400 &lt;= @tag and @tag &lt;= 485]"/>
105
106         <!-- notes -->
107         <xsl:apply-templates select="marc:datafield[667 &lt;= @tag and @tag &lt;= 688]"/>
108
109         <!-- url -->
110         <xsl:apply-templates select="marc:datafield[@tag=856]"/>
111         <xsl:apply-templates select="marc:datafield[@tag=010]"/>
112         <xsl:apply-templates select="marc:datafield[@tag=024]"/>
113         <xsl:apply-templates select="marc:datafield[@tag=372]"/>
114
115         <!-- classification -->
116         <xsl:apply-templates select="marc:datafield[@tag=053]"/>
117         <xsl:apply-templates select="marc:datafield[@tag=055]"/>
118         <xsl:apply-templates select="marc:datafield[@tag=060]"/>
119         <xsl:apply-templates select="marc:datafield[@tag=065]"/>
120         <xsl:apply-templates select="marc:datafield[@tag=070]"/>
121         <xsl:apply-templates select="marc:datafield[@tag=080]"/>
122         <xsl:apply-templates select="marc:datafield[@tag=082]"/>
123         <xsl:apply-templates select="marc:datafield[@tag=083]"/>
124         <xsl:apply-templates select="marc:datafield[@tag=086]"/>
125         <xsl:apply-templates select="marc:datafield[@tag=087]"/>
126
127         <!-- affiliation-->
128
129         <xsl:for-each select="marc:datafield[@tag=373]">
130             <mads:affiliation>
131                 <mads:position>
132                     <xsl:value-of select="marc:subfield[@code='a']"/>
133                 </mads:position>
134                 <mads:dateValid point="start">
135                     <xsl:value-of select="marc:subfield[@code='s']"/>
136                 </mads:dateValid>
137                 <mads:dateValid point="end">
138                     <xsl:value-of select="marc:subfield[@code='t']"/>
139                 </mads:dateValid>
140             </mads:affiliation>
141         </xsl:for-each>
142         <xsl:for-each select="marc:datafield[@tag=371]">
143             <mads:affiliation>
144                 <mads:address>
145                     <mads:street>
146                         <xsl:value-of select="marc:subfield[@code='a']"/>
147                     </mads:street>
148                     <mads:city>
149                         <xsl:value-of select="marc:subfield[@code='b']"/>
150                     </mads:city>
151                     <mads:state>
152                         <xsl:value-of select="marc:subfield[@code='c']"/>
153                     </mads:state>
154                     <mads:country>
155                         <xsl:value-of select="marc:subfield[@code='d']"/>
156                     </mads:country>
157                     <mads:postcode>
158                         <xsl:value-of select="marc:subfield[@code='e']"/>
159                     </mads:postcode>
160                 </mads:address>
161                 <mads:email>
162                     <xsl:value-of select="marc:subfield[@code='m']"/>
163                 </mads:email>
164             </mads:affiliation>
165         </xsl:for-each>
166
167         <!-- extension-->
168         <xsl:for-each select="marc:datafield[@tag=336]">
169             <mads:extension>
170                 <mads:contentType>
171                     <mads:contentType type="text">
172                         <xsl:value-of select="marc:subfield[@code='a']"/>
173                     </mads:contentType>
174                     <mads:contentType type="code">
175                         <xsl:value-of select="marc:subfield[@code='b']"/>
176                     </mads:contentType>
177                 </mads:contentType>
178             </mads:extension>
179         </xsl:for-each>
180
181         <xsl:for-each select="marc:datafield[@tag=374]">
182             <mads:extension>
183                 <mads:profession>
184                     <xsl:choose>
185                         <xsl:when test="marc:subfield[@code='a']">
186                             <mads:professionTerm>
187                                 <xsl:value-of select="marc:subfield[@code='a']"/>
188                             </mads:professionTerm>
189                         </xsl:when>
190                         <xsl:when test="marc:subfield[@code='s']">
191                             <mads:dateValid point="start">
192                                 <xsl:value-of select="marc:subfield[@code='s']"/>
193                             </mads:dateValid>
194                         </xsl:when>
195                         <xsl:when test="marc:subfield[@code='t']">
196                             <mads:dateValid point="end">
197                                 <xsl:value-of select="marc:subfield[@code='t']"/>
198                             </mads:dateValid>
199                         </xsl:when>
200                     </xsl:choose>
201                 </mads:profession>
202             </mads:extension>
203         </xsl:for-each>
204
205         <xsl:for-each select="marc:datafield[@tag=375]">
206             <mads:extension>
207                 <mads:gender>
208                     <xsl:choose>
209                         <xsl:when test="marc:subfield[@code='a']">
210                             <mads:genderTerm>
211                                 <xsl:value-of select="marc:subfield[@code='a']"/>
212                             </mads:genderTerm>
213                         </xsl:when>
214                         <xsl:when test="marc:subfield[@code='s']">
215                             <mads:dateValid point="start">
216                                 <xsl:value-of select="marc:subfield[@code='s']"/>
217                             </mads:dateValid>
218                         </xsl:when>
219                         <xsl:when test="marc:subfield[@code='t']">
220                             <mads:dateValid point="end">
221                                 <xsl:value-of select="marc:subfield[@code='t']"/>
222                             </mads:dateValid>
223                         </xsl:when>
224                     </xsl:choose>
225                 </mads:gender>
226             </mads:extension>
227         </xsl:for-each>
228
229         <xsl:for-each select="marc:datafield[@tag=376]">
230             <mads:extension>
231                 <mads:familyInformation>
232                     <mads:typeOfFamily>
233                         <xsl:value-of select="marc:subfield[@code='a']"/>
234                     </mads:typeOfFamily>
235                     <mads:nameOfProminentMember>
236                         <xsl:value-of select="marc:subfield[@code='b']"/>
237                     </mads:nameOfProminentMember>
238                     <mads:hereditaryTitle>
239                         <xsl:value-of select="marc:subfield[@code='c']"/>
240                     </mads:hereditaryTitle>
241                     <mads:dateValid point="start">
242                         <xsl:value-of select="marc:subfield[@code='s']"/>
243                     </mads:dateValid>
244                     <mads:dateValid point="end">
245                         <xsl:value-of select="marc:subfield[@code='t']"/>
246                     </mads:dateValid>
247                 </mads:familyInformation>
248             </mads:extension>
249         </xsl:for-each>
250
251         <mads:recordInfo>
252             <mads:recordOrigin>Converted from MARCXML to MADS version 2.0 (Revision 2.10)</mads:recordOrigin>
253             <!-- <xsl:apply-templates select="marc:datafield[@tag=024]"/> -->
254
255             <xsl:apply-templates select="marc:datafield[@tag=040]/marc:subfield[@code='a']"/>
256             <xsl:apply-templates select="marc:controlfield[@tag=005]"/>
257             <xsl:apply-templates select="marc:controlfield[@tag=001]"/>
258             <xsl:apply-templates select="marc:datafield[@tag=040]/marc:subfield[@code='b']"/>
259             <xsl:apply-templates select="marc:datafield[@tag=040]/marc:subfield[@code='e']"/>
260             <xsl:for-each select="marc:controlfield[@tag=008]">
261                 <xsl:if test="substring(.,11,1)='a'">
262                     <mads:descriptionStandard>
263                         <xsl:text>earlier rules</xsl:text>
264                     </mads:descriptionStandard>
265                 </xsl:if>
266                 <xsl:if test="substring(.,11,1)='b'">
267                     <mads:descriptionStandard>
268                         <xsl:text>aacr1</xsl:text>
269                     </mads:descriptionStandard>
270                 </xsl:if>
271                 <xsl:if test="substring(.,11,1)='c'">
272                     <mads:descriptionStandard>
273                         <xsl:text>aacr2</xsl:text>
274                     </mads:descriptionStandard>
275                 </xsl:if>
276                 <xsl:if test="substring(.,11,1)='d'">
277                     <mads:descriptionStandard>
278                         <xsl:text>aacr2 compatible</xsl:text>
279                     </mads:descriptionStandard>
280                 </xsl:if>
281                 <xsl:if test="substring(.,11,1)='z'">
282                     <mads:descriptionStandard>
283                         <xsl:text>other rules</xsl:text>
284                     </mads:descriptionStandard>
285                 </xsl:if>
286             </xsl:for-each>
287         </mads:recordInfo>
288     </xsl:template>
289
290     <!-- start of secondary templates -->
291
292     <!-- ======== xlink ======== -->
293
294     <!-- <xsl:template name="uri">
295     <xsl:for-each select="marc:subfield[@code='0']">
296       <xsl:attribute name="xlink:href">
297     <xsl:value-of select="."/>
298       </xsl:attribute>
299     </xsl:for-each>
300      </xsl:template>
301    -->
302     <xsl:template match="marc:subfield[@code='i']">
303         <xsl:attribute name="otherType">
304             <xsl:value-of select="."/>
305         </xsl:attribute>
306     </xsl:template>
307
308     <!-- No role/roleTerm mapped in MADS 06/24/2010
309     <xsl:template name="role">
310         <xsl:for-each select="marc:subfield[@code='e']">
311             <mads:role>
312                 <mads:roleTerm type="text">
313                     <xsl:value-of select="."/>
314                 </mads:roleTerm>
315             </mads:role>
316         </xsl:for-each>
317     </xsl:template>
318 -->
319
320     <xsl:template name="part">
321         <xsl:variable name="partNumber">
322             <xsl:call-template name="specialSubfieldSelect">
323                 <xsl:with-param name="axis">n</xsl:with-param>
324                 <xsl:with-param name="anyCodes">n</xsl:with-param>
325                 <xsl:with-param name="afterCodes">fghkdlmor</xsl:with-param>
326             </xsl:call-template>
327         </xsl:variable>
328         <xsl:variable name="partName">
329             <xsl:call-template name="specialSubfieldSelect">
330                 <xsl:with-param name="axis">p</xsl:with-param>
331                 <xsl:with-param name="anyCodes">p</xsl:with-param>
332                 <xsl:with-param name="afterCodes">fghkdlmor</xsl:with-param>
333             </xsl:call-template>
334         </xsl:variable>
335         <xsl:if test="string-length(normalize-space($partNumber))">
336             <mads:partNumber>
337                 <xsl:call-template name="chopPunctuation">
338                     <xsl:with-param name="chopString" select="$partNumber"/>
339                 </xsl:call-template>
340             </mads:partNumber>
341         </xsl:if>
342         <xsl:if test="string-length(normalize-space($partName))">
343             <mads:partName>
344                 <xsl:call-template name="chopPunctuation">
345                     <xsl:with-param name="chopString" select="$partName"/>
346                 </xsl:call-template>
347             </mads:partName>
348         </xsl:if>
349     </xsl:template>
350
351     <xsl:template name="nameABCDN">
352         <xsl:for-each select="marc:subfield[@code='a']">
353             <mads:namePart>
354                 <xsl:call-template name="chopPunctuation">
355                     <xsl:with-param name="chopString" select="."/>
356                 </xsl:call-template>
357             </mads:namePart>
358         </xsl:for-each>
359         <xsl:for-each select="marc:subfield[@code='b']">
360             <mads:namePart>
361                 <xsl:value-of select="."/>
362             </mads:namePart>
363         </xsl:for-each>
364         <xsl:if
365             test="marc:subfield[@code='c'] or marc:subfield[@code='d'] or marc:subfield[@code='n']">
366             <mads:namePart>
367                 <xsl:call-template name="subfieldSelect">
368                     <xsl:with-param name="codes">cdn</xsl:with-param>
369                 </xsl:call-template>
370             </mads:namePart>
371         </xsl:if>
372     </xsl:template>
373
374     <xsl:template name="nameABCDQ">
375         <mads:namePart>
376             <xsl:call-template name="chopPunctuation">
377                 <xsl:with-param name="chopString">
378                     <xsl:call-template name="subfieldSelect">
379                         <xsl:with-param name="codes">aq</xsl:with-param>
380                     </xsl:call-template>
381                 </xsl:with-param>
382             </xsl:call-template>
383         </mads:namePart>
384         <xsl:call-template name="termsOfAddress"/>
385         <xsl:call-template name="nameDate"/>
386     </xsl:template>
387
388     <xsl:template name="nameACDENQ">
389         <mads:namePart>
390             <xsl:call-template name="subfieldSelect">
391                 <xsl:with-param name="codes">acdenq</xsl:with-param>
392             </xsl:call-template>
393         </mads:namePart>
394     </xsl:template>
395
396     <xsl:template name="nameDate">
397         <xsl:for-each select="marc:subfield[@code='d']">
398             <mads:namePart type="date">
399                 <xsl:call-template name="chopPunctuation">
400                     <xsl:with-param name="chopString" select="."/>
401                 </xsl:call-template>
402             </mads:namePart>
403         </xsl:for-each>
404     </xsl:template>
405
406     <xsl:template name="specialSubfieldSelect">
407         <xsl:param name="anyCodes"/>
408         <xsl:param name="axis"/>
409         <xsl:param name="beforeCodes"/>
410         <xsl:param name="afterCodes"/>
411         <xsl:variable name="str">
412             <xsl:for-each select="marc:subfield">
413                 <xsl:if
414                     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])">
415                     <xsl:value-of select="text()"/>
416                     <xsl:text> </xsl:text>
417                 </xsl:if>
418             </xsl:for-each>
419         </xsl:variable>
420         <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
421     </xsl:template>
422
423     <xsl:template name="termsOfAddress">
424         <xsl:if test="marc:subfield[@code='b' or @code='c']">
425             <mads:namePart type="termsOfAddress">
426                 <xsl:call-template name="chopPunctuation">
427                     <xsl:with-param name="chopString">
428                         <xsl:call-template name="subfieldSelect">
429                             <xsl:with-param name="codes">bc</xsl:with-param>
430                         </xsl:call-template>
431                     </xsl:with-param>
432                 </xsl:call-template>
433             </mads:namePart>
434         </xsl:if>
435     </xsl:template>
436
437     <xsl:template name="displayLabel">
438         <xsl:if test="marc:subfield[@code='z']">
439             <xsl:attribute name="displayLabel">
440                 <xsl:value-of select="marc:subfield[@code='z']"/>
441             </xsl:attribute>
442         </xsl:if>
443         <xsl:if test="marc:subfield[@code='3']">
444             <xsl:attribute name="displayLabel">
445                 <xsl:value-of select="marc:subfield[@code='3']"/>
446             </xsl:attribute>
447         </xsl:if>
448     </xsl:template>
449
450     <xsl:template name="isInvalid">
451         <xsl:if test="@code='z'">
452             <xsl:attribute name="invalid">yes</xsl:attribute>
453         </xsl:if>
454     </xsl:template>
455
456     <xsl:template name="sub2Attribute">
457         <!-- 024 -->
458         <xsl:if test="../marc:subfield[@code='2']">
459             <xsl:attribute name="type">
460                 <xsl:value-of select="../marc:subfield[@code='2']"/>
461             </xsl:attribute>
462         </xsl:if>
463     </xsl:template>
464
465     <xsl:template match="marc:controlfield[@tag=001]">
466         <mads:recordIdentifier>
467             <xsl:if test="../marc:controlfield[@tag=003]">
468                 <xsl:attribute name="source">
469                     <xsl:value-of select="../marc:controlfield[@tag=003]"/>
470                 </xsl:attribute>
471             </xsl:if>
472             <xsl:value-of select="."/>
473         </mads:recordIdentifier>
474     </xsl:template>
475
476     <xsl:template match="marc:controlfield[@tag=005]">
477         <mads:recordChangeDate encoding="iso8601">
478             <xsl:value-of select="."/>
479         </mads:recordChangeDate>
480     </xsl:template>
481
482     <xsl:template match="marc:controlfield[@tag=008]">
483         <mads:recordCreationDate encoding="marc">
484             <xsl:value-of select="substring(.,1,6)"/>
485         </mads:recordCreationDate>
486     </xsl:template>
487
488     <xsl:template match="marc:datafield[@tag=010]">
489         <xsl:for-each select="marc:subfield">
490             <mads:identifier type="lccn">
491                 <xsl:call-template name="isInvalid"/>
492                 <xsl:value-of select="."/>
493             </mads:identifier>
494         </xsl:for-each>
495     </xsl:template>
496
497     <xsl:template match="marc:datafield[@tag=024]">
498         <xsl:for-each select="marc:subfield[not(@code=2)]">
499             <mads:identifier>
500                 <xsl:call-template name="isInvalid"/>
501                 <xsl:call-template name="sub2Attribute"/>
502                 <xsl:value-of select="."/>
503             </mads:identifier>
504         </xsl:for-each>
505     </xsl:template>
506
507     <!-- ========== 372 ========== -->
508     <xsl:template match="marc:datafield[@tag=372]">
509         <mads:fieldOfActivity>
510             <xsl:call-template name="subfieldSelect">
511                 <xsl:with-param name="codes">a</xsl:with-param>
512             </xsl:call-template>
513             <xsl:text>-</xsl:text>
514             <xsl:call-template name="subfieldSelect">
515                 <xsl:with-param name="codes">st</xsl:with-param>
516             </xsl:call-template>
517         </mads:fieldOfActivity>
518     </xsl:template>
519
520
521     <!-- ========== 040 ========== -->
522     <xsl:template match="marc:datafield[@tag=040]/marc:subfield[@code='a']">
523         <mads:recordContentSource authority="marcorg">
524             <xsl:value-of select="."/>
525         </mads:recordContentSource>
526     </xsl:template>
527
528     <xsl:template match="marc:datafield[@tag=040]/marc:subfield[@code='b']">
529         <mads:languageOfCataloging>
530             <mads:languageTerm authority="iso639-2b" type="code">
531                 <xsl:value-of select="."/>
532             </mads:languageTerm>
533         </mads:languageOfCataloging>
534     </xsl:template>
535
536     <xsl:template match="marc:datafield[@tag=040]/marc:subfield[@code='e']">
537         <mads:descriptionStandard>
538             <xsl:value-of select="."/>
539         </mads:descriptionStandard>
540     </xsl:template>
541
542     <!-- ========== classification 2.03 ========== -->
543
544     <xsl:template match="marc:datafield[@tag=053]">
545         <mads:classification>
546             <xsl:value-of select="."/>
547         </mads:classification>
548     </xsl:template>
549     <xsl:template match="marc:datafield[@tag=055]">
550         <mads:classification>
551             <xsl:value-of select="."/>
552         </mads:classification>
553     </xsl:template>
554     <xsl:template match="marc:datafield[@tag=060]">
555         <mads:classification>
556             <xsl:value-of select="."/>
557         </mads:classification>
558     </xsl:template>
559     <xsl:template match="marc:datafield[@tag=065]">
560         <mads:classification>
561             <xsl:value-of select="."/>
562         </mads:classification>
563     </xsl:template>
564     <xsl:template match="marc:datafield[@tag=070]">
565         <mads:classification>
566             <xsl:value-of select="."/>
567         </mads:classification>
568     </xsl:template>
569     <xsl:template match="marc:datafield[@tag=080]">
570         <mads:classification>
571             <xsl:value-of select="."/>
572         </mads:classification>
573     </xsl:template>
574     <xsl:template match="marc:datafield[@tag=082]">
575         <mads:classification>
576             <xsl:value-of select="."/>
577         </mads:classification>
578     </xsl:template>
579     <xsl:template match="marc:datafield[@tag=083]">
580         <mads:classification>
581             <xsl:value-of select="."/>
582         </mads:classification>
583     </xsl:template>
584     <xsl:template match="marc:datafield[@tag=086]">
585         <mads:classification>
586             <xsl:value-of select="."/>
587         </mads:classification>
588     </xsl:template>
589     <xsl:template match="marc:datafield[@tag=087]">
590         <mads:classification>
591             <xsl:value-of select="."/>
592         </mads:classification>
593     </xsl:template>
594
595
596     <!-- ========== names  ========== -->
597     <xsl:template match="marc:datafield[@tag=100]">
598         <mads:name type="personal">
599             <xsl:call-template name="setAuthority"/>
600             <xsl:call-template name="nameABCDQ"/>
601         </mads:name>
602         <xsl:apply-templates select="*[marc:subfield[not(contains('abcdeq',@code))]]"/>
603         <xsl:call-template name="title"/>
604         <xsl:apply-templates select="marc:subfield[@code!='i']"/>
605     </xsl:template>
606
607     <xsl:template match="marc:datafield[@tag=110]">
608         <mads:name type="corporate">
609             <xsl:call-template name="setAuthority"/>
610             <xsl:call-template name="nameABCDN"/>
611         </mads:name>
612         <xsl:apply-templates select="marc:subfield[@code!='i']"/>
613     </xsl:template>
614
615     <xsl:template match="marc:datafield[@tag=111]">
616         <mads:name type="conference">
617             <xsl:call-template name="setAuthority"/>
618             <xsl:call-template name="nameACDENQ"/>
619         </mads:name>
620         <xsl:apply-templates select="marc:subfield[@code!='i']"/>
621     </xsl:template>
622
623     <xsl:template match="marc:datafield[@tag=400]">
624         <mads:variant>
625             <xsl:call-template name="variantTypeAttribute"/>
626             <mads:name type="personal">
627                 <xsl:call-template name="nameABCDQ"/>
628             </mads:name>
629             <xsl:apply-templates select="marc:subfield[@code!='i']"/>
630             <xsl:call-template name="title"/>
631         </mads:variant>
632     </xsl:template>
633
634     <xsl:template match="marc:datafield[@tag=410]">
635         <mads:variant>
636             <xsl:call-template name="variantTypeAttribute"/>
637             <mads:name type="corporate">
638                 <xsl:call-template name="nameABCDN"/>
639             </mads:name>
640             <xsl:apply-templates select="marc:subfield[@code!='i']"/>
641         </mads:variant>
642     </xsl:template>
643
644     <xsl:template match="marc:datafield[@tag=411]">
645         <mads:variant>
646             <xsl:call-template name="variantTypeAttribute"/>
647             <mads:name type="conference">
648                 <xsl:call-template name="nameACDENQ"/>
649             </mads:name>
650             <xsl:apply-templates select="marc:subfield[@code!='i']"/>
651         </mads:variant>
652     </xsl:template>
653
654     <xsl:template match="marc:datafield[@tag=500]|marc:datafield[@tag=700]">
655         <mads:related>
656             <xsl:call-template name="relatedTypeAttribute"/>
657             <!-- <xsl:call-template name="uri"/> -->
658             <mads:name type="personal">
659                 <xsl:call-template name="setAuthority"/>
660                 <xsl:call-template name="nameABCDQ"/>
661             </mads:name>
662             <xsl:call-template name="title"/>
663             <xsl:apply-templates select="marc:subfield[@code!='i']"/>
664         </mads:related>
665     </xsl:template>
666
667     <xsl:template match="marc:datafield[@tag=510]|marc:datafield[@tag=710]">
668         <mads:related>
669             <xsl:call-template name="relatedTypeAttribute"/>
670             <!-- <xsl:call-template name="uri"/> -->
671             <mads:name type="corporate">
672                 <xsl:call-template name="setAuthority"/>
673                 <xsl:call-template name="nameABCDN"/>
674             </mads:name>
675             <xsl:apply-templates select="marc:subfield[@code!='i']"/>
676         </mads:related>
677     </xsl:template>
678
679     <xsl:template match="marc:datafield[@tag=511]|marc:datafield[@tag=711]">
680         <mads:related>
681             <xsl:call-template name="relatedTypeAttribute"/>
682             <!-- <xsl:call-template name="uri"/> -->
683             <mads:name type="conference">
684                 <xsl:call-template name="setAuthority"/>
685                 <xsl:call-template name="nameACDENQ"/>
686             </mads:name>
687             <xsl:apply-templates select="marc:subfield[@code!='i']"/>
688         </mads:related>
689     </xsl:template>
690
691     <!-- ========== titles  ========== -->
692     <xsl:template match="marc:datafield[@tag=130]">
693         <xsl:call-template name="uniform-title"/>
694         <xsl:apply-templates select="marc:subfield[@code!='i']"/>
695     </xsl:template>
696
697     <xsl:template match="marc:datafield[@tag=430]">
698         <mads:variant>
699             <xsl:call-template name="variantTypeAttribute"/>
700             <xsl:call-template name="uniform-title"/>
701             <xsl:apply-templates select="marc:subfield[@code!='i']"/>
702         </mads:variant>
703     </xsl:template>
704
705     <xsl:template match="marc:datafield[@tag=530]|marc:datafield[@tag=730]">
706         <mads:related>
707             <xsl:call-template name="relatedTypeAttribute"/>
708             <xsl:call-template name="uniform-title"/>
709             <xsl:apply-templates select="marc:subfield[@code!='i']"/>
710         </mads:related>
711     </xsl:template>
712
713     <xsl:template name="title">
714         <xsl:variable name="hasTitle">
715             <xsl:for-each select="marc:subfield">
716                 <xsl:if test="(contains('tfghklmors',@code) )">
717                     <xsl:value-of select="@code"/>
718                 </xsl:if>
719             </xsl:for-each>
720         </xsl:variable>
721         <xsl:if test="string-length($hasTitle) &gt; 0 ">
722             <mads:titleInfo>
723                 <xsl:call-template name="setAuthority"/>
724                 <mads:title>
725                     <xsl:variable name="str">
726                         <xsl:for-each select="marc:subfield">
727                             <xsl:if test="(contains('atfghklmors',@code) )">
728                                 <xsl:value-of select="text()"/>
729                                 <xsl:text> </xsl:text>
730                             </xsl:if>
731                         </xsl:for-each>
732                     </xsl:variable>
733                     <xsl:call-template name="chopPunctuation">
734                         <xsl:with-param name="chopString">
735                             <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
736                         </xsl:with-param>
737                     </xsl:call-template>
738                 </mads:title>
739                 <xsl:call-template name="part"/>
740                 <!-- <xsl:call-template name="uri"/> -->
741             </mads:titleInfo>
742         </xsl:if>
743     </xsl:template>
744
745     <xsl:template name="uniform-title">
746         <xsl:variable name="hasTitle">
747             <xsl:for-each select="marc:subfield">
748                 <xsl:if test="(contains('atfghklmors',@code) )">
749                     <xsl:value-of select="@code"/>
750                 </xsl:if>
751             </xsl:for-each>
752         </xsl:variable>
753         <xsl:if test="string-length($hasTitle) &gt; 0 ">
754             <mads:titleInfo>
755                 <xsl:call-template name="setAuthority"/>
756                 <mads:title>
757                     <xsl:variable name="str">
758                         <xsl:for-each select="marc:subfield">
759                             <xsl:if test="(contains('adfghklmors',@code) )">
760                                 <xsl:value-of select="text()"/>
761                                 <xsl:text> </xsl:text>
762                             </xsl:if>
763                         </xsl:for-each>
764                     </xsl:variable>
765                     <xsl:call-template name="chopPunctuation">
766                         <xsl:with-param name="chopString">
767                             <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
768                         </xsl:with-param>
769                     </xsl:call-template>
770                 </mads:title>
771                 <xsl:call-template name="part"/>
772                 <!-- <xsl:call-template name="uri"/> -->
773             </mads:titleInfo>
774         </xsl:if>
775     </xsl:template>
776
777
778     <!-- ========== topics  ========== -->
779     <xsl:template match="marc:subfield[@code='x']">
780         <mads:topic>
781             <xsl:call-template name="chopPunctuation">
782                 <xsl:with-param name="chopString">
783                     <xsl:value-of select="."/>
784                 </xsl:with-param>
785             </xsl:call-template>
786         </mads:topic>
787     </xsl:template>
788
789     <!-- 2.06 fix -->
790     <xsl:template
791         match="marc:datafield[@tag=150][marc:subfield[@code='a' or @code='b']]|marc:datafield[@tag=180][marc:subfield[@code='x']]">
792         <xsl:call-template name="topic"/>
793         <xsl:apply-templates select="marc:subfield[@code!='i']"/>
794     </xsl:template>
795     <xsl:template
796         match="marc:datafield[@tag=450][marc:subfield[@code='a' or @code='b']]|marc:datafield[@tag=480][marc:subfield[@code='x']]">
797         <mads:variant>
798             <xsl:call-template name="variantTypeAttribute"/>
799             <xsl:call-template name="topic"/>
800         </mads:variant>
801     </xsl:template>
802     <xsl:template
803         match="marc:datafield[@tag=550 or @tag=750][marc:subfield[@code='a' or @code='b']]">
804         <mads:related>
805             <xsl:call-template name="relatedTypeAttribute"/>
806             <!-- <xsl:call-template name="uri"/> -->
807             <xsl:call-template name="topic"/>
808             <xsl:apply-templates select="marc:subfield[@code='z']"/>
809         </mads:related>
810     </xsl:template>
811     <xsl:template name="topic">
812         <mads:topic>
813             <xsl:call-template name="setAuthority"/>
814             <!-- tmee2006 dedupe 550a
815             <xsl:if test="@tag=550 or @tag=750">
816                 <xsl:call-template name="subfieldSelect">
817                     <xsl:with-param name="codes">ab</xsl:with-param>
818                 </xsl:call-template>
819             </xsl:if>
820             -->
821             <xsl:choose>
822                 <xsl:when test="@tag=180 or @tag=480 or @tag=580 or @tag=780">
823                     <xsl:call-template name="chopPunctuation">
824                         <xsl:with-param name="chopString">
825                             <xsl:apply-templates select="marc:subfield[@code='x']"/>
826                         </xsl:with-param>
827                     </xsl:call-template>
828                 </xsl:when>
829             </xsl:choose>
830             <xsl:call-template name="chopPunctuation">
831                 <xsl:with-param name="chopString">
832                     <xsl:choose>
833                         <xsl:when test="@tag=180 or @tag=480 or @tag=580 or @tag=780">
834                             <xsl:apply-templates select="marc:subfield[@code='x']"/>
835                         </xsl:when>
836                         <xsl:otherwise>
837                             <xsl:call-template name="subfieldSelect">
838                                 <xsl:with-param name="codes">ab</xsl:with-param>
839                             </xsl:call-template>
840                         </xsl:otherwise>
841                     </xsl:choose>
842                 </xsl:with-param>
843             </xsl:call-template>
844         </mads:topic>
845     </xsl:template>
846
847     <!-- ========= temporals  ========== -->
848     <xsl:template match="marc:subfield[@code='y']">
849         <mads:temporal>
850             <xsl:call-template name="chopPunctuation">
851                 <xsl:with-param name="chopString">
852                     <xsl:value-of select="."/>
853                 </xsl:with-param>
854             </xsl:call-template>
855         </mads:temporal>
856     </xsl:template>
857     <xsl:template
858         match="marc:datafield[@tag=148][marc:subfield[@code='a']]|marc:datafield[@tag=182 ][marc:subfield[@code='y']]">
859         <xsl:call-template name="temporal"/>
860     </xsl:template>
861     <xsl:template
862         match="marc:datafield[@tag=448][marc:subfield[@code='a']]|marc:datafield[@tag=482][marc:subfield[@code='y']]">
863         <mads:variant>
864             <xsl:call-template name="variantTypeAttribute"/>
865             <xsl:call-template name="temporal"/>
866         </mads:variant>
867     </xsl:template>
868     <xsl:template
869         match="marc:datafield[@tag=548 or @tag=748][marc:subfield[@code='a']]|marc:datafield[@tag=582 or @tag=782][marc:subfield[@code='y']]">
870         <mads:related>
871             <xsl:call-template name="relatedTypeAttribute"/>
872             <!-- <xsl:call-template name="uri"/> -->
873             <xsl:call-template name="temporal"/>
874         </mads:related>
875     </xsl:template>
876     <xsl:template name="temporal">
877         <mads:temporal>
878             <xsl:call-template name="setAuthority"/>
879             <xsl:if test="@tag=548 or @tag=748">
880                 <xsl:value-of select="marc:subfield[@code='a']"/>
881             </xsl:if>
882             <xsl:call-template name="chopPunctuation">
883                 <xsl:with-param name="chopString">
884                     <xsl:choose>
885                         <xsl:when test="@tag=182 or @tag=482 or @tag=582 or @tag=782">
886                             <xsl:apply-templates select="marc:subfield[@code='y']"/>
887                         </xsl:when>
888                         <xsl:otherwise>
889                             <xsl:value-of select="marc:subfield[@code='a']"/>
890                         </xsl:otherwise>
891                     </xsl:choose>
892                 </xsl:with-param>
893             </xsl:call-template>
894         </mads:temporal>
895         <xsl:apply-templates select="marc:subfield[@code!='i']"/>
896     </xsl:template>
897
898     <!-- ========== genre  ========== -->
899     <xsl:template match="marc:subfield[@code='v']">
900         <mads:genre>
901             <xsl:call-template name="chopPunctuation">
902                 <xsl:with-param name="chopString">
903                     <xsl:value-of select="."/>
904                 </xsl:with-param>
905             </xsl:call-template>
906         </mads:genre>
907     </xsl:template>
908     <xsl:template
909         match="marc:datafield[@tag=155][marc:subfield[@code='a']]|marc:datafield[@tag=185][marc:subfield[@code='v']]">
910         <xsl:call-template name="genre"/>
911     </xsl:template>
912     <xsl:template
913         match="marc:datafield[@tag=455][marc:subfield[@code='a']]|marc:datafield[@tag=485 ][marc:subfield[@code='v']]">
914         <mads:variant>
915             <xsl:call-template name="variantTypeAttribute"/>
916             <xsl:call-template name="genre"/>
917         </mads:variant>
918     </xsl:template>
919     <!--
920     <xsl:template match="marc:datafield[@tag=555]">
921         <mads:related>
922             <xsl:call-template name="relatedTypeAttribute"/>
923             <xsl:call-template name="uri"/>
924             <xsl:call-template name="genre"/>
925         </mads:related>
926     </xsl:template>
927     -->
928     <xsl:template
929         match="marc:datafield[@tag=555 or @tag=755][marc:subfield[@code='a']]|marc:datafield[@tag=585][marc:subfield[@code='v']]">
930         <mads:related>
931             <xsl:call-template name="relatedTypeAttribute"/>
932             <xsl:call-template name="genre"/>
933         </mads:related>
934     </xsl:template>
935     <xsl:template name="genre">
936         <mads:genre>
937             <xsl:if test="@tag=555">
938                 <xsl:value-of select="marc:subfield[@code='a']"/>
939             </xsl:if>
940             <xsl:call-template name="setAuthority"/>
941             <xsl:call-template name="chopPunctuation">
942                 <xsl:with-param name="chopString">
943                     <xsl:choose>
944                         <!-- 2.07 fix -->
945                         <xsl:when test="@tag='555'"/>
946                         <xsl:when test="@tag=185 or @tag=485 or @tag=585">
947                             <xsl:apply-templates select="marc:subfield[@code='v']"/>
948                         </xsl:when>
949                         <xsl:otherwise>
950                             <xsl:value-of select="marc:subfield[@code='a']"/>
951                         </xsl:otherwise>
952                     </xsl:choose>
953                 </xsl:with-param>
954             </xsl:call-template>
955         </mads:genre>
956         <xsl:apply-templates/>
957     </xsl:template>
958
959     <!-- ========= geographic  ========== -->
960     <xsl:template match="marc:subfield[@code='z']">
961         <mads:geographic>
962             <xsl:call-template name="chopPunctuation">
963                 <xsl:with-param name="chopString">
964                     <xsl:value-of select="."/>
965                 </xsl:with-param>
966             </xsl:call-template>
967         </mads:geographic>
968     </xsl:template>
969     <xsl:template name="geographic">
970         <mads:geographic>
971             <xsl:if test="@tag=551">
972                 <xsl:value-of select="marc:subfield[@code='a']"/>
973             </xsl:if>
974             <xsl:call-template name="setAuthority"/>
975             <xsl:call-template name="chopPunctuation">
976                 <xsl:with-param name="chopString">
977                     <xsl:choose>
978                         <xsl:when test="@tag=181 or @tag=481 or @tag=581">
979                             <xsl:apply-templates select="marc:subfield[@code='z']"/>
980                         </xsl:when>
981                         <xsl:otherwise>
982                             <xsl:value-of select="marc:subfield[@code='a']"/>
983                         </xsl:otherwise>
984                     </xsl:choose>
985                 </xsl:with-param>
986             </xsl:call-template>
987         </mads:geographic>
988         <xsl:apply-templates select="marc:subfield[@code!='i']"/>
989     </xsl:template>
990     <xsl:template
991         match="marc:datafield[@tag=151][marc:subfield[@code='a']]|marc:datafield[@tag=181][marc:subfield[@code='z']]">
992         <xsl:call-template name="geographic"/>
993     </xsl:template>
994     <xsl:template
995         match="marc:datafield[@tag=451][marc:subfield[@code='a']]|marc:datafield[@tag=481][marc:subfield[@code='z']]">
996         <mads:variant>
997             <xsl:call-template name="variantTypeAttribute"/>
998             <xsl:call-template name="geographic"/>
999         </mads:variant>
1000     </xsl:template>
1001     <xsl:template
1002         match="marc:datafield[@tag=551]|marc:datafield[@tag=581][marc:subfield[@code='z']]">
1003         <mads:related>
1004             <xsl:call-template name="relatedTypeAttribute"/>
1005             <!-- <xsl:call-template name="uri"/> -->
1006             <xsl:call-template name="geographic"/>
1007         </mads:related>
1008     </xsl:template>
1009     <xsl:template match="marc:datafield[@tag=580]">
1010         <mads:related>
1011             <xsl:call-template name="relatedTypeAttribute"/>
1012             <xsl:apply-templates select="marc:subfield[@code!='i']"/>
1013         </mads:related>
1014     </xsl:template>
1015     <xsl:template
1016         match="marc:datafield[@tag=751][marc:subfield[@code='z']]|marc:datafield[@tag=781][marc:subfield[@code='z']]">
1017         <mads:related>
1018             <xsl:call-template name="relatedTypeAttribute"/>
1019             <xsl:call-template name="geographic"/>
1020         </mads:related>
1021     </xsl:template>
1022     <xsl:template match="marc:datafield[@tag=755]">
1023         <mads:related>
1024             <xsl:call-template name="relatedTypeAttribute"/>
1025             <xsl:call-template name="genre"/>
1026             <xsl:call-template name="setAuthority"/>
1027             <xsl:apply-templates select="marc:subfield[@code!='i']"/>
1028         </mads:related>
1029     </xsl:template>
1030     <xsl:template match="marc:datafield[@tag=780]">
1031         <mads:related>
1032             <xsl:call-template name="relatedTypeAttribute"/>
1033             <xsl:apply-templates select="marc:subfield[@code!='i']"/>
1034         </mads:related>
1035     </xsl:template>
1036     <xsl:template match="marc:datafield[@tag=785]">
1037         <mads:related>
1038             <xsl:call-template name="relatedTypeAttribute"/>
1039             <xsl:apply-templates select="marc:subfield[@code!='i']"/>
1040         </mads:related>
1041     </xsl:template>
1042
1043     <!-- ========== notes  ========== -->
1044     <xsl:template match="marc:datafield[667 &lt;= @tag and @tag &lt;= 688]">
1045         <mads:note>
1046             <xsl:choose>
1047                 <xsl:when test="@tag=667">
1048                     <xsl:attribute name="type">nonpublic</xsl:attribute>
1049                 </xsl:when>
1050                 <xsl:when test="@tag=670">
1051                     <xsl:attribute name="type">source</xsl:attribute>
1052                 </xsl:when>
1053                 <xsl:when test="@tag=675">
1054                     <xsl:attribute name="type">notFound</xsl:attribute>
1055                 </xsl:when>
1056                 <xsl:when test="@tag=678">
1057                     <xsl:attribute name="type">history</xsl:attribute>
1058                 </xsl:when>
1059                 <xsl:when test="@tag=681">
1060                     <xsl:attribute name="type">subject example</xsl:attribute>
1061                 </xsl:when>
1062                 <xsl:when test="@tag=682">
1063                     <xsl:attribute name="type">deleted heading information</xsl:attribute>
1064                 </xsl:when>
1065                 <xsl:when test="@tag=688">
1066                     <xsl:attribute name="type">application history</xsl:attribute>
1067                 </xsl:when>
1068             </xsl:choose>
1069             <xsl:call-template name="chopPunctuation">
1070                 <xsl:with-param name="chopString">
1071                     <xsl:choose>
1072                         <xsl:when test="@tag=667 or @tag=675">
1073                             <xsl:value-of select="marc:subfield[@code='a']"/>
1074                         </xsl:when>
1075                         <xsl:when test="@tag=670 or @tag=678">
1076                             <xsl:call-template name="subfieldSelect">
1077                                 <xsl:with-param name="codes">ab</xsl:with-param>
1078                             </xsl:call-template>
1079                         </xsl:when>
1080                         <xsl:when test="680 &lt;= @tag and @tag &lt;=688">
1081                             <xsl:call-template name="subfieldSelect">
1082                                 <xsl:with-param name="codes">ai</xsl:with-param>
1083                             </xsl:call-template>
1084                         </xsl:when>
1085                     </xsl:choose>
1086                 </xsl:with-param>
1087             </xsl:call-template>
1088         </mads:note>
1089     </xsl:template>
1090
1091     <!-- ========== url  ========== -->
1092     <xsl:template match="marc:datafield[@tag=856][marc:subfield[@code='u']]">
1093         <mads:url>
1094             <xsl:if test="marc:subfield[@code='z' or @code='3']">
1095                 <xsl:attribute name="displayLabel">
1096                     <xsl:call-template name="subfieldSelect">
1097                         <xsl:with-param name="codes">z3</xsl:with-param>
1098                     </xsl:call-template>
1099                 </xsl:attribute>
1100             </xsl:if>
1101             <xsl:value-of select="marc:subfield[@code='u']"/>
1102         </mads:url>
1103     </xsl:template>
1104
1105     <xsl:template name="relatedTypeAttribute">
1106         <xsl:choose>
1107             <xsl:when
1108                 test="@tag=500 or @tag=510 or @tag=511 or @tag=548 or @tag=550 or @tag=551 or @tag=555 or @tag=580 or @tag=581 or @tag=582 or @tag=585">
1109                 <xsl:if test="substring(marc:subfield[@code='w'],1,1)='a'">
1110                     <xsl:attribute name="type">earlier</xsl:attribute>
1111                 </xsl:if>
1112                 <xsl:if test="substring(marc:subfield[@code='w'],1,1)='b'">
1113                     <xsl:attribute name="type">later</xsl:attribute>
1114                 </xsl:if>
1115                 <xsl:if test="substring(marc:subfield[@code='w'],1,1)='t'">
1116                     <xsl:attribute name="type">parentOrg</xsl:attribute>
1117                 </xsl:if>
1118                 <xsl:if test="substring(marc:subfield[@code='w'],1,1)='g'">
1119                     <xsl:attribute name="type">broader</xsl:attribute>
1120                 </xsl:if>
1121                 <xsl:if test="substring(marc:subfield[@code='w'],1,1)='h'">
1122                     <xsl:attribute name="type">narrower</xsl:attribute>
1123                 </xsl:if>
1124                 <xsl:if test="substring(marc:subfield[@code='w'],1,1)='r'">
1125                     <xsl:attribute name="type">other</xsl:attribute>
1126                 </xsl:if>
1127                 <xsl:if test="contains('fin|', substring(marc:subfield[@code='w'],1,1))">
1128                     <xsl:attribute name="type">other</xsl:attribute>
1129                 </xsl:if>
1130             </xsl:when>
1131             <xsl:when test="@tag=530 or @tag=730">
1132                 <xsl:attribute name="type">other</xsl:attribute>
1133             </xsl:when>
1134             <xsl:otherwise>
1135                 <!-- 7xx -->
1136                 <xsl:attribute name="type">equivalent</xsl:attribute>
1137             </xsl:otherwise>
1138         </xsl:choose>
1139         <xsl:apply-templates select="marc:subfield[@code='i']"/>
1140     </xsl:template>
1141
1142     <xsl:template name="variantTypeAttribute">
1143         <xsl:choose>
1144             <xsl:when
1145                 test="@tag=400 or @tag=410 or @tag=411 or @tag=451 or @tag=455 or @tag=480 or @tag=481 or @tag=482 or @tag=485">
1146                 <xsl:if test="substring(marc:subfield[@code='w'],1,1)='d'">
1147                     <xsl:attribute name="type">acronym</xsl:attribute>
1148                 </xsl:if>
1149                 <xsl:if test="substring(marc:subfield[@code='w'],1,1)='n'">
1150                     <xsl:attribute name="type">other</xsl:attribute>
1151                 </xsl:if>
1152                 <xsl:if test="contains('fit', substring(marc:subfield[@code='w'],1,1))">
1153                     <xsl:attribute name="type">other</xsl:attribute>
1154                 </xsl:if>
1155             </xsl:when>
1156             <xsl:otherwise>
1157                 <!-- 430  -->
1158                 <xsl:attribute name="type">other</xsl:attribute>
1159             </xsl:otherwise>
1160         </xsl:choose>
1161         <xsl:apply-templates select="marc:subfield[@code='i']"/>
1162     </xsl:template>
1163
1164     <xsl:template name="setAuthority">
1165         <xsl:choose>
1166             <!-- can be called from the datafield or subfield level, so "..//@tag" means
1167             the tag can be at the subfield's parent level or at the datafields own level -->
1168
1169             <xsl:when
1170                 test="ancestor-or-self::marc:datafield/@tag=100 and (@ind1=0 or @ind1=1) and $controlField008-11='a' and $controlField008-14='a'">
1171                 <xsl:attribute name="authority">
1172                     <xsl:text>naf</xsl:text>
1173                 </xsl:attribute>
1174             </xsl:when>
1175             <xsl:when
1176                 test="ancestor-or-self::marc:datafield/@tag=100 and (@ind1=0 or @ind1=1) and $controlField008-11='a' and $controlField008-14='b'">
1177                 <xsl:attribute name="authority">
1178                     <xsl:text>lcsh</xsl:text>
1179                 </xsl:attribute>
1180             </xsl:when>
1181             <xsl:when
1182                 test="ancestor-or-self::marc:datafield/@tag=100 and (@ind1=0 or @ind1=1) and $controlField008-11='k'">
1183                 <xsl:attribute name="authority">
1184                     <xsl:text>lacnaf</xsl:text>
1185                 </xsl:attribute>
1186             </xsl:when>
1187             <xsl:when
1188                 test="ancestor-or-self::marc:datafield/@tag=100 and @ind1=3 and $controlField008-11='a' and $controlField008-14='b'">
1189                 <xsl:attribute name="authority">
1190                     <xsl:text>lcsh</xsl:text>
1191                 </xsl:attribute>
1192             </xsl:when>
1193             <xsl:when
1194                 test="ancestor-or-self::marc:datafield/@tag=100 and @ind1=3 and $controlField008-11='k' and $controlField008-14='b'">
1195                 <xsl:attribute name="authority">cash</xsl:attribute>
1196             </xsl:when>
1197             <xsl:when
1198                 test="ancestor-or-self::marc:datafield/@tag=110 and $controlField008-11='a' and $controlField008-14='a'">
1199                 <xsl:attribute name="authority">naf</xsl:attribute>
1200             </xsl:when>
1201             <xsl:when
1202                 test="ancestor-or-self::marc:datafield/@tag=110 and $controlField008-11='a' and $controlField008-14='b'">
1203                 <xsl:attribute name="authority">lcsh</xsl:attribute>
1204             </xsl:when>
1205             <xsl:when
1206                 test="ancestor-or-self::marc:datafield/@tag=110 and $controlField008-11='k' and $controlField008-14='a'">
1207                 <xsl:attribute name="authority">
1208                     <xsl:text>lacnaf</xsl:text>
1209                 </xsl:attribute>
1210             </xsl:when>
1211             <xsl:when
1212                 test="ancestor-or-self::marc:datafield/@tag=110 and $controlField008-11='k' and $controlField008-14='b'">
1213                 <xsl:attribute name="authority">
1214                     <xsl:text>cash</xsl:text>
1215                 </xsl:attribute>
1216             </xsl:when>
1217             <xsl:when
1218                 test="100 &lt;= ancestor-or-self::marc:datafield/@tag and ancestor-or-self::marc:datafield/@tag &lt;= 155 and $controlField008-11='b'">
1219                 <xsl:attribute name="authority">
1220                     <xsl:text>lcshcl</xsl:text>
1221                 </xsl:attribute>
1222             </xsl:when>
1223             <xsl:when
1224                 test="(ancestor-or-self::marc:datafield/@tag=100 or ancestor-or-self::marc:datafield/@tag=110 or ancestor-or-self::marc:datafield/@tag=111 or ancestor-or-self::marc:datafield/@tag=130 or ancestor-or-self::marc:datafield/@tag=151) and $controlField008-11='c'">
1225                 <xsl:attribute name="authority">
1226                     <xsl:text>nlmnaf</xsl:text>
1227                 </xsl:attribute>
1228             </xsl:when>
1229             <xsl:when
1230                 test="(ancestor-or-self::marc:datafield/@tag=100 or ancestor-or-self::marc:datafield/@tag=110 or ancestor-or-self::marc:datafield/@tag=111 or ancestor-or-self::marc:datafield/@tag=130 or ancestor-or-self::marc:datafield/@tag=151) and $controlField008-11='d'">
1231                 <xsl:attribute name="authority">
1232                     <xsl:text>nalnaf</xsl:text>
1233                 </xsl:attribute>
1234             </xsl:when>
1235             <xsl:when
1236                 test="100 &lt;= ancestor-or-self::marc:datafield/@tag and ancestor-or-self::marc:datafield/@tag &lt;= 155 and $controlField008-11='r'">
1237                 <xsl:attribute name="authority">
1238                     <xsl:text>aat</xsl:text>
1239                 </xsl:attribute>
1240             </xsl:when>
1241             <xsl:when
1242                 test="100 &lt;= ancestor-or-self::marc:datafield/@tag and ancestor-or-self::marc:datafield/@tag &lt;= 155 and $controlField008-11='s'">
1243                 <xsl:attribute name="authority">sears</xsl:attribute>
1244             </xsl:when>
1245             <xsl:when
1246                 test="100 &lt;= ancestor-or-self::marc:datafield/@tag and ancestor-or-self::marc:datafield/@tag &lt;= 155 and $controlField008-11='v'">
1247                 <xsl:attribute name="authority">rvm</xsl:attribute>
1248             </xsl:when>
1249             <xsl:when
1250                 test="100 &lt;= ancestor-or-self::marc:datafield/@tag and ancestor-or-self::marc:datafield/@tag &lt;= 155 and $controlField008-11='z'">
1251                 <xsl:attribute name="authority">
1252                     <xsl:value-of
1253                         select="../marc:datafield[ancestor-or-self::marc:datafield/@tag=040]/marc:subfield[@code='f']"
1254                     />
1255                 </xsl:attribute>
1256             </xsl:when>
1257             <xsl:when
1258                 test="(ancestor-or-self::marc:datafield/@tag=111 or ancestor-or-self::marc:datafield/@tag=130) and $controlField008-11='a' and $controlField008-14='a'">
1259                 <xsl:attribute name="authority">
1260                     <xsl:text>naf</xsl:text>
1261                 </xsl:attribute>
1262             </xsl:when>
1263             <xsl:when
1264                 test="(ancestor-or-self::marc:datafield/@tag=111 or ancestor-or-self::marc:datafield/@tag=130) and $controlField008-11='a' and $controlField008-14='b'">
1265                 <xsl:attribute name="authority">
1266                     <xsl:text>lcsh</xsl:text>
1267                 </xsl:attribute>
1268             </xsl:when>
1269             <xsl:when
1270                 test="(ancestor-or-self::marc:datafield/@tag=111 or ancestor-or-self::marc:datafield/@tag=130) and $controlField008-11='k' ">
1271                 <xsl:attribute name="authority">
1272                     <xsl:text>lacnaf</xsl:text>
1273                 </xsl:attribute>
1274             </xsl:when>
1275             <xsl:when
1276                 test="(ancestor-or-self::marc:datafield/@tag=148 or ancestor-or-self::marc:datafield/@tag=150  or ancestor-or-self::marc:datafield/@tag=155) and $controlField008-11='a' ">
1277                 <xsl:attribute name="authority">
1278                     <xsl:text>lcsh</xsl:text>
1279                 </xsl:attribute>
1280             </xsl:when>
1281             <xsl:when
1282                 test="(ancestor-or-self::marc:datafield/@tag=148 or ancestor-or-self::marc:datafield/@tag=150  or ancestor-or-self::marc:datafield/@tag=155) and $controlField008-11='a' ">
1283                 <xsl:attribute name="authority">
1284                     <xsl:text>lcsh</xsl:text>
1285                 </xsl:attribute>
1286             </xsl:when>
1287             <xsl:when
1288                 test="(ancestor-or-self::marc:datafield/@tag=148 or ancestor-or-self::marc:datafield/@tag=150  or ancestor-or-self::marc:datafield/@tag=155) and $controlField008-11='c' ">
1289                 <xsl:attribute name="authority">
1290                     <xsl:text>mesh</xsl:text>
1291                 </xsl:attribute>
1292             </xsl:when>
1293             <xsl:when
1294                 test="(ancestor-or-self::marc:datafield/@tag=148 or ancestor-or-self::marc:datafield/@tag=150  or ancestor-or-self::marc:datafield/@tag=155) and $controlField008-11='d' ">
1295                 <xsl:attribute name="authority">
1296                     <xsl:text>nal</xsl:text>
1297                 </xsl:attribute>
1298             </xsl:when>
1299             <xsl:when
1300                 test="(ancestor-or-self::marc:datafield/@tag=148 or ancestor-or-self::marc:datafield/@tag=150  or ancestor-or-self::marc:datafield/@tag=155) and $controlField008-11='k' ">
1301                 <xsl:attribute name="authority">
1302                     <xsl:text>cash</xsl:text>
1303                 </xsl:attribute>
1304             </xsl:when>
1305             <xsl:when
1306                 test="ancestor-or-self::marc:datafield/@tag=151 and $controlField008-11='a' and $controlField008-14='a'">
1307                 <xsl:attribute name="authority">
1308                     <xsl:text>naf</xsl:text>
1309                 </xsl:attribute>
1310             </xsl:when>
1311             <xsl:when
1312                 test="ancestor-or-self::marc:datafield/@tag=151 and $controlField008-11='a' and $controlField008-14='b'">
1313                 <xsl:attribute name="authority">lcsh</xsl:attribute>
1314             </xsl:when>
1315             <xsl:when
1316                 test="ancestor-or-self::marc:datafield/@tag=151 and $controlField008-11='k' and $controlField008-14='a'">
1317                 <xsl:attribute name="authority">lacnaf</xsl:attribute>
1318             </xsl:when>
1319             <xsl:when
1320                 test="ancestor-or-self::marc:datafield/@tag=151 and $controlField008-11='k' and $controlField008-14='b'">
1321                 <xsl:attribute name="authority">cash</xsl:attribute>
1322             </xsl:when>
1323             <xsl:when
1324                 test="(..//ancestor-or-self::marc:datafield/@tag=180 or ..//ancestor-or-self::marc:datafield/@tag=181 or ..//ancestor-or-self::marc:datafield/@tag=182 or ..//ancestor-or-self::marc:datafield/@tag=185) and $controlField008-11='a'">
1325                 <xsl:attribute name="authority">lcsh</xsl:attribute>
1326             </xsl:when>
1327             <xsl:when
1328                 test="ancestor-or-self::marc:datafield/@tag=700 and (@ind1='0' or @ind1='1') and @ind2='0'">
1329                 <xsl:attribute name="authority">naf</xsl:attribute>
1330             </xsl:when>
1331             <xsl:when
1332                 test="ancestor-or-self::marc:datafield/@tag=700 and (@ind1='0' or @ind1='1') and @ind2='5'">
1333                 <xsl:attribute name="authority">lacnaf</xsl:attribute>
1334             </xsl:when>
1335             <xsl:when test="ancestor-or-self::marc:datafield/@tag=700 and @ind1='3' and @ind2='0'">
1336                 <xsl:attribute name="authority">lcsh</xsl:attribute>
1337             </xsl:when>
1338             <xsl:when test="ancestor-or-self::marc:datafield/@tag=700 and @ind1='3' and @ind2='5'">
1339                 <xsl:attribute name="authority">cash</xsl:attribute>
1340             </xsl:when>
1341             <xsl:when
1342                 test="(700 &lt;= ancestor-or-self::marc:datafield/@tag and ancestor-or-self::marc:datafield/@tag &lt;= 755 ) and @ind2='1'">
1343                 <xsl:attribute name="authority">lcshcl</xsl:attribute>
1344             </xsl:when>
1345             <xsl:when
1346                 test="(ancestor-or-self::marc:datafield/@tag=700 or ancestor-or-self::marc:datafield/@tag=710 or ancestor-or-self::marc:datafield/@tag=711 or ancestor-or-self::marc:datafield/@tag=730 or ancestor-or-self::marc:datafield/@tag=751)  and @ind2='2'">
1347                 <xsl:attribute name="authority">nlmnaf</xsl:attribute>
1348             </xsl:when>
1349             <xsl:when
1350                 test="(ancestor-or-self::marc:datafield/@tag=700 or ancestor-or-self::marc:datafield/@tag=710 or ancestor-or-self::marc:datafield/@tag=711 or ancestor-or-self::marc:datafield/@tag=730 or ancestor-or-self::marc:datafield/@tag=751)  and @ind2='3'">
1351                 <xsl:attribute name="authority">nalnaf</xsl:attribute>
1352             </xsl:when>
1353             <xsl:when
1354                 test="(700 &lt;= ancestor-or-self::marc:datafield/@tag and ancestor-or-self::marc:datafield/@tag &lt;= 755 ) and @ind2='6'">
1355                 <xsl:attribute name="authority">rvm</xsl:attribute>
1356             </xsl:when>
1357             <xsl:when
1358                 test="(700 &lt;= ancestor-or-self::marc:datafield/@tag and ancestor-or-self::marc:datafield/@tag &lt;= 755 ) and @ind2='7'">
1359                 <xsl:attribute name="authority">
1360                     <xsl:value-of select="marc:subfield[@code='2']"/>
1361                 </xsl:attribute>
1362             </xsl:when>
1363             <xsl:when
1364                 test="(ancestor-or-self::marc:datafield/@tag=710 or ancestor-or-self::marc:datafield/@tag=711 or ancestor-or-self::marc:datafield/@tag=730 or ancestor-or-self::marc:datafield/@tag=751)  and @ind2='5'">
1365                 <xsl:attribute name="authority">lacnaf</xsl:attribute>
1366             </xsl:when>
1367             <xsl:when
1368                 test="(ancestor-or-self::marc:datafield/@tag=710 or ancestor-or-self::marc:datafield/@tag=711 or ancestor-or-self::marc:datafield/@tag=730 or ancestor-or-self::marc:datafield/@tag=751)  and @ind2='0'">
1369                 <xsl:attribute name="authority">naf</xsl:attribute>
1370             </xsl:when>
1371             <xsl:when
1372                 test="(ancestor-or-self::marc:datafield/@tag=748 or ancestor-or-self::marc:datafield/@tag=750 or ancestor-or-self::marc:datafield/@tag=755)  and @ind2='0'">
1373                 <xsl:attribute name="authority">lcsh</xsl:attribute>
1374             </xsl:when>
1375             <xsl:when
1376                 test="(ancestor-or-self::marc:datafield/@tag=748 or ancestor-or-self::marc:datafield/@tag=750 or ancestor-or-self::marc:datafield/@tag=755)  and @ind2='2'">
1377                 <xsl:attribute name="authority">mesh</xsl:attribute>
1378             </xsl:when>
1379             <xsl:when
1380                 test="(ancestor-or-self::marc:datafield/@tag=748 or ancestor-or-self::marc:datafield/@tag=750 or ancestor-or-self::marc:datafield/@tag=755)  and @ind2='3'">
1381                 <xsl:attribute name="authority">nal</xsl:attribute>
1382             </xsl:when>
1383             <xsl:when
1384                 test="(ancestor-or-self::marc:datafield/@tag=748 or ancestor-or-self::marc:datafield/@tag=750 or ancestor-or-self::marc:datafield/@tag=755)  and @ind2='5'">
1385                 <xsl:attribute name="authority">cash</xsl:attribute>
1386             </xsl:when>
1387         </xsl:choose>
1388     </xsl:template>
1389     <xsl:template match="*"/>
1390 </xsl:stylesheet>