LP#1638299: MADS 2.1 stylesheet
[working/Evergreen.git] / Open-ILS / src / sql / Pg / upgrade / XXXX.data.MADS21-xsl.sql
1 INSERT INTO config.xml_transform (name,namespace_uri,prefix,xslt) VALUES ('mads21','http://www.loc.gov/mads/v2','mads21',$XSLT$<?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         <xsl:output method="xml" indent="yes" encoding="UTF-8"/>
6         <xsl:strip-space elements="*"/>
7
8         <xsl:variable name="ascii">
9                 <xsl:text> !"#$%&amp;'()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~</xsl:text>
10         </xsl:variable>
11
12         <xsl:variable name="latin1">
13                 <xsl:text> ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ</xsl:text>
14         </xsl:variable>
15         <!-- Characters that usually don't need to be escaped -->
16         <xsl:variable name="safe">
17                 <xsl:text>!'()*-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~</xsl:text>
18         </xsl:variable>
19
20         <xsl:variable name="hex">0123456789ABCDEF</xsl:variable>
21
22
23         <xsl:template name="datafield">
24                 <xsl:param name="tag"/>
25                 <xsl:param name="ind1">
26                         <xsl:text> </xsl:text>
27                 </xsl:param>
28                 <xsl:param name="ind2">
29                         <xsl:text> </xsl:text>
30                 </xsl:param>
31                 <xsl:param name="subfields"/>
32                 <xsl:element name="marc:datafield">
33                         <xsl:attribute name="tag">
34                                 <xsl:value-of select="$tag"/>
35                         </xsl:attribute>
36                         <xsl:attribute name="ind1">
37                                 <xsl:value-of select="$ind1"/>
38                         </xsl:attribute>
39                         <xsl:attribute name="ind2">
40                                 <xsl:value-of select="$ind2"/>
41                         </xsl:attribute>
42                         <xsl:copy-of select="$subfields"/>
43                 </xsl:element>
44         </xsl:template>
45
46         <xsl:template name="subfieldSelect">
47                 <xsl:param name="codes">abcdefghijklmnopqrstuvwxyz</xsl:param>
48                 <xsl:param name="delimeter">
49                         <xsl:text> </xsl:text>
50                 </xsl:param>
51                 <xsl:variable name="str">
52                         <xsl:for-each select="marc:subfield">
53                                 <xsl:if test="contains($codes, @code)">
54                                         <xsl:value-of select="text()"/>
55                                         <xsl:value-of select="$delimeter"/>
56                                 </xsl:if>
57                         </xsl:for-each>
58                 </xsl:variable>
59                 <xsl:value-of select="substring($str,1,string-length($str)-string-length($delimeter))"/>
60         </xsl:template>
61
62         <xsl:template name="buildSpaces">
63                 <xsl:param name="spaces"/>
64                 <xsl:param name="char">
65                         <xsl:text> </xsl:text>
66                 </xsl:param>
67                 <xsl:if test="$spaces>0">
68                         <xsl:value-of select="$char"/>
69                         <xsl:call-template name="buildSpaces">
70                                 <xsl:with-param name="spaces" select="$spaces - 1"/>
71                                 <xsl:with-param name="char" select="$char"/>
72                         </xsl:call-template>
73                 </xsl:if>
74         </xsl:template>
75
76         <xsl:template name="chopPunctuation">
77                 <xsl:param name="chopString"/>
78                 <xsl:param name="punctuation">
79                         <xsl:text>.:,;/ </xsl:text>
80                 </xsl:param>
81                 <xsl:variable name="length" select="string-length($chopString)"/>
82                 <xsl:choose>
83                         <xsl:when test="$length=0"/>
84                         <xsl:when test="contains($punctuation, substring($chopString,$length,1))">
85                                 <xsl:call-template name="chopPunctuation">
86                                         <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
87                                         <xsl:with-param name="punctuation" select="$punctuation"/>
88                                 </xsl:call-template>
89                         </xsl:when>
90                         <xsl:when test="not($chopString)"/>
91                         <xsl:otherwise>
92                                 <xsl:value-of select="$chopString"/>
93                         </xsl:otherwise>
94                 </xsl:choose>
95         </xsl:template>
96
97         <xsl:template name="chopPunctuationFront">
98                 <xsl:param name="chopString"/>
99                 <xsl:variable name="length" select="string-length($chopString)"/>
100                 <xsl:choose>
101                         <xsl:when test="$length=0"/>
102                         <xsl:when test="contains('.:,;/[ ', substring($chopString,1,1))">
103                                 <xsl:call-template name="chopPunctuationFront">
104                                         <xsl:with-param name="chopString" select="substring($chopString,2,$length - 1)"
105                                         />
106                                 </xsl:call-template>
107                         </xsl:when>
108                         <xsl:when test="not($chopString)"/>
109                         <xsl:otherwise>
110                                 <xsl:value-of select="$chopString"/>
111                         </xsl:otherwise>
112                 </xsl:choose>
113         </xsl:template>
114
115         <xsl:template name="chopPunctuationBack">
116                 <xsl:param name="chopString"/>
117                 <xsl:param name="punctuation">
118                         <xsl:text>.:,;/] </xsl:text>
119                 </xsl:param>
120                 <xsl:variable name="length" select="string-length($chopString)"/>
121                 <xsl:choose>
122                         <xsl:when test="$length=0"/>
123                         <xsl:when test="contains($punctuation, substring($chopString,$length,1))">
124                                 <xsl:call-template name="chopPunctuation">
125                                         <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
126                                         <xsl:with-param name="punctuation" select="$punctuation"/>
127                                 </xsl:call-template>
128                         </xsl:when>
129                         <xsl:when test="not($chopString)"/>
130                         <xsl:otherwise>
131                                 <xsl:value-of select="$chopString"/>
132                         </xsl:otherwise>
133                 </xsl:choose>
134         </xsl:template>
135
136         <!-- nate added 12/14/2007 for lccn.loc.gov: url encode ampersand, etc. -->
137         <xsl:template name="url-encode">
138
139                 <xsl:param name="str"/>
140
141                 <xsl:if test="$str">
142                         <xsl:variable name="first-char" select="substring($str,1,1)"/>
143                         <xsl:choose>
144                                 <xsl:when test="contains($safe,$first-char)">
145                                         <xsl:value-of select="$first-char"/>
146                                 </xsl:when>
147                                 <xsl:otherwise>
148                                         <xsl:variable name="codepoint">
149                                                 <xsl:choose>
150                                                         <xsl:when test="contains($ascii,$first-char)">
151                                                                 <xsl:value-of
152                                                                         select="string-length(substring-before($ascii,$first-char)) + 32"
153                                                                 />
154                                                         </xsl:when>
155                                                         <xsl:when test="contains($latin1,$first-char)">
156                                                                 <xsl:value-of
157                                                                         select="string-length(substring-before($latin1,$first-char)) + 160"/>
158                                                                 <!-- was 160 -->
159                                                         </xsl:when>
160                                                         <xsl:otherwise>
161                                                                 <xsl:message terminate="no">Warning: string contains a character
162                                                                         that is out of range! Substituting "?".</xsl:message>
163                                                                 <xsl:text>63</xsl:text>
164                                                         </xsl:otherwise>
165                                                 </xsl:choose>
166                                         </xsl:variable>
167                                         <xsl:variable name="hex-digit1"
168                                                 select="substring($hex,floor($codepoint div 16) + 1,1)"/>
169                                         <xsl:variable name="hex-digit2" select="substring($hex,$codepoint mod 16 + 1,1)"/>
170                                         <!-- <xsl:value-of select="concat('%',$hex-digit2)"/> -->
171                                         <xsl:value-of select="concat('%',$hex-digit1,$hex-digit2)"/>
172                                 </xsl:otherwise>
173                         </xsl:choose>
174                         <xsl:if test="string-length($str) &gt; 1">
175                                 <xsl:call-template name="url-encode">
176                                         <xsl:with-param name="str" select="substring($str,2)"/>
177                                 </xsl:call-template>
178                         </xsl:if>
179                 </xsl:if>
180         </xsl:template>
181
182
183 <!--
184 2.14    Fixed bug in mads:geographic attributes syntax                                      ws   05/04/2016             
185 2.13    fixed repeating <geographic>                                                                                                            tmee 01/31/2014
186 2.12    added $2 authority for <classification>                                                                                         tmee 09/18/2012
187 2.11    added delimiters between <classification> subfields                                                                     tmee 09/18/2012
188 2.10    fixed type="other" and type="otherType" for mads:related                                                        tmee 09/16/2011
189 2.09    fixed professionTerm and genreTerm empty tag error                                                                      tmee 09/16/2011
190 2.08    fixed marc:subfield @code='i' matching error                                                                            tmee 09/16/2011
191 2.07    fixed 555 duplication error                                                                                                                     tmee 08/10/2011 
192 2.06    fixed topic subfield error                                                                                                                      tmee 08/10/2011 
193 2.05    fixed title subfield error                                                                                                                      tmee 06/20/2011 
194 2.04    fixed geographicSubdivision mapping for authority element                                                       tmee 06/16/2011
195 2.03    added classification for 053, 055, 060, 065, 070, 080, 082, 083, 086, 087                       tmee 06/03/2011         
196 2.02    added descriptionStandard for 008/10                                                                                            tmee 04/27/2011
197 2.01    added extensions for 046, 336, 370, 374, 375, 376                                                                       tmee 04/08/2011
198 2.00    redefined imported MODS elements in version 1.0 to MADS elements in version 2.0         tmee 02/08/2011
199 1.08    added 372 subfields $a $s $t for <fieldOfActivity>                                                                      tmee 06/24/2010
200 1.07    removed role/roleTerm 100, 110, 111, 400, 410, 411, 500, 510, 511, 700, 710, 711        tmee 06/24/2010
201 1.06    added strip-space                                                                                                                                       tmee 06/24/2010
202 1.05    added subfield $a for 130, 430, 530                                                                                                     tmee 06/21/2010
203 1.04    fixed 550 z omission                                                                                                                            ntra 08/11/2008
204 1.03    removed duplication of 550 $a text                                                                                                      tmee 11/01/2006
205 1.02    fixed namespace references between mads and mods                                                                        ntra 10/06/2006
206 1.01    revised                                                                                                                                                         rgue/jrad 11/29/05
207 1.00    adapted from MARC21Slim2MODS3.xsl                                                                                                       ntra 07/06/05
208 -->
209
210         <!-- authority attribute defaults to 'naf' if not set using this authority parameter, for <authority> descriptors: name, titleInfo, geographic -->
211         <xsl:param name="authority"/>
212         <xsl:variable name="auth">
213                 <xsl:choose>
214                         <xsl:when test="$authority">
215                                 <xsl:value-of select="$authority"/>
216                         </xsl:when>
217                         <xsl:otherwise>naf</xsl:otherwise>
218                 </xsl:choose>
219         </xsl:variable>
220         <xsl:variable name="controlField008" select="marc:controlfield[@tag='008']"/>
221         <xsl:variable name="controlField008-06"
222                 select="substring(descendant-or-self::marc:controlfield[@tag=008],7,1)"/>
223         <xsl:variable name="controlField008-11"
224                 select="substring(descendant-or-self::marc:controlfield[@tag=008],12,1)"/>
225         <xsl:variable name="controlField008-14"
226                 select="substring(descendant-or-self::marc:controlfield[@tag=008],15,1)"/>
227         <xsl:template match="/">
228                 <xsl:choose>
229                         <xsl:when test="descendant-or-self::marc:collection">
230                                 <mads:madsCollection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
231                                         xsi:schemaLocation="http://www.loc.gov/mads/v2 http://www.loc.gov/standards/mads/v2/mads-2-0.xsd">
232                                         <xsl:for-each select="descendant-or-self::marc:collection/marc:record">
233                                                 <mads:mads version="2.0">
234                                                         <xsl:call-template name="marcRecord"/>
235                                                 </mads:mads>
236                                         </xsl:for-each>
237                                 </mads:madsCollection>
238                         </xsl:when>
239                         <xsl:otherwise>
240                                 <mads:mads version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
241                                         xsi:schemaLocation="http://www.loc.gov/mads/v2 http://www.loc.gov/standards/mads/mads-2-0.xsd">
242                                         <xsl:for-each select="descendant-or-self::marc:record">
243                                                 <xsl:call-template name="marcRecord"/>
244                                         </xsl:for-each>
245                                 </mads:mads>
246                         </xsl:otherwise>
247                 </xsl:choose>
248         </xsl:template>
249
250         <xsl:template name="marcRecord">
251                 <mads:authority>
252                         <!-- 2.04 -->
253                         <xsl:choose>
254                                 <xsl:when test="$controlField008-06='d'">
255                                         <xsl:attribute name="geographicSubdivision">
256                                                 <xsl:text>direct</xsl:text>
257                                         </xsl:attribute>
258                                 </xsl:when>
259                                 <xsl:when test="$controlField008-06='i'">
260                                         <xsl:attribute name="geographicSubdivision">
261                                                 <xsl:text>indirect</xsl:text>
262                                         </xsl:attribute>
263                                 </xsl:when>
264                                 <xsl:when test="$controlField008-06='n'">
265                                         <xsl:attribute name="geographicSubdivision">
266                                                 <xsl:text>not applicable</xsl:text>
267                                         </xsl:attribute>
268                                 </xsl:when>
269                         </xsl:choose>
270                         
271                         <xsl:apply-templates select="marc:datafield[100 &lt;= @tag  and @tag &lt; 200]"/>               
272                 </mads:authority>
273
274                 <!-- related -->
275                 <xsl:apply-templates
276                         select="marc:datafield[500 &lt;= @tag and @tag &lt;= 585]|marc:datafield[700 &lt;= @tag and @tag &lt;= 785]"/>
277
278                 <!-- variant -->
279                 <xsl:apply-templates select="marc:datafield[400 &lt;= @tag and @tag &lt;= 485]"/>
280
281                 <!-- notes -->
282                 <xsl:apply-templates select="marc:datafield[667 &lt;= @tag and @tag &lt;= 688]"/>
283
284                 <!-- url -->
285                 <xsl:apply-templates select="marc:datafield[@tag=856]"/>
286                 <xsl:apply-templates select="marc:datafield[@tag=010]"/>
287                 <xsl:apply-templates select="marc:datafield[@tag=024]"/>
288                 <xsl:apply-templates select="marc:datafield[@tag=372]"/>
289                 
290                 <!-- classification -->
291                 <xsl:apply-templates select="marc:datafield[@tag=053]"/>
292                 <xsl:apply-templates select="marc:datafield[@tag=055]"/>
293                 <xsl:apply-templates select="marc:datafield[@tag=060]"/>
294                 <xsl:apply-templates select="marc:datafield[@tag=065]"/>
295                 <xsl:apply-templates select="marc:datafield[@tag=070]"/>
296                 <xsl:apply-templates select="marc:datafield[@tag=080]"/>
297                 <xsl:apply-templates select="marc:datafield[@tag=082]"/>
298                 <xsl:apply-templates select="marc:datafield[@tag=083]"/>
299                 <xsl:apply-templates select="marc:datafield[@tag=086]"/>
300                 <xsl:apply-templates select="marc:datafield[@tag=087]"/>
301
302                 <!-- affiliation-->
303                 <xsl:for-each select="marc:datafield[@tag=373]">
304                         <mads:affiliation>
305                                 <mads:position>
306                                         <xsl:value-of select="marc:subfield[@code='a']"/>
307                                 </mads:position>
308                                 <mads:dateValid point="start">
309                                         <xsl:value-of select="marc:subfield[@code='s']"/>
310                                 </mads:dateValid>
311                                 <mads:dateValid point="end">
312                                         <xsl:value-of select="marc:subfield[@code='t']"/>
313                                 </mads:dateValid>
314                         </mads:affiliation>
315                 </xsl:for-each>
316                 <xsl:for-each select="marc:datafield[@tag=371]">
317                         <mads:affiliation>
318                                 <mads:address>
319                                         <mads:street>
320                                                 <xsl:value-of select="marc:subfield[@code='a']"/>
321                                         </mads:street>
322                                         <mads:city>
323                                                 <xsl:value-of select="marc:subfield[@code='b']"/>
324                                         </mads:city>
325                                         <mads:state>
326                                                 <xsl:value-of select="marc:subfield[@code='c']"/>
327                                         </mads:state>
328                                         <mads:country>
329                                                 <xsl:value-of select="marc:subfield[@code='d']"/>
330                                         </mads:country>
331                                         <mads:postcode>
332                                                 <xsl:value-of select="marc:subfield[@code='e']"/>
333                                         </mads:postcode>
334                                 </mads:address>
335                                 <mads:email>
336                                         <xsl:value-of select="marc:subfield[@code='m']"/>
337                                 </mads:email>
338                         </mads:affiliation>
339                 </xsl:for-each>
340
341                 <!-- extension-->
342                 <xsl:for-each select="marc:datafield[@tag=336]">
343                         <mads:extension>
344                                 <mads:contentType>
345                                         <mads:contentType type="text">
346                                                 <xsl:value-of select="marc:subfield[@code='a']"/>
347                                         </mads:contentType>
348                                         <mads:contentType type="code">
349                                                 <xsl:value-of select="marc:subfield[@code='b']"/>
350                                         </mads:contentType>
351                                 </mads:contentType>
352                         </mads:extension>
353                 </xsl:for-each>
354
355                 <xsl:for-each select="marc:datafield[@tag=374]">
356                         <mads:extension>
357                                 <mads:profession>
358                                         <xsl:choose>
359                                                 <xsl:when test="marc:subfield[@code='a']">
360                                                         <mads:professionTerm>
361                                                                 <xsl:value-of select="marc:subfield[@code='a']"/>
362                                                         </mads:professionTerm>
363                                                 </xsl:when>
364                                                 <xsl:when test="marc:subfield[@code='s']">
365                                                         <mads:dateValid point="start">
366                                                                 <xsl:value-of select="marc:subfield[@code='s']"/>
367                                                         </mads:dateValid>
368                                                 </xsl:when>
369                                                 <xsl:when test="marc:subfield[@code='t']">
370                                                         <mads:dateValid point="end">
371                                                                 <xsl:value-of select="marc:subfield[@code='t']"/>
372                                                         </mads:dateValid>
373                                                 </xsl:when>
374                                         </xsl:choose>
375                                 </mads:profession>
376                         </mads:extension>
377                 </xsl:for-each>
378                 
379                 <xsl:for-each select="marc:datafield[@tag=375]">
380                         <mads:extension>
381                                 <mads:gender>
382                                         <xsl:choose>
383                                                 <xsl:when test="marc:subfield[@code='a']">
384                                                         <mads:genderTerm>
385                                                                 <xsl:value-of select="marc:subfield[@code='a']"/>
386                                                         </mads:genderTerm>
387                                                 </xsl:when>
388                                                 <xsl:when test="marc:subfield[@code='s']">
389                                                         <mads:dateValid point="start">
390                                                                 <xsl:value-of select="marc:subfield[@code='s']"/>
391                                                         </mads:dateValid>
392                                                 </xsl:when>
393                                                 <xsl:when test="marc:subfield[@code='t']">
394                                                         <mads:dateValid point="end">
395                                                                 <xsl:value-of select="marc:subfield[@code='t']"/>
396                                                         </mads:dateValid>
397                                                 </xsl:when>
398                                         </xsl:choose>
399                                 </mads:gender>
400                         </mads:extension>
401                 </xsl:for-each>
402
403                 <xsl:for-each select="marc:datafield[@tag=376]">
404                         <mads:extension>
405                                 <mads:familyInformation>
406                                         <mads:typeOfFamily>
407                                                 <xsl:value-of select="marc:subfield[@code='a']"/>
408                                         </mads:typeOfFamily>
409                                         <mads:nameOfProminentMember>
410                                                 <xsl:value-of select="marc:subfield[@code='b']"/>
411                                         </mads:nameOfProminentMember>
412                                         <mads:hereditaryTitle>
413                                                 <xsl:value-of select="marc:subfield[@code='c']"/>
414                                         </mads:hereditaryTitle>
415                                         <mads:dateValid point="start">
416                                                 <xsl:value-of select="marc:subfield[@code='s']"/>
417                                         </mads:dateValid>
418                                         <mads:dateValid point="end">
419                                                 <xsl:value-of select="marc:subfield[@code='t']"/>
420                                         </mads:dateValid>
421                                 </mads:familyInformation>
422                         </mads:extension>
423                 </xsl:for-each>
424
425                 <mads:recordInfo>
426                         <mads:recordOrigin>Converted from MARCXML to MADS version 2.0 (Revision 2.13)</mads:recordOrigin>
427                         <!-- <xsl:apply-templates select="marc:datafield[@tag=024]"/> -->
428
429                         <xsl:apply-templates select="marc:datafield[@tag=040]/marc:subfield[@code='a']"/>
430                         <xsl:apply-templates select="marc:controlfield[@tag=005]"/>
431                         <xsl:apply-templates select="marc:controlfield[@tag=001]"/>
432                         <xsl:apply-templates select="marc:datafield[@tag=040]/marc:subfield[@code='b']"/>
433                         <xsl:apply-templates select="marc:datafield[@tag=040]/marc:subfield[@code='e']"/>
434                         <xsl:for-each select="marc:controlfield[@tag=008]">
435                                 <xsl:if test="substring(.,11,1)='a'">
436                                         <mads:descriptionStandard>
437                                                 <xsl:text>earlier rules</xsl:text>
438                                         </mads:descriptionStandard>
439                                 </xsl:if>
440                                 <xsl:if test="substring(.,11,1)='b'">
441                                         <mads:descriptionStandard>
442                                                 <xsl:text>aacr1</xsl:text>
443                                         </mads:descriptionStandard>
444                                 </xsl:if>
445                                 <xsl:if test="substring(.,11,1)='c'">
446                                         <mads:descriptionStandard>
447                                                 <xsl:text>aacr2</xsl:text>
448                                         </mads:descriptionStandard>
449                                 </xsl:if>
450                                 <xsl:if test="substring(.,11,1)='d'">
451                                         <mads:descriptionStandard>
452                                                 <xsl:text>aacr2 compatible</xsl:text>
453                                         </mads:descriptionStandard>
454                                 </xsl:if>
455                                 <xsl:if test="substring(.,11,1)='z'">
456                                         <mads:descriptionStandard>
457                                                 <xsl:text>other rules</xsl:text>
458                                         </mads:descriptionStandard>
459                                 </xsl:if>
460                         </xsl:for-each>
461                 </mads:recordInfo>
462         </xsl:template>
463
464         <!-- start of secondary templates -->
465
466         <!-- ======== xlink ======== -->
467
468         <!-- <xsl:template name="uri"> 
469     <xsl:for-each select="marc:subfield[@code='0']">
470       <xsl:attribute name="xlink:href">
471         <xsl:value-of select="."/>
472       </xsl:attribute>
473     </xsl:for-each>
474      </xsl:template> 
475    -->
476         <xsl:template match="marc:subfield[@code='i']">
477                 <xsl:attribute name="otherType">
478                         <xsl:value-of select="."/>
479                 </xsl:attribute>
480         </xsl:template>
481
482         <!-- No role/roleTerm mapped in MADS 06/24/2010
483         <xsl:template name="role">
484                 <xsl:for-each select="marc:subfield[@code='e']">
485                         <mads:role>
486                                 <mads:roleTerm type="text">
487                                         <xsl:value-of select="."/>
488                                 </mads:roleTerm>
489                         </mads:role>
490                 </xsl:for-each>
491         </xsl:template>
492 -->
493
494         <xsl:template name="part">
495                 <xsl:variable name="partNumber">
496                         <xsl:call-template name="specialSubfieldSelect">
497                                 <xsl:with-param name="axis">n</xsl:with-param>
498                                 <xsl:with-param name="anyCodes">n</xsl:with-param>
499                                 <xsl:with-param name="afterCodes">fghkdlmor</xsl:with-param>
500                         </xsl:call-template>
501                 </xsl:variable>
502                 <xsl:variable name="partName">
503                         <xsl:call-template name="specialSubfieldSelect">
504                                 <xsl:with-param name="axis">p</xsl:with-param>
505                                 <xsl:with-param name="anyCodes">p</xsl:with-param>
506                                 <xsl:with-param name="afterCodes">fghkdlmor</xsl:with-param>
507                         </xsl:call-template>
508                 </xsl:variable>
509                 <xsl:if test="string-length(normalize-space($partNumber))">
510                         <mads:partNumber>
511                                 <xsl:call-template name="chopPunctuation">
512                                         <xsl:with-param name="chopString" select="$partNumber"/>
513                                 </xsl:call-template>
514                         </mads:partNumber>
515                 </xsl:if>
516                 <xsl:if test="string-length(normalize-space($partName))">
517                         <mads:partName>
518                                 <xsl:call-template name="chopPunctuation">
519                                         <xsl:with-param name="chopString" select="$partName"/>
520                                 </xsl:call-template>
521                         </mads:partName>
522                 </xsl:if>
523         </xsl:template>
524
525         <xsl:template name="nameABCDN">
526                 <xsl:for-each select="marc:subfield[@code='a']">
527                         <mads:namePart>
528                                 <xsl:call-template name="chopPunctuation">
529                                         <xsl:with-param name="chopString" select="."/>
530                                 </xsl:call-template>
531                         </mads:namePart>
532                 </xsl:for-each>
533                 <xsl:for-each select="marc:subfield[@code='b']">
534                         <mads:namePart>
535                                 <xsl:value-of select="."/>
536                         </mads:namePart>
537                 </xsl:for-each>
538                 <xsl:if
539                         test="marc:subfield[@code='c'] or marc:subfield[@code='d'] or marc:subfield[@code='n']">
540                         <mads:namePart>
541                                 <xsl:call-template name="subfieldSelect">
542                                         <xsl:with-param name="codes">cdn</xsl:with-param>
543                                 </xsl:call-template>
544                         </mads:namePart>
545                 </xsl:if>
546         </xsl:template>
547
548         <xsl:template name="nameABCDQ">
549                 <mads:namePart>
550                         <xsl:call-template name="chopPunctuation">
551                                 <xsl:with-param name="chopString">
552                                         <xsl:call-template name="subfieldSelect">
553                                                 <xsl:with-param name="codes">aq</xsl:with-param>
554                                         </xsl:call-template>
555                                 </xsl:with-param>
556                         </xsl:call-template>
557                 </mads:namePart>
558                 <xsl:call-template name="termsOfAddress"/>
559                 <xsl:call-template name="nameDate"/>
560         </xsl:template>
561
562         <xsl:template name="nameACDENQ">
563                 <mads:namePart>
564                         <xsl:call-template name="subfieldSelect">
565                                 <xsl:with-param name="codes">acdenq</xsl:with-param>
566                         </xsl:call-template>
567                 </mads:namePart>
568         </xsl:template>
569
570         <xsl:template name="nameDate">
571                 <xsl:for-each select="marc:subfield[@code='d']">
572                         <mads:namePart type="date">
573                                 <xsl:call-template name="chopPunctuation">
574                                         <xsl:with-param name="chopString" select="."/>
575                                 </xsl:call-template>
576                         </mads:namePart>
577                 </xsl:for-each>
578         </xsl:template>
579
580         <xsl:template name="specialSubfieldSelect">
581                 <xsl:param name="anyCodes"/>
582                 <xsl:param name="axis"/>
583                 <xsl:param name="beforeCodes"/>
584                 <xsl:param name="afterCodes"/>
585                 <xsl:variable name="str">
586                         <xsl:for-each select="marc:subfield">
587                                 <xsl:if
588                                         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])">
589                                         <xsl:value-of select="text()"/>
590                                         <xsl:text> </xsl:text>
591                                 </xsl:if>
592                         </xsl:for-each>
593                 </xsl:variable>
594                 <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
595         </xsl:template>
596
597         <xsl:template name="termsOfAddress">
598                 <xsl:if test="marc:subfield[@code='b' or @code='c']">
599                         <mads:namePart type="termsOfAddress">
600                                 <xsl:call-template name="chopPunctuation">
601                                         <xsl:with-param name="chopString">
602                                                 <xsl:call-template name="subfieldSelect">
603                                                         <xsl:with-param name="codes">bc</xsl:with-param>
604                                                 </xsl:call-template>
605                                         </xsl:with-param>
606                                 </xsl:call-template>
607                         </mads:namePart>
608                 </xsl:if>
609         </xsl:template>
610
611         <xsl:template name="displayLabel">
612                 <xsl:if test="marc:subfield[@code='z']">
613                         <xsl:attribute name="displayLabel">
614                                 <xsl:value-of select="marc:subfield[@code='z']"/>
615                         </xsl:attribute>
616                 </xsl:if>
617                 <xsl:if test="marc:subfield[@code='3']">
618                         <xsl:attribute name="displayLabel">
619                                 <xsl:value-of select="marc:subfield[@code='3']"/>
620                         </xsl:attribute>
621                 </xsl:if>
622         </xsl:template>
623
624         <xsl:template name="isInvalid">
625                 <xsl:if test="@code='z'">
626                         <xsl:attribute name="invalid">yes</xsl:attribute>
627                 </xsl:if>
628         </xsl:template>
629
630         <xsl:template name="sub2Attribute">
631                 <!-- 024 -->
632                 <xsl:if test="../marc:subfield[@code='2']">
633                         <xsl:attribute name="type">
634                                 <xsl:value-of select="../marc:subfield[@code='2']"/>
635                         </xsl:attribute>
636                 </xsl:if>
637         </xsl:template>
638
639         <xsl:template match="marc:controlfield[@tag=001]">
640                 <mads:recordIdentifier>
641                         <xsl:if test="../marc:controlfield[@tag=003]">
642                                 <xsl:attribute name="source">
643                                         <xsl:value-of select="../marc:controlfield[@tag=003]"/>
644                                 </xsl:attribute>
645                         </xsl:if>
646                         <xsl:value-of select="."/>
647                 </mads:recordIdentifier>
648         </xsl:template>
649
650         <xsl:template match="marc:controlfield[@tag=005]">
651                 <mads:recordChangeDate encoding="iso8601">
652                         <xsl:value-of select="."/>
653                 </mads:recordChangeDate>
654         </xsl:template>
655
656         <xsl:template match="marc:controlfield[@tag=008]">
657                 <mads:recordCreationDate encoding="marc">
658                         <xsl:value-of select="substring(.,1,6)"/>
659                 </mads:recordCreationDate>
660         </xsl:template>
661
662         <xsl:template match="marc:datafield[@tag=010]">
663                 <xsl:for-each select="marc:subfield">
664                         <mads:identifier type="lccn">
665                                 <xsl:call-template name="isInvalid"/>
666                                 <xsl:value-of select="."/>
667                         </mads:identifier>
668                 </xsl:for-each>
669         </xsl:template>
670
671         <xsl:template match="marc:datafield[@tag=024]">
672                 <xsl:for-each select="marc:subfield[not(@code=2)]">
673                         <mads:identifier>
674                                 <xsl:call-template name="isInvalid"/>
675                                 <xsl:call-template name="sub2Attribute"/>
676                                 <xsl:value-of select="."/>
677                         </mads:identifier>
678                 </xsl:for-each>
679         </xsl:template>
680
681         <!-- ========== 372 ========== -->
682         <xsl:template match="marc:datafield[@tag=372]">
683                 <mads:fieldOfActivity>
684                         <xsl:call-template name="subfieldSelect">
685                                 <xsl:with-param name="codes">a</xsl:with-param>
686                         </xsl:call-template>
687                         <xsl:text>-</xsl:text>
688                         <xsl:call-template name="subfieldSelect">
689                                 <xsl:with-param name="codes">st</xsl:with-param>
690                         </xsl:call-template>
691                 </mads:fieldOfActivity>
692         </xsl:template>
693
694
695         <!-- ========== 040 ========== -->
696         <xsl:template match="marc:datafield[@tag=040]/marc:subfield[@code='a']">
697                 <mads:recordContentSource authority="marcorg">
698                         <xsl:value-of select="."/>
699                 </mads:recordContentSource>
700         </xsl:template>
701
702         <xsl:template match="marc:datafield[@tag=040]/marc:subfield[@code='b']">
703                 <mads:languageOfCataloging>
704                         <mads:languageTerm authority="iso639-2b" type="code">
705                                 <xsl:value-of select="."/>
706                         </mads:languageTerm>
707                 </mads:languageOfCataloging>
708         </xsl:template>
709
710         <xsl:template match="marc:datafield[@tag=040]/marc:subfield[@code='e']">
711                 <mads:descriptionStandard>
712                         <xsl:value-of select="."/>
713                 </mads:descriptionStandard>
714         </xsl:template>
715         
716         <!-- ========== classification 2.03 ========== -->
717         
718         <xsl:template match="marc:datafield[@tag=053]">
719                 <mads:classification>
720                         <xsl:call-template name="subfieldSelect">
721                                 <xsl:with-param name="codes">abcdxyz</xsl:with-param>
722                                 <xsl:with-param name="delimeter">-</xsl:with-param>
723                         </xsl:call-template>
724                 </mads:classification>
725         </xsl:template>
726         
727         <xsl:template match="marc:datafield[@tag=055]">
728                 <mads:classification>
729                         <xsl:call-template name="subfieldSelect">
730                                 <xsl:with-param name="codes">abcdxyz</xsl:with-param>
731                                 <xsl:with-param name="delimeter">-</xsl:with-param>
732                         </xsl:call-template>
733                 </mads:classification>
734         </xsl:template>
735         
736         <xsl:template match="marc:datafield[@tag=060]">
737                 <mads:classification>
738                         <xsl:call-template name="subfieldSelect">
739                                 <xsl:with-param name="codes">abcdxyz</xsl:with-param>
740                                 <xsl:with-param name="delimeter">-</xsl:with-param>
741                         </xsl:call-template>
742                 </mads:classification>
743         </xsl:template>
744         <xsl:template match="marc:datafield[@tag=065]">
745                 <mads:classification>
746                         <xsl:attribute name="authority">
747                                 <xsl:value-of select="marc:subfield[@code='2']"/>
748                         </xsl:attribute>
749                         <xsl:call-template name="subfieldSelect">
750                                 <xsl:with-param name="codes">abcdxyz</xsl:with-param>
751                                 <xsl:with-param name="delimeter">-</xsl:with-param>
752                         </xsl:call-template>
753                 </mads:classification>
754         </xsl:template>
755         <xsl:template match="marc:datafield[@tag=070]">
756                 <mads:classification>
757                         <xsl:call-template name="subfieldSelect">
758                                 <xsl:with-param name="codes">abcdxyz5</xsl:with-param>
759                                 <xsl:with-param name="delimeter">-</xsl:with-param>
760                         </xsl:call-template>
761                 </mads:classification>
762         </xsl:template>
763         <xsl:template match="marc:datafield[@tag=080]">
764                 <mads:classification>
765                         <xsl:attribute name="authority">
766                                 <xsl:value-of select="marc:subfield[@code='2']"/>
767                         </xsl:attribute>
768                         <xsl:call-template name="subfieldSelect">
769                                 <xsl:with-param name="codes">abcdxyz5</xsl:with-param>
770                                 <xsl:with-param name="delimeter">-</xsl:with-param>
771                         </xsl:call-template>
772                 </mads:classification>
773         </xsl:template>
774         <xsl:template match="marc:datafield[@tag=082]">
775                 <mads:classification>
776                         <xsl:attribute name="authority">
777                                 <xsl:value-of select="marc:subfield[@code='2']"/>
778                         </xsl:attribute>
779                         <xsl:call-template name="subfieldSelect">
780                                 <xsl:with-param name="codes">abcdxyz5</xsl:with-param>
781                                 <xsl:with-param name="delimeter">-</xsl:with-param>
782                         </xsl:call-template>
783                 </mads:classification>
784         </xsl:template>
785         <xsl:template match="marc:datafield[@tag=083]">
786                 <mads:classification>
787                         <xsl:attribute name="authority">
788                                 <xsl:value-of select="marc:subfield[@code='2']"/>
789                         </xsl:attribute>
790                         <xsl:call-template name="subfieldSelect">
791                                 <xsl:with-param name="codes">abcdxyz5</xsl:with-param>
792                                 <xsl:with-param name="delimeter">-</xsl:with-param>
793                         </xsl:call-template>
794                 </mads:classification>
795         </xsl:template>
796         <xsl:template match="marc:datafield[@tag=086]">
797                 <mads:classification>
798                         <xsl:attribute name="authority">
799                                 <xsl:value-of select="marc:subfield[@code='2']"/>
800                         </xsl:attribute>
801                         <xsl:call-template name="subfieldSelect">
802                                 <xsl:with-param name="codes">abcdxyz5</xsl:with-param>
803                                 <xsl:with-param name="delimeter">-</xsl:with-param>
804                         </xsl:call-template>
805                 </mads:classification>
806         </xsl:template>
807         <xsl:template match="marc:datafield[@tag=087]">
808                 <mads:classification>
809                         <xsl:attribute name="authority">
810                                 <xsl:value-of select="marc:subfield[@code='2']"/>
811                         </xsl:attribute>
812                         <xsl:call-template name="subfieldSelect">
813                                 <xsl:with-param name="codes">abcdxyz5</xsl:with-param>
814                                 <xsl:with-param name="delimeter">-</xsl:with-param>
815                         </xsl:call-template>
816                 </mads:classification>
817         </xsl:template>
818         
819
820         <!-- ========== names  ========== -->
821         <xsl:template match="marc:datafield[@tag=100]">
822                 <mads:name type="personal">
823                         <xsl:call-template name="setAuthority"/>
824                         <xsl:call-template name="nameABCDQ"/>
825                 </mads:name>
826                 <xsl:apply-templates select="*[marc:subfield[not(contains('abcdeq',@code))]]"/>
827                 <xsl:call-template name="title"/>
828                 <xsl:apply-templates select="marc:subfield[@code!='i']"/>
829         </xsl:template>
830
831         <xsl:template match="marc:datafield[@tag=110]">
832                 <mads:name type="corporate">
833                         <xsl:call-template name="setAuthority"/>
834                         <xsl:call-template name="nameABCDN"/>
835                 </mads:name>
836                 <xsl:apply-templates select="marc:subfield[@code!='i']"/>
837         </xsl:template>
838
839         <xsl:template match="marc:datafield[@tag=111]">
840                 <mads:name type="conference">
841                         <xsl:call-template name="setAuthority"/>
842                         <xsl:call-template name="nameACDENQ"/>
843                 </mads:name>
844                 <xsl:apply-templates select="marc:subfield[@code!='i']"/>
845         </xsl:template>
846
847         <xsl:template match="marc:datafield[@tag=400]">
848                 <mads:variant>
849                         <xsl:call-template name="variantTypeAttribute"/>
850                         <mads:name type="personal">
851                                 <xsl:call-template name="nameABCDQ"/>
852                         </mads:name>
853                         <xsl:apply-templates select="marc:subfield[@code!='i']"/>
854                         <xsl:call-template name="title"/>
855                 </mads:variant>
856         </xsl:template>
857
858         <xsl:template match="marc:datafield[@tag=410]">
859                 <mads:variant>
860                         <xsl:call-template name="variantTypeAttribute"/>
861                         <mads:name type="corporate">
862                                 <xsl:call-template name="nameABCDN"/>
863                         </mads:name>
864                         <xsl:apply-templates select="marc:subfield[@code!='i']"/>
865                 </mads:variant>
866         </xsl:template>
867
868         <xsl:template match="marc:datafield[@tag=411]">
869                 <mads:variant>
870                         <xsl:call-template name="variantTypeAttribute"/>
871                         <mads:name type="conference">
872                                 <xsl:call-template name="nameACDENQ"/>
873                         </mads:name>
874                         <xsl:apply-templates select="marc:subfield[@code!='i']"/>
875                 </mads:variant>
876         </xsl:template>
877
878         <xsl:template match="marc:datafield[@tag=500]|marc:datafield[@tag=700]">
879                 <mads:related>
880                         <xsl:call-template name="relatedTypeAttribute"/>
881                         <!-- <xsl:call-template name="uri"/> -->
882                         <mads:name type="personal">
883                                 <xsl:call-template name="setAuthority"/>
884                                 <xsl:call-template name="nameABCDQ"/>
885                         </mads:name>
886                         <xsl:call-template name="title"/>
887                         <xsl:apply-templates select="marc:subfield[@code!='i']"/>
888                 </mads:related>
889         </xsl:template>
890
891         <xsl:template match="marc:datafield[@tag=510]|marc:datafield[@tag=710]">
892                 <mads:related>
893                         <xsl:call-template name="relatedTypeAttribute"/>
894                         <!-- <xsl:call-template name="uri"/> -->
895                         <mads:name type="corporate">
896                                 <xsl:call-template name="setAuthority"/>
897                                 <xsl:call-template name="nameABCDN"/>
898                         </mads:name>
899                         <xsl:apply-templates select="marc:subfield[@code!='i']"/>
900                 </mads:related>
901         </xsl:template>
902
903         <xsl:template match="marc:datafield[@tag=511]|marc:datafield[@tag=711]">
904                 <mads:related>
905                         <xsl:call-template name="relatedTypeAttribute"/>
906                         <!-- <xsl:call-template name="uri"/> -->
907                         <mads:name type="conference">
908                                 <xsl:call-template name="setAuthority"/>
909                                 <xsl:call-template name="nameACDENQ"/>
910                         </mads:name>
911                         <xsl:apply-templates select="marc:subfield[@code!='i']"/>
912                 </mads:related>
913         </xsl:template>
914
915         <!-- ========== titles  ========== -->
916         <xsl:template match="marc:datafield[@tag=130]">
917                 <xsl:call-template name="uniform-title"/>
918                 <xsl:apply-templates select="marc:subfield[@code!='i']"/>
919         </xsl:template>
920
921         <xsl:template match="marc:datafield[@tag=430]">
922                 <mads:variant>
923                         <xsl:call-template name="variantTypeAttribute"/>
924                         <xsl:call-template name="uniform-title"/>
925                         <xsl:apply-templates select="marc:subfield[@code!='i']"/>
926                 </mads:variant>
927         </xsl:template>
928
929         <xsl:template match="marc:datafield[@tag=530]|marc:datafield[@tag=730]">
930                 <mads:related>
931                         <xsl:call-template name="relatedTypeAttribute"/>
932                         <xsl:call-template name="uniform-title"/>
933                         <xsl:apply-templates select="marc:subfield[@code!='i']"/>
934                 </mads:related>
935         </xsl:template>
936
937         <xsl:template name="title">
938                 <xsl:variable name="hasTitle">
939                         <xsl:for-each select="marc:subfield">
940                                 <xsl:if test="(contains('tfghklmors',@code) )">
941                                         <xsl:value-of select="@code"/>
942                                 </xsl:if>
943                         </xsl:for-each>
944                 </xsl:variable>
945                 <xsl:if test="string-length($hasTitle) &gt; 0 ">
946                         <mads:titleInfo>
947                                 <xsl:call-template name="setAuthority"/>
948                                 <mads:title>
949                                         <xsl:variable name="str">
950                                                 <xsl:for-each select="marc:subfield">
951                                                         <xsl:if test="(contains('atfghklmors',@code) )">
952                                                                 <xsl:value-of select="text()"/>
953                                                                 <xsl:text> </xsl:text>
954                                                         </xsl:if>
955                                                 </xsl:for-each>
956                                         </xsl:variable>
957                                         <xsl:call-template name="chopPunctuation">
958                                                 <xsl:with-param name="chopString">
959                                                         <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
960                                                 </xsl:with-param>
961                                         </xsl:call-template>
962                                 </mads:title>
963                                 <xsl:call-template name="part"/>
964                                 <!-- <xsl:call-template name="uri"/> -->
965                         </mads:titleInfo>
966                 </xsl:if>
967         </xsl:template>
968
969         <xsl:template name="uniform-title">
970                 <xsl:variable name="hasTitle">
971                         <xsl:for-each select="marc:subfield">
972                                 <xsl:if test="(contains('atfghklmors',@code) )">
973                                         <xsl:value-of select="@code"/>
974                                 </xsl:if>
975                         </xsl:for-each>
976                 </xsl:variable>
977                 <xsl:if test="string-length($hasTitle) &gt; 0 ">
978                         <mads:titleInfo>
979                                 <xsl:call-template name="setAuthority"/>
980                                 <mads:title>
981                                         <xsl:variable name="str">
982                                                 <xsl:for-each select="marc:subfield">
983                                                         <xsl:if test="(contains('adfghklmors',@code) )">
984                                                                 <xsl:value-of select="text()"/>
985                                                                 <xsl:text> </xsl:text>
986                                                         </xsl:if>
987                                                 </xsl:for-each>
988                                         </xsl:variable>
989                                         <xsl:call-template name="chopPunctuation">
990                                                 <xsl:with-param name="chopString">
991                                                         <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
992                                                 </xsl:with-param>
993                                         </xsl:call-template>
994                                 </mads:title>
995                                 <xsl:call-template name="part"/>
996                                 <!-- <xsl:call-template name="uri"/> -->
997                         </mads:titleInfo>
998                 </xsl:if>
999         </xsl:template>
1000
1001
1002         <!-- ========== topics  ========== -->
1003         <xsl:template match="marc:subfield[@code='x']">
1004                 <mads:topic>
1005                         <xsl:call-template name="chopPunctuation">
1006                                 <xsl:with-param name="chopString">
1007                                         <xsl:value-of select="."/>
1008                                 </xsl:with-param>
1009                         </xsl:call-template>
1010                 </mads:topic>
1011         </xsl:template>
1012         
1013         <!-- 2.06 fix -->
1014         <xsl:template
1015                 match="marc:datafield[@tag=150][marc:subfield[@code='a' or @code='b']]|marc:datafield[@tag=180][marc:subfield[@code='x']]">
1016                 <xsl:call-template name="topic"/>
1017                 <xsl:apply-templates select="marc:subfield[@code!='i']"/>
1018         </xsl:template>
1019         <xsl:template
1020                 match="marc:datafield[@tag=450][marc:subfield[@code='a' or @code='b']]|marc:datafield[@tag=480][marc:subfield[@code='x']]">
1021                 <mads:variant>
1022                         <xsl:call-template name="variantTypeAttribute"/>
1023                         <xsl:call-template name="topic"/>
1024                 </mads:variant>
1025         </xsl:template>
1026         <xsl:template
1027                 match="marc:datafield[@tag=550 or @tag=750][marc:subfield[@code='a' or @code='b']]">
1028                 <mads:related>
1029                         <xsl:call-template name="relatedTypeAttribute"/>
1030                         <!-- <xsl:call-template name="uri"/> -->
1031                         <xsl:call-template name="topic"/>
1032                         <xsl:apply-templates select="marc:subfield[@code='z']"/>
1033                 </mads:related>
1034         </xsl:template>
1035         <xsl:template name="topic">
1036                 <mads:topic>
1037                         <xsl:call-template name="setAuthority"/>
1038                         <!-- tmee2006 dedupe 550a
1039                         <xsl:if test="@tag=550 or @tag=750">
1040                                 <xsl:call-template name="subfieldSelect">
1041                                         <xsl:with-param name="codes">ab</xsl:with-param>
1042                                 </xsl:call-template>
1043                         </xsl:if>       
1044                         -->
1045                         <xsl:choose>
1046                                 <xsl:when test="@tag=180 or @tag=480 or @tag=580 or @tag=780">
1047                                         <xsl:call-template name="chopPunctuation">
1048                                                 <xsl:with-param name="chopString">
1049                                                         <xsl:apply-templates select="marc:subfield[@code='x']"/>
1050                                                 </xsl:with-param>
1051                                         </xsl:call-template>
1052                                 </xsl:when>
1053                         </xsl:choose>
1054                         <xsl:call-template name="chopPunctuation">
1055                                 <xsl:with-param name="chopString">
1056                                         <xsl:choose>
1057                                                 <xsl:when test="@tag=180 or @tag=480 or @tag=580 or @tag=780">
1058                                                         <xsl:apply-templates select="marc:subfield[@code='x']"/>
1059                                                 </xsl:when>
1060                                                 <xsl:otherwise>
1061                                                         <xsl:call-template name="subfieldSelect">
1062                                                                 <xsl:with-param name="codes">ab</xsl:with-param>
1063                                                         </xsl:call-template>
1064                                                 </xsl:otherwise>
1065                                         </xsl:choose>
1066                                 </xsl:with-param>
1067                         </xsl:call-template>
1068                 </mads:topic>
1069         </xsl:template>
1070
1071         <!-- ========= temporals  ========== -->
1072         <xsl:template match="marc:subfield[@code='y']">
1073                 <mads:temporal>
1074                         <xsl:call-template name="chopPunctuation">
1075                                 <xsl:with-param name="chopString">
1076                                         <xsl:value-of select="."/>
1077                                 </xsl:with-param>
1078                         </xsl:call-template>
1079                 </mads:temporal>
1080         </xsl:template>
1081         <xsl:template
1082                 match="marc:datafield[@tag=148][marc:subfield[@code='a']]|marc:datafield[@tag=182 ][marc:subfield[@code='y']]">
1083                 <xsl:call-template name="temporal"/>
1084         </xsl:template>
1085         <xsl:template
1086                 match="marc:datafield[@tag=448][marc:subfield[@code='a']]|marc:datafield[@tag=482][marc:subfield[@code='y']]">
1087                 <mads:variant>
1088                         <xsl:call-template name="variantTypeAttribute"/>
1089                         <xsl:call-template name="temporal"/>
1090                 </mads:variant>
1091         </xsl:template>
1092         <xsl:template
1093                 match="marc:datafield[@tag=548 or @tag=748][marc:subfield[@code='a']]|marc:datafield[@tag=582 or @tag=782][marc:subfield[@code='y']]">
1094                 <mads:related>
1095                         <xsl:call-template name="relatedTypeAttribute"/>
1096                         <!-- <xsl:call-template name="uri"/> -->
1097                         <xsl:call-template name="temporal"/>
1098                 </mads:related>
1099         </xsl:template>
1100         <xsl:template name="temporal">
1101                 <mads:temporal>
1102                         <xsl:call-template name="setAuthority"/>
1103                         <xsl:if test="@tag=548 or @tag=748">
1104                                 <xsl:value-of select="marc:subfield[@code='a']"/>
1105                         </xsl:if>
1106                         <xsl:call-template name="chopPunctuation">
1107                                 <xsl:with-param name="chopString">
1108                                         <xsl:choose>
1109                                                 <xsl:when test="@tag=182 or @tag=482 or @tag=582 or @tag=782">
1110                                                         <xsl:apply-templates select="marc:subfield[@code='y']"/>
1111                                                 </xsl:when>
1112                                                 <xsl:otherwise>
1113                                                         <xsl:value-of select="marc:subfield[@code='a']"/>
1114                                                 </xsl:otherwise>
1115                                         </xsl:choose>
1116                                 </xsl:with-param>
1117                         </xsl:call-template>
1118                 </mads:temporal>
1119                 <xsl:apply-templates select="marc:subfield[@code!='i']"/>
1120         </xsl:template>
1121
1122         <!-- ========== genre  ========== -->
1123         <xsl:template match="marc:subfield[@code='v']">
1124                 <mads:genre>
1125                         <xsl:call-template name="chopPunctuation">
1126                                 <xsl:with-param name="chopString">
1127                                         <xsl:value-of select="."/>
1128                                 </xsl:with-param>
1129                         </xsl:call-template>
1130                 </mads:genre>
1131         </xsl:template>
1132         <xsl:template
1133                 match="marc:datafield[@tag=155][marc:subfield[@code='a']]|marc:datafield[@tag=185][marc:subfield[@code='v']]">
1134                 <xsl:call-template name="genre"/>
1135         </xsl:template>
1136         <xsl:template
1137                 match="marc:datafield[@tag=455][marc:subfield[@code='a']]|marc:datafield[@tag=485 ][marc:subfield[@code='v']]">
1138                 <mads:variant>
1139                         <xsl:call-template name="variantTypeAttribute"/>
1140                         <xsl:call-template name="genre"/>
1141                 </mads:variant>
1142         </xsl:template>
1143         <!--
1144         <xsl:template match="marc:datafield[@tag=555]">
1145                 <mads:related>
1146                         <xsl:call-template name="relatedTypeAttribute"/>
1147                         <xsl:call-template name="uri"/>
1148                         <xsl:call-template name="genre"/>
1149                 </mads:related>
1150         </xsl:template>
1151         -->
1152         <xsl:template
1153                 match="marc:datafield[@tag=555 or @tag=755][marc:subfield[@code='a']]|marc:datafield[@tag=585][marc:subfield[@code='v']]">
1154                 <mads:related>
1155                         <xsl:call-template name="relatedTypeAttribute"/>
1156                         <xsl:call-template name="genre"/>
1157                 </mads:related>
1158         </xsl:template>
1159         <xsl:template name="genre">
1160                 <mads:genre>
1161                         <xsl:if test="@tag=555">
1162                                 <xsl:value-of select="marc:subfield[@code='a']"/>
1163                         </xsl:if>
1164                         <xsl:call-template name="setAuthority"/>
1165                         <xsl:call-template name="chopPunctuation">
1166                                 <xsl:with-param name="chopString">
1167                                         <xsl:choose>
1168                                                 <!-- 2.07 fix -->
1169                                                 <xsl:when test="@tag='555'"/>
1170                                                 <xsl:when test="@tag=185 or @tag=485 or @tag=585">
1171                                                         <xsl:apply-templates select="marc:subfield[@code='v']"/>
1172                                                 </xsl:when>
1173                                                 <xsl:otherwise>
1174                                                         <xsl:value-of select="marc:subfield[@code='a']"/>
1175                                                 </xsl:otherwise>
1176                                         </xsl:choose>
1177                                 </xsl:with-param>
1178                         </xsl:call-template>
1179                 </mads:genre>
1180                 <xsl:apply-templates/>
1181         </xsl:template>
1182
1183         <!-- ========= geographic  ========== -->
1184         <xsl:template match="marc:subfield[@code='z']">
1185                 <mads:geographic>
1186                         <xsl:call-template name="chopPunctuation">
1187                                 <xsl:with-param name="chopString">
1188                                         <xsl:value-of select="."/>
1189                                 </xsl:with-param>
1190                         </xsl:call-template>
1191                 </mads:geographic>
1192         </xsl:template>
1193         <xsl:template name="geographic">
1194                 <mads:geographic>
1195                         <!-- 2.14 -->
1196                         <xsl:call-template name="setAuthority"/>
1197                         <!-- 2.13 -->
1198                         <xsl:if test="@tag=151 or @tag=551">
1199                                 <xsl:value-of select="marc:subfield[@code='a']"/>
1200                         </xsl:if>
1201                         <xsl:call-template name="chopPunctuation">
1202                                 <xsl:with-param name="chopString">
1203                                                 <xsl:if test="@tag=181 or @tag=481 or @tag=581">
1204                                                                 <xsl:apply-templates select="marc:subfield[@code='z']"/>
1205                                                 </xsl:if>
1206                                                 <!-- 2.13
1207                                                         <xsl:choose>
1208                                                 <xsl:when test="@tag=181 or @tag=481 or @tag=581">
1209                                                         <xsl:apply-templates select="marc:subfield[@code='z']"/>
1210                                                 </xsl:when>
1211                                         
1212                                                 <xsl:otherwise>
1213                                                         <xsl:value-of select="marc:subfield[@code='a']"/>
1214                                                 </xsl:otherwise>
1215                                                 </xsl:choose>
1216                                                 -->
1217                                 </xsl:with-param>
1218                         </xsl:call-template>
1219                 </mads:geographic>
1220                 <xsl:apply-templates select="marc:subfield[@code!='i']"/>
1221         </xsl:template>
1222         <xsl:template
1223                 match="marc:datafield[@tag=151][marc:subfield[@code='a']]|marc:datafield[@tag=181][marc:subfield[@code='z']]">
1224                 <xsl:call-template name="geographic"/>
1225         </xsl:template>
1226         <xsl:template
1227                 match="marc:datafield[@tag=451][marc:subfield[@code='a']]|marc:datafield[@tag=481][marc:subfield[@code='z']]">
1228                 <mads:variant>
1229                         <xsl:call-template name="variantTypeAttribute"/>
1230                         <xsl:call-template name="geographic"/>
1231                 </mads:variant>
1232         </xsl:template>
1233         <xsl:template
1234                 match="marc:datafield[@tag=551]|marc:datafield[@tag=581][marc:subfield[@code='z']]">
1235                 <mads:related>
1236                         <xsl:call-template name="relatedTypeAttribute"/>
1237                         <!-- <xsl:call-template name="uri"/> -->
1238                         <xsl:call-template name="geographic"/>
1239                 </mads:related>
1240         </xsl:template>
1241         <xsl:template match="marc:datafield[@tag=580]">
1242                 <mads:related>
1243                         <xsl:call-template name="relatedTypeAttribute"/>
1244                         <xsl:apply-templates select="marc:subfield[@code!='i']"/>
1245                 </mads:related>
1246         </xsl:template>
1247         <xsl:template
1248                 match="marc:datafield[@tag=751][marc:subfield[@code='z']]|marc:datafield[@tag=781][marc:subfield[@code='z']]">
1249                 <mads:related>
1250                         <xsl:call-template name="relatedTypeAttribute"/>
1251                         <xsl:call-template name="geographic"/>
1252                 </mads:related>
1253         </xsl:template>
1254         <xsl:template match="marc:datafield[@tag=755]">
1255                 <mads:related>
1256                         <xsl:call-template name="relatedTypeAttribute"/>
1257                         <xsl:call-template name="genre"/>
1258                         <xsl:call-template name="setAuthority"/>
1259                         <xsl:apply-templates select="marc:subfield[@code!='i']"/>
1260                 </mads:related>
1261         </xsl:template>
1262         <xsl:template match="marc:datafield[@tag=780]">
1263                 <mads:related>
1264                         <xsl:call-template name="relatedTypeAttribute"/>
1265                         <xsl:apply-templates select="marc:subfield[@code!='i']"/>
1266                 </mads:related>
1267         </xsl:template>
1268         <xsl:template match="marc:datafield[@tag=785]">
1269                 <mads:related>
1270                         <xsl:call-template name="relatedTypeAttribute"/>
1271                         <xsl:apply-templates select="marc:subfield[@code!='i']"/>
1272                 </mads:related>
1273         </xsl:template>
1274
1275         <!-- ========== notes  ========== -->
1276         <xsl:template match="marc:datafield[667 &lt;= @tag and @tag &lt;= 688]">
1277                 <mads:note>
1278                         <xsl:choose>
1279                                 <xsl:when test="@tag=667">
1280                                         <xsl:attribute name="type">nonpublic</xsl:attribute>
1281                                 </xsl:when>
1282                                 <xsl:when test="@tag=670">
1283                                         <xsl:attribute name="type">source</xsl:attribute>
1284                                 </xsl:when>
1285                                 <xsl:when test="@tag=675">
1286                                         <xsl:attribute name="type">notFound</xsl:attribute>
1287                                 </xsl:when>
1288                                 <xsl:when test="@tag=678">
1289                                         <xsl:attribute name="type">history</xsl:attribute>
1290                                 </xsl:when>
1291                                 <xsl:when test="@tag=681">
1292                                         <xsl:attribute name="type">subject example</xsl:attribute>
1293                                 </xsl:when>
1294                                 <xsl:when test="@tag=682">
1295                                         <xsl:attribute name="type">deleted heading information</xsl:attribute>
1296                                 </xsl:when>
1297                                 <xsl:when test="@tag=688">
1298                                         <xsl:attribute name="type">application history</xsl:attribute>
1299                                 </xsl:when>
1300                         </xsl:choose>
1301                         <xsl:call-template name="chopPunctuation">
1302                                 <xsl:with-param name="chopString">
1303                                         <xsl:choose>
1304                                                 <xsl:when test="@tag=667 or @tag=675">
1305                                                         <xsl:value-of select="marc:subfield[@code='a']"/>
1306                                                 </xsl:when>
1307                                                 <xsl:when test="@tag=670 or @tag=678">
1308                                                         <xsl:call-template name="subfieldSelect">
1309                                                                 <xsl:with-param name="codes">ab</xsl:with-param>
1310                                                         </xsl:call-template>
1311                                                 </xsl:when>
1312                                                 <xsl:when test="680 &lt;= @tag and @tag &lt;=688">
1313                                                         <xsl:call-template name="subfieldSelect">
1314                                                                 <xsl:with-param name="codes">ai</xsl:with-param>
1315                                                         </xsl:call-template>
1316                                                 </xsl:when>
1317                                         </xsl:choose>
1318                                 </xsl:with-param>
1319                         </xsl:call-template>
1320                 </mads:note>
1321         </xsl:template>
1322
1323         <!-- ========== url  ========== -->
1324         <xsl:template match="marc:datafield[@tag=856][marc:subfield[@code='u']]">
1325                 <mads:url>
1326                         <xsl:if test="marc:subfield[@code='z' or @code='3']">
1327                                 <xsl:attribute name="displayLabel">
1328                                         <xsl:call-template name="subfieldSelect">
1329                                                 <xsl:with-param name="codes">z3</xsl:with-param>
1330                                         </xsl:call-template>
1331                                 </xsl:attribute>
1332                         </xsl:if>
1333                         <xsl:value-of select="marc:subfield[@code='u']"/>
1334                 </mads:url>
1335         </xsl:template>
1336
1337         <xsl:template name="relatedTypeAttribute">
1338                 <xsl:choose>
1339                         <xsl:when
1340                                 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">
1341                                 <xsl:if test="substring(marc:subfield[@code='w'],1,1)='a'">
1342                                         <xsl:attribute name="type">earlier</xsl:attribute>
1343                                 </xsl:if>
1344                                 <xsl:if test="substring(marc:subfield[@code='w'],1,1)='b'">
1345                                         <xsl:attribute name="type">later</xsl:attribute>
1346                                 </xsl:if>
1347                                 <xsl:if test="substring(marc:subfield[@code='w'],1,1)='t'">
1348                                         <xsl:attribute name="type">parentOrg</xsl:attribute>
1349                                 </xsl:if>
1350                                 <xsl:if test="substring(marc:subfield[@code='w'],1,1)='g'">
1351                                         <xsl:attribute name="type">broader</xsl:attribute>
1352                                 </xsl:if>
1353                                 <xsl:if test="substring(marc:subfield[@code='w'],1,1)='h'">
1354                                         <xsl:attribute name="type">narrower</xsl:attribute>
1355                                 </xsl:if>
1356                                 <xsl:if test="substring(marc:subfield[@code='w'],1,1)='r'">
1357                                         <xsl:attribute name="type">other</xsl:attribute>
1358                                 </xsl:if>
1359                                 <xsl:if test="contains('fin|', substring(marc:subfield[@code='w'],1,1))">
1360                                         <xsl:attribute name="type">other</xsl:attribute>
1361                                 </xsl:if>
1362                         </xsl:when>
1363                         <xsl:when test="@tag=530 or @tag=730">
1364                                 <xsl:attribute name="type">other</xsl:attribute>
1365                         </xsl:when>
1366                         <xsl:otherwise>
1367                                 <!-- 7xx -->
1368                                 <xsl:attribute name="type">equivalent</xsl:attribute>
1369                         </xsl:otherwise>
1370                 </xsl:choose>
1371                 <xsl:apply-templates select="marc:subfield[@code='i']"/>
1372         </xsl:template>
1373         
1374
1375
1376         <xsl:template name="variantTypeAttribute">
1377                 <xsl:choose>
1378                         <xsl:when
1379                                 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">
1380                                 <xsl:if test="substring(marc:subfield[@code='w'],1,1)='d'">
1381                                         <xsl:attribute name="type">acronym</xsl:attribute>
1382                                 </xsl:if>
1383                                 <xsl:if test="substring(marc:subfield[@code='w'],1,1)='n'">
1384                                         <xsl:attribute name="type">other</xsl:attribute>
1385                                 </xsl:if>
1386                                 <xsl:if test="contains('fit', substring(marc:subfield[@code='w'],1,1))">
1387                                         <xsl:attribute name="type">other</xsl:attribute>
1388                                 </xsl:if>
1389                         </xsl:when>
1390                         <xsl:otherwise>
1391                                 <!-- 430  -->
1392                                 <xsl:attribute name="type">other</xsl:attribute>
1393                         </xsl:otherwise>
1394                 </xsl:choose>
1395                 <xsl:apply-templates select="marc:subfield[@code='i']"/>
1396         </xsl:template>
1397
1398         <xsl:template name="setAuthority">
1399                 <xsl:choose>
1400                         <!-- can be called from the datafield or subfield level, so "..//@tag" means
1401                         the tag can be at the subfield's parent level or at the datafields own level -->
1402
1403                         <xsl:when
1404                                 test="ancestor-or-self::marc:datafield/@tag=100 and (@ind1=0 or @ind1=1) and $controlField008-11='a' and $controlField008-14='a'">
1405                                 <xsl:attribute name="authority">
1406                                         <xsl:text>naf</xsl:text>
1407                                 </xsl:attribute>
1408                         </xsl:when>
1409                         <xsl:when
1410                                 test="ancestor-or-self::marc:datafield/@tag=100 and (@ind1=0 or @ind1=1) and $controlField008-11='a' and $controlField008-14='b'">
1411                                 <xsl:attribute name="authority">
1412                                         <xsl:text>lcsh</xsl:text>
1413                                 </xsl:attribute>
1414                         </xsl:when>
1415                         <xsl:when
1416                                 test="ancestor-or-self::marc:datafield/@tag=100 and (@ind1=0 or @ind1=1) and $controlField008-11='k'">
1417                                 <xsl:attribute name="authority">
1418                                         <xsl:text>lacnaf</xsl:text>
1419                                 </xsl:attribute>
1420                         </xsl:when>
1421                         <xsl:when
1422                                 test="ancestor-or-self::marc:datafield/@tag=100 and @ind1=3 and $controlField008-11='a' and $controlField008-14='b'">
1423                                 <xsl:attribute name="authority">
1424                                         <xsl:text>lcsh</xsl:text>
1425                                 </xsl:attribute>
1426                         </xsl:when>
1427                         <xsl:when
1428                                 test="ancestor-or-self::marc:datafield/@tag=100 and @ind1=3 and $controlField008-11='k' and $controlField008-14='b'">
1429                                 <xsl:attribute name="authority">cash</xsl:attribute>
1430                         </xsl:when>
1431                         <xsl:when
1432                                 test="ancestor-or-self::marc:datafield/@tag=110 and $controlField008-11='a' and $controlField008-14='a'">
1433                                 <xsl:attribute name="authority">naf</xsl:attribute>
1434                         </xsl:when>
1435                         <xsl:when
1436                                 test="ancestor-or-self::marc:datafield/@tag=110 and $controlField008-11='a' and $controlField008-14='b'">
1437                                 <xsl:attribute name="authority">lcsh</xsl:attribute>
1438                         </xsl:when>
1439                         <xsl:when
1440                                 test="ancestor-or-self::marc:datafield/@tag=110 and $controlField008-11='k' and $controlField008-14='a'">
1441                                 <xsl:attribute name="authority">
1442                                         <xsl:text>lacnaf</xsl:text>
1443                                 </xsl:attribute>
1444                         </xsl:when>
1445                         <xsl:when
1446                                 test="ancestor-or-self::marc:datafield/@tag=110 and $controlField008-11='k' and $controlField008-14='b'">
1447                                 <xsl:attribute name="authority">
1448                                         <xsl:text>cash</xsl:text>
1449                                 </xsl:attribute>
1450                         </xsl:when>
1451                         <xsl:when
1452                                 test="100 &lt;= ancestor-or-self::marc:datafield/@tag and ancestor-or-self::marc:datafield/@tag &lt;= 155 and $controlField008-11='b'">
1453                                 <xsl:attribute name="authority">
1454                                         <xsl:text>lcshcl</xsl:text>
1455                                 </xsl:attribute>
1456                         </xsl:when>
1457                         <xsl:when
1458                                 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'">
1459                                 <xsl:attribute name="authority">
1460                                         <xsl:text>nlmnaf</xsl:text>
1461                                 </xsl:attribute>
1462                         </xsl:when>
1463                         <xsl:when
1464                                 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'">
1465                                 <xsl:attribute name="authority">
1466                                         <xsl:text>nalnaf</xsl:text>
1467                                 </xsl:attribute>
1468                         </xsl:when>
1469                         <xsl:when
1470                                 test="100 &lt;= ancestor-or-self::marc:datafield/@tag and ancestor-or-self::marc:datafield/@tag &lt;= 155 and $controlField008-11='r'">
1471                                 <xsl:attribute name="authority">
1472                                         <xsl:text>aat</xsl:text>
1473                                 </xsl:attribute>
1474                         </xsl:when>
1475                         <xsl:when
1476                                 test="100 &lt;= ancestor-or-self::marc:datafield/@tag and ancestor-or-self::marc:datafield/@tag &lt;= 155 and $controlField008-11='s'">
1477                                 <xsl:attribute name="authority">sears</xsl:attribute>
1478                         </xsl:when>
1479                         <xsl:when
1480                                 test="100 &lt;= ancestor-or-self::marc:datafield/@tag and ancestor-or-self::marc:datafield/@tag &lt;= 155 and $controlField008-11='v'">
1481                                 <xsl:attribute name="authority">rvm</xsl:attribute>
1482                         </xsl:when>
1483                         <xsl:when
1484                                 test="100 &lt;= ancestor-or-self::marc:datafield/@tag and ancestor-or-self::marc:datafield/@tag &lt;= 155 and $controlField008-11='z'">
1485                                 <xsl:attribute name="authority">
1486                                         <xsl:value-of
1487                                                 select="../marc:datafield[ancestor-or-self::marc:datafield/@tag=040]/marc:subfield[@code='f']"
1488                                         />
1489                                 </xsl:attribute>
1490                         </xsl:when>
1491                         <xsl:when
1492                                 test="(ancestor-or-self::marc:datafield/@tag=111 or ancestor-or-self::marc:datafield/@tag=130) and $controlField008-11='a' and $controlField008-14='a'">
1493                                 <xsl:attribute name="authority">
1494                                         <xsl:text>naf</xsl:text>
1495                                 </xsl:attribute>
1496                         </xsl:when>
1497                         <xsl:when
1498                                 test="(ancestor-or-self::marc:datafield/@tag=111 or ancestor-or-self::marc:datafield/@tag=130) and $controlField008-11='a' and $controlField008-14='b'">
1499                                 <xsl:attribute name="authority">
1500                                         <xsl:text>lcsh</xsl:text>
1501                                 </xsl:attribute>
1502                         </xsl:when>
1503                         <xsl:when
1504                                 test="(ancestor-or-self::marc:datafield/@tag=111 or ancestor-or-self::marc:datafield/@tag=130) and $controlField008-11='k' ">
1505                                 <xsl:attribute name="authority">
1506                                         <xsl:text>lacnaf</xsl:text>
1507                                 </xsl:attribute>
1508                         </xsl:when>
1509                         <xsl:when
1510                                 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' ">
1511                                 <xsl:attribute name="authority">
1512                                         <xsl:text>lcsh</xsl:text>
1513                                 </xsl:attribute>
1514                         </xsl:when>
1515                         <xsl:when
1516                                 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' ">
1517                                 <xsl:attribute name="authority">
1518                                         <xsl:text>lcsh</xsl:text>
1519                                 </xsl:attribute>
1520                         </xsl:when>
1521                         <xsl:when
1522                                 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' ">
1523                                 <xsl:attribute name="authority">
1524                                         <xsl:text>mesh</xsl:text>
1525                                 </xsl:attribute>
1526                         </xsl:when>
1527                         <xsl:when
1528                                 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' ">
1529                                 <xsl:attribute name="authority">
1530                                         <xsl:text>nal</xsl:text>
1531                                 </xsl:attribute>
1532                         </xsl:when>
1533                         <xsl:when
1534                                 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' ">
1535                                 <xsl:attribute name="authority">
1536                                         <xsl:text>cash</xsl:text>
1537                                 </xsl:attribute>
1538                         </xsl:when>
1539                         <xsl:when
1540                                 test="ancestor-or-self::marc:datafield/@tag=151 and $controlField008-11='a' and $controlField008-14='a'">
1541                                 <xsl:attribute name="authority">
1542                                         <xsl:text>naf</xsl:text>
1543                                 </xsl:attribute>
1544                         </xsl:when>
1545                         <xsl:when
1546                                 test="ancestor-or-self::marc:datafield/@tag=151 and $controlField008-11='a' and $controlField008-14='b'">
1547                                 <xsl:attribute name="authority">lcsh</xsl:attribute>
1548                         </xsl:when>
1549                         <xsl:when
1550                                 test="ancestor-or-self::marc:datafield/@tag=151 and $controlField008-11='k' and $controlField008-14='a'">
1551                                 <xsl:attribute name="authority">lacnaf</xsl:attribute>
1552                         </xsl:when>
1553                         <xsl:when
1554                                 test="ancestor-or-self::marc:datafield/@tag=151 and $controlField008-11='k' and $controlField008-14='b'">
1555                                 <xsl:attribute name="authority">cash</xsl:attribute>
1556                         </xsl:when>
1557                         <xsl:when
1558                                 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'">
1559                                 <xsl:attribute name="authority">lcsh</xsl:attribute>
1560                         </xsl:when>
1561                         <xsl:when
1562                                 test="ancestor-or-self::marc:datafield/@tag=700 and (@ind1='0' or @ind1='1') and @ind2='0'">
1563                                 <xsl:attribute name="authority">naf</xsl:attribute>
1564                         </xsl:when>
1565                         <xsl:when
1566                                 test="ancestor-or-self::marc:datafield/@tag=700 and (@ind1='0' or @ind1='1') and @ind2='5'">
1567                                 <xsl:attribute name="authority">lacnaf</xsl:attribute>
1568                         </xsl:when>
1569                         <xsl:when test="ancestor-or-self::marc:datafield/@tag=700 and @ind1='3' and @ind2='0'">
1570                                 <xsl:attribute name="authority">lcsh</xsl:attribute>
1571                         </xsl:when>
1572                         <xsl:when test="ancestor-or-self::marc:datafield/@tag=700 and @ind1='3' and @ind2='5'">
1573                                 <xsl:attribute name="authority">cash</xsl:attribute>
1574                         </xsl:when>
1575                         <xsl:when
1576                                 test="(700 &lt;= ancestor-or-self::marc:datafield/@tag and ancestor-or-self::marc:datafield/@tag &lt;= 755 ) and @ind2='1'">
1577                                 <xsl:attribute name="authority">lcshcl</xsl:attribute>
1578                         </xsl:when>
1579                         <xsl:when
1580                                 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'">
1581                                 <xsl:attribute name="authority">nlmnaf</xsl:attribute>
1582                         </xsl:when>
1583                         <xsl:when
1584                                 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'">
1585                                 <xsl:attribute name="authority">nalnaf</xsl:attribute>
1586                         </xsl:when>
1587                         <xsl:when
1588                                 test="(700 &lt;= ancestor-or-self::marc:datafield/@tag and ancestor-or-self::marc:datafield/@tag &lt;= 755 ) and @ind2='6'">
1589                                 <xsl:attribute name="authority">rvm</xsl:attribute>
1590                         </xsl:when>
1591                         <xsl:when
1592                                 test="(700 &lt;= ancestor-or-self::marc:datafield/@tag and ancestor-or-self::marc:datafield/@tag &lt;= 755 ) and @ind2='7'">
1593                                 <xsl:attribute name="authority">
1594                                         <xsl:value-of select="marc:subfield[@code='2']"/>
1595                                 </xsl:attribute>
1596                         </xsl:when>
1597                         <xsl:when
1598                                 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'">
1599                                 <xsl:attribute name="authority">lacnaf</xsl:attribute>
1600                         </xsl:when>
1601                         <xsl:when
1602                                 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'">
1603                                 <xsl:attribute name="authority">naf</xsl:attribute>
1604                         </xsl:when>
1605                         <xsl:when
1606                                 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'">
1607                                 <xsl:attribute name="authority">lcsh</xsl:attribute>
1608                         </xsl:when>
1609                         <xsl:when
1610                                 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'">
1611                                 <xsl:attribute name="authority">mesh</xsl:attribute>
1612                         </xsl:when>
1613                         <xsl:when
1614                                 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'">
1615                                 <xsl:attribute name="authority">nal</xsl:attribute>
1616                         </xsl:when>
1617                         <xsl:when
1618                                 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'">
1619                                 <xsl:attribute name="authority">cash</xsl:attribute>
1620                         </xsl:when>
1621                 </xsl:choose>
1622         </xsl:template>
1623         <xsl:template match="*"/>
1624 </xsl:stylesheet>$XSLT$);