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