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