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