LP#1638299: MADS 2.1 stylesheet
authorMike Rylander <mrylander@gmail.com>
Tue, 6 Dec 2016 21:49:15 +0000 (16:49 -0500)
committerKathy Lussier <klussier@masslnc.org>
Fri, 1 Sep 2017 19:39:32 +0000 (15:39 -0400)
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Open-ILS/src/sql/Pg/955.data.MADS21-xsl.sql [new file with mode: 0644]
Open-ILS/src/sql/Pg/upgrade/XXXX.data.MADS21-xsl.sql [new file with mode: 0644]
Open-ILS/xsl/MARC21slim2MADS.xsl [new file with mode: 0644]

diff --git a/Open-ILS/src/sql/Pg/955.data.MADS21-xsl.sql b/Open-ILS/src/sql/Pg/955.data.MADS21-xsl.sql
new file mode 100644 (file)
index 0000000..225be32
--- /dev/null
@@ -0,0 +1,1624 @@
+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"?>
+<xsl:stylesheet version="1.0" xmlns:mads="http://www.loc.gov/mads/v2"
+       xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:marc="http://www.loc.gov/MARC21/slim"
+       xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="marc">
+       <xsl:output method="xml" indent="yes" encoding="UTF-8"/>
+       <xsl:strip-space elements="*"/>
+
+       <xsl:variable name="ascii">
+               <xsl:text> !"#$%&amp;'()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~</xsl:text>
+       </xsl:variable>
+
+       <xsl:variable name="latin1">
+               <xsl:text> ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ</xsl:text>
+       </xsl:variable>
+       <!-- Characters that usually don't need to be escaped -->
+       <xsl:variable name="safe">
+               <xsl:text>!'()*-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~</xsl:text>
+       </xsl:variable>
+
+       <xsl:variable name="hex">0123456789ABCDEF</xsl:variable>
+
+
+       <xsl:template name="datafield">
+               <xsl:param name="tag"/>
+               <xsl:param name="ind1">
+                       <xsl:text> </xsl:text>
+               </xsl:param>
+               <xsl:param name="ind2">
+                       <xsl:text> </xsl:text>
+               </xsl:param>
+               <xsl:param name="subfields"/>
+               <xsl:element name="marc:datafield">
+                       <xsl:attribute name="tag">
+                               <xsl:value-of select="$tag"/>
+                       </xsl:attribute>
+                       <xsl:attribute name="ind1">
+                               <xsl:value-of select="$ind1"/>
+                       </xsl:attribute>
+                       <xsl:attribute name="ind2">
+                               <xsl:value-of select="$ind2"/>
+                       </xsl:attribute>
+                       <xsl:copy-of select="$subfields"/>
+               </xsl:element>
+       </xsl:template>
+
+       <xsl:template name="subfieldSelect">
+               <xsl:param name="codes">abcdefghijklmnopqrstuvwxyz</xsl:param>
+               <xsl:param name="delimeter">
+                       <xsl:text> </xsl:text>
+               </xsl:param>
+               <xsl:variable name="str">
+                       <xsl:for-each select="marc:subfield">
+                               <xsl:if test="contains($codes, @code)">
+                                       <xsl:value-of select="text()"/>
+                                       <xsl:value-of select="$delimeter"/>
+                               </xsl:if>
+                       </xsl:for-each>
+               </xsl:variable>
+               <xsl:value-of select="substring($str,1,string-length($str)-string-length($delimeter))"/>
+       </xsl:template>
+
+       <xsl:template name="buildSpaces">
+               <xsl:param name="spaces"/>
+               <xsl:param name="char">
+                       <xsl:text> </xsl:text>
+               </xsl:param>
+               <xsl:if test="$spaces>0">
+                       <xsl:value-of select="$char"/>
+                       <xsl:call-template name="buildSpaces">
+                               <xsl:with-param name="spaces" select="$spaces - 1"/>
+                               <xsl:with-param name="char" select="$char"/>
+                       </xsl:call-template>
+               </xsl:if>
+       </xsl:template>
+
+       <xsl:template name="chopPunctuation">
+               <xsl:param name="chopString"/>
+               <xsl:param name="punctuation">
+                       <xsl:text>.:,;/ </xsl:text>
+               </xsl:param>
+               <xsl:variable name="length" select="string-length($chopString)"/>
+               <xsl:choose>
+                       <xsl:when test="$length=0"/>
+                       <xsl:when test="contains($punctuation, substring($chopString,$length,1))">
+                               <xsl:call-template name="chopPunctuation">
+                                       <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
+                                       <xsl:with-param name="punctuation" select="$punctuation"/>
+                               </xsl:call-template>
+                       </xsl:when>
+                       <xsl:when test="not($chopString)"/>
+                       <xsl:otherwise>
+                               <xsl:value-of select="$chopString"/>
+                       </xsl:otherwise>
+               </xsl:choose>
+       </xsl:template>
+
+       <xsl:template name="chopPunctuationFront">
+               <xsl:param name="chopString"/>
+               <xsl:variable name="length" select="string-length($chopString)"/>
+               <xsl:choose>
+                       <xsl:when test="$length=0"/>
+                       <xsl:when test="contains('.:,;/[ ', substring($chopString,1,1))">
+                               <xsl:call-template name="chopPunctuationFront">
+                                       <xsl:with-param name="chopString" select="substring($chopString,2,$length - 1)"
+                                       />
+                               </xsl:call-template>
+                       </xsl:when>
+                       <xsl:when test="not($chopString)"/>
+                       <xsl:otherwise>
+                               <xsl:value-of select="$chopString"/>
+                       </xsl:otherwise>
+               </xsl:choose>
+       </xsl:template>
+
+       <xsl:template name="chopPunctuationBack">
+               <xsl:param name="chopString"/>
+               <xsl:param name="punctuation">
+                       <xsl:text>.:,;/] </xsl:text>
+               </xsl:param>
+               <xsl:variable name="length" select="string-length($chopString)"/>
+               <xsl:choose>
+                       <xsl:when test="$length=0"/>
+                       <xsl:when test="contains($punctuation, substring($chopString,$length,1))">
+                               <xsl:call-template name="chopPunctuation">
+                                       <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
+                                       <xsl:with-param name="punctuation" select="$punctuation"/>
+                               </xsl:call-template>
+                       </xsl:when>
+                       <xsl:when test="not($chopString)"/>
+                       <xsl:otherwise>
+                               <xsl:value-of select="$chopString"/>
+                       </xsl:otherwise>
+               </xsl:choose>
+       </xsl:template>
+
+       <!-- nate added 12/14/2007 for lccn.loc.gov: url encode ampersand, etc. -->
+       <xsl:template name="url-encode">
+
+               <xsl:param name="str"/>
+
+               <xsl:if test="$str">
+                       <xsl:variable name="first-char" select="substring($str,1,1)"/>
+                       <xsl:choose>
+                               <xsl:when test="contains($safe,$first-char)">
+                                       <xsl:value-of select="$first-char"/>
+                               </xsl:when>
+                               <xsl:otherwise>
+                                       <xsl:variable name="codepoint">
+                                               <xsl:choose>
+                                                       <xsl:when test="contains($ascii,$first-char)">
+                                                               <xsl:value-of
+                                                                       select="string-length(substring-before($ascii,$first-char)) + 32"
+                                                               />
+                                                       </xsl:when>
+                                                       <xsl:when test="contains($latin1,$first-char)">
+                                                               <xsl:value-of
+                                                                       select="string-length(substring-before($latin1,$first-char)) + 160"/>
+                                                               <!-- was 160 -->
+                                                       </xsl:when>
+                                                       <xsl:otherwise>
+                                                               <xsl:message terminate="no">Warning: string contains a character
+                                                                       that is out of range! Substituting "?".</xsl:message>
+                                                               <xsl:text>63</xsl:text>
+                                                       </xsl:otherwise>
+                                               </xsl:choose>
+                                       </xsl:variable>
+                                       <xsl:variable name="hex-digit1"
+                                               select="substring($hex,floor($codepoint div 16) + 1,1)"/>
+                                       <xsl:variable name="hex-digit2" select="substring($hex,$codepoint mod 16 + 1,1)"/>
+                                       <!-- <xsl:value-of select="concat('%',$hex-digit2)"/> -->
+                                       <xsl:value-of select="concat('%',$hex-digit1,$hex-digit2)"/>
+                               </xsl:otherwise>
+                       </xsl:choose>
+                       <xsl:if test="string-length($str) &gt; 1">
+                               <xsl:call-template name="url-encode">
+                                       <xsl:with-param name="str" select="substring($str,2)"/>
+                               </xsl:call-template>
+                       </xsl:if>
+               </xsl:if>
+       </xsl:template>
+
+
+<!--
+2.14    Fixed bug in mads:geographic attributes syntax                                      ws   05/04/2016            
+2.13   fixed repeating <geographic>                                                                                                            tmee 01/31/2014
+2.12   added $2 authority for <classification>                                                                                         tmee 09/18/2012
+2.11   added delimiters between <classification> subfields                                                                     tmee 09/18/2012
+2.10   fixed type="other" and type="otherType" for mads:related                                                        tmee 09/16/2011
+2.09   fixed professionTerm and genreTerm empty tag error                                                                      tmee 09/16/2011
+2.08   fixed marc:subfield @code='i' matching error                                                                            tmee 09/16/2011
+2.07   fixed 555 duplication error                                                                                                                     tmee 08/10/2011 
+2.06   fixed topic subfield error                                                                                                                      tmee 08/10/2011 
+2.05   fixed title subfield error                                                                                                                      tmee 06/20/2011 
+2.04   fixed geographicSubdivision mapping for authority element                                                       tmee 06/16/2011
+2.03   added classification for 053, 055, 060, 065, 070, 080, 082, 083, 086, 087                       tmee 06/03/2011         
+2.02   added descriptionStandard for 008/10                                                                                            tmee 04/27/2011
+2.01   added extensions for 046, 336, 370, 374, 375, 376                                                                       tmee 04/08/2011
+2.00   redefined imported MODS elements in version 1.0 to MADS elements in version 2.0         tmee 02/08/2011
+1.08   added 372 subfields $a $s $t for <fieldOfActivity>                                                                      tmee 06/24/2010
+1.07   removed role/roleTerm 100, 110, 111, 400, 410, 411, 500, 510, 511, 700, 710, 711        tmee 06/24/2010
+1.06   added strip-space                                                                                                                                       tmee 06/24/2010
+1.05   added subfield $a for 130, 430, 530                                                                                                     tmee 06/21/2010
+1.04   fixed 550 z omission                                                                                                                            ntra 08/11/2008
+1.03   removed duplication of 550 $a text                                                                                                      tmee 11/01/2006
+1.02   fixed namespace references between mads and mods                                                                        ntra 10/06/2006
+1.01   revised                                                                                                                                                         rgue/jrad 11/29/05
+1.00   adapted from MARC21Slim2MODS3.xsl                                                                                                       ntra 07/06/05
+-->
+
+       <!-- authority attribute defaults to 'naf' if not set using this authority parameter, for <authority> descriptors: name, titleInfo, geographic -->
+       <xsl:param name="authority"/>
+       <xsl:variable name="auth">
+               <xsl:choose>
+                       <xsl:when test="$authority">
+                               <xsl:value-of select="$authority"/>
+                       </xsl:when>
+                       <xsl:otherwise>naf</xsl:otherwise>
+               </xsl:choose>
+       </xsl:variable>
+       <xsl:variable name="controlField008" select="marc:controlfield[@tag='008']"/>
+       <xsl:variable name="controlField008-06"
+               select="substring(descendant-or-self::marc:controlfield[@tag=008],7,1)"/>
+       <xsl:variable name="controlField008-11"
+               select="substring(descendant-or-self::marc:controlfield[@tag=008],12,1)"/>
+       <xsl:variable name="controlField008-14"
+               select="substring(descendant-or-self::marc:controlfield[@tag=008],15,1)"/>
+       <xsl:template match="/">
+               <xsl:choose>
+                       <xsl:when test="descendant-or-self::marc:collection">
+                               <mads:madsCollection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+                                       xsi:schemaLocation="http://www.loc.gov/mads/v2 http://www.loc.gov/standards/mads/v2/mads-2-0.xsd">
+                                       <xsl:for-each select="descendant-or-self::marc:collection/marc:record">
+                                               <mads:mads version="2.0">
+                                                       <xsl:call-template name="marcRecord"/>
+                                               </mads:mads>
+                                       </xsl:for-each>
+                               </mads:madsCollection>
+                       </xsl:when>
+                       <xsl:otherwise>
+                               <mads:mads version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+                                       xsi:schemaLocation="http://www.loc.gov/mads/v2 http://www.loc.gov/standards/mads/mads-2-0.xsd">
+                                       <xsl:for-each select="descendant-or-self::marc:record">
+                                               <xsl:call-template name="marcRecord"/>
+                                       </xsl:for-each>
+                               </mads:mads>
+                       </xsl:otherwise>
+               </xsl:choose>
+       </xsl:template>
+
+       <xsl:template name="marcRecord">
+               <mads:authority>
+                       <!-- 2.04 -->
+                       <xsl:choose>
+                               <xsl:when test="$controlField008-06='d'">
+                                       <xsl:attribute name="geographicSubdivision">
+                                               <xsl:text>direct</xsl:text>
+                                       </xsl:attribute>
+                               </xsl:when>
+                               <xsl:when test="$controlField008-06='i'">
+                                       <xsl:attribute name="geographicSubdivision">
+                                               <xsl:text>indirect</xsl:text>
+                                       </xsl:attribute>
+                               </xsl:when>
+                               <xsl:when test="$controlField008-06='n'">
+                                       <xsl:attribute name="geographicSubdivision">
+                                               <xsl:text>not applicable</xsl:text>
+                                       </xsl:attribute>
+                               </xsl:when>
+                       </xsl:choose>
+                       
+                       <xsl:apply-templates select="marc:datafield[100 &lt;= @tag  and @tag &lt; 200]"/>               
+               </mads:authority>
+
+               <!-- related -->
+               <xsl:apply-templates
+                       select="marc:datafield[500 &lt;= @tag and @tag &lt;= 585]|marc:datafield[700 &lt;= @tag and @tag &lt;= 785]"/>
+
+               <!-- variant -->
+               <xsl:apply-templates select="marc:datafield[400 &lt;= @tag and @tag &lt;= 485]"/>
+
+               <!-- notes -->
+               <xsl:apply-templates select="marc:datafield[667 &lt;= @tag and @tag &lt;= 688]"/>
+
+               <!-- url -->
+               <xsl:apply-templates select="marc:datafield[@tag=856]"/>
+               <xsl:apply-templates select="marc:datafield[@tag=010]"/>
+               <xsl:apply-templates select="marc:datafield[@tag=024]"/>
+               <xsl:apply-templates select="marc:datafield[@tag=372]"/>
+               
+               <!-- classification -->
+               <xsl:apply-templates select="marc:datafield[@tag=053]"/>
+               <xsl:apply-templates select="marc:datafield[@tag=055]"/>
+               <xsl:apply-templates select="marc:datafield[@tag=060]"/>
+               <xsl:apply-templates select="marc:datafield[@tag=065]"/>
+               <xsl:apply-templates select="marc:datafield[@tag=070]"/>
+               <xsl:apply-templates select="marc:datafield[@tag=080]"/>
+               <xsl:apply-templates select="marc:datafield[@tag=082]"/>
+               <xsl:apply-templates select="marc:datafield[@tag=083]"/>
+               <xsl:apply-templates select="marc:datafield[@tag=086]"/>
+               <xsl:apply-templates select="marc:datafield[@tag=087]"/>
+
+               <!-- affiliation-->
+               <xsl:for-each select="marc:datafield[@tag=373]">
+                       <mads:affiliation>
+                               <mads:position>
+                                       <xsl:value-of select="marc:subfield[@code='a']"/>
+                               </mads:position>
+                               <mads:dateValid point="start">
+                                       <xsl:value-of select="marc:subfield[@code='s']"/>
+                               </mads:dateValid>
+                               <mads:dateValid point="end">
+                                       <xsl:value-of select="marc:subfield[@code='t']"/>
+                               </mads:dateValid>
+                       </mads:affiliation>
+               </xsl:for-each>
+               <xsl:for-each select="marc:datafield[@tag=371]">
+                       <mads:affiliation>
+                               <mads:address>
+                                       <mads:street>
+                                               <xsl:value-of select="marc:subfield[@code='a']"/>
+                                       </mads:street>
+                                       <mads:city>
+                                               <xsl:value-of select="marc:subfield[@code='b']"/>
+                                       </mads:city>
+                                       <mads:state>
+                                               <xsl:value-of select="marc:subfield[@code='c']"/>
+                                       </mads:state>
+                                       <mads:country>
+                                               <xsl:value-of select="marc:subfield[@code='d']"/>
+                                       </mads:country>
+                                       <mads:postcode>
+                                               <xsl:value-of select="marc:subfield[@code='e']"/>
+                                       </mads:postcode>
+                               </mads:address>
+                               <mads:email>
+                                       <xsl:value-of select="marc:subfield[@code='m']"/>
+                               </mads:email>
+                       </mads:affiliation>
+               </xsl:for-each>
+
+               <!-- extension-->
+               <xsl:for-each select="marc:datafield[@tag=336]">
+                       <mads:extension>
+                               <mads:contentType>
+                                       <mads:contentType type="text">
+                                               <xsl:value-of select="marc:subfield[@code='a']"/>
+                                       </mads:contentType>
+                                       <mads:contentType type="code">
+                                               <xsl:value-of select="marc:subfield[@code='b']"/>
+                                       </mads:contentType>
+                               </mads:contentType>
+                       </mads:extension>
+               </xsl:for-each>
+
+               <xsl:for-each select="marc:datafield[@tag=374]">
+                       <mads:extension>
+                               <mads:profession>
+                                       <xsl:choose>
+                                               <xsl:when test="marc:subfield[@code='a']">
+                                                       <mads:professionTerm>
+                                                               <xsl:value-of select="marc:subfield[@code='a']"/>
+                                                       </mads:professionTerm>
+                                               </xsl:when>
+                                               <xsl:when test="marc:subfield[@code='s']">
+                                                       <mads:dateValid point="start">
+                                                               <xsl:value-of select="marc:subfield[@code='s']"/>
+                                                       </mads:dateValid>
+                                               </xsl:when>
+                                               <xsl:when test="marc:subfield[@code='t']">
+                                                       <mads:dateValid point="end">
+                                                               <xsl:value-of select="marc:subfield[@code='t']"/>
+                                                       </mads:dateValid>
+                                               </xsl:when>
+                                       </xsl:choose>
+                               </mads:profession>
+                       </mads:extension>
+               </xsl:for-each>
+               
+               <xsl:for-each select="marc:datafield[@tag=375]">
+                       <mads:extension>
+                               <mads:gender>
+                                       <xsl:choose>
+                                               <xsl:when test="marc:subfield[@code='a']">
+                                                       <mads:genderTerm>
+                                                               <xsl:value-of select="marc:subfield[@code='a']"/>
+                                                       </mads:genderTerm>
+                                               </xsl:when>
+                                               <xsl:when test="marc:subfield[@code='s']">
+                                                       <mads:dateValid point="start">
+                                                               <xsl:value-of select="marc:subfield[@code='s']"/>
+                                                       </mads:dateValid>
+                                               </xsl:when>
+                                               <xsl:when test="marc:subfield[@code='t']">
+                                                       <mads:dateValid point="end">
+                                                               <xsl:value-of select="marc:subfield[@code='t']"/>
+                                                       </mads:dateValid>
+                                               </xsl:when>
+                                       </xsl:choose>
+                               </mads:gender>
+                       </mads:extension>
+               </xsl:for-each>
+
+               <xsl:for-each select="marc:datafield[@tag=376]">
+                       <mads:extension>
+                               <mads:familyInformation>
+                                       <mads:typeOfFamily>
+                                               <xsl:value-of select="marc:subfield[@code='a']"/>
+                                       </mads:typeOfFamily>
+                                       <mads:nameOfProminentMember>
+                                               <xsl:value-of select="marc:subfield[@code='b']"/>
+                                       </mads:nameOfProminentMember>
+                                       <mads:hereditaryTitle>
+                                               <xsl:value-of select="marc:subfield[@code='c']"/>
+                                       </mads:hereditaryTitle>
+                                       <mads:dateValid point="start">
+                                               <xsl:value-of select="marc:subfield[@code='s']"/>
+                                       </mads:dateValid>
+                                       <mads:dateValid point="end">
+                                               <xsl:value-of select="marc:subfield[@code='t']"/>
+                                       </mads:dateValid>
+                               </mads:familyInformation>
+                       </mads:extension>
+               </xsl:for-each>
+
+               <mads:recordInfo>
+                       <mads:recordOrigin>Converted from MARCXML to MADS version 2.0 (Revision 2.13)</mads:recordOrigin>
+                       <!-- <xsl:apply-templates select="marc:datafield[@tag=024]"/> -->
+
+                       <xsl:apply-templates select="marc:datafield[@tag=040]/marc:subfield[@code='a']"/>
+                       <xsl:apply-templates select="marc:controlfield[@tag=005]"/>
+                       <xsl:apply-templates select="marc:controlfield[@tag=001]"/>
+                       <xsl:apply-templates select="marc:datafield[@tag=040]/marc:subfield[@code='b']"/>
+                       <xsl:apply-templates select="marc:datafield[@tag=040]/marc:subfield[@code='e']"/>
+                       <xsl:for-each select="marc:controlfield[@tag=008]">
+                               <xsl:if test="substring(.,11,1)='a'">
+                                       <mads:descriptionStandard>
+                                               <xsl:text>earlier rules</xsl:text>
+                                       </mads:descriptionStandard>
+                               </xsl:if>
+                               <xsl:if test="substring(.,11,1)='b'">
+                                       <mads:descriptionStandard>
+                                               <xsl:text>aacr1</xsl:text>
+                                       </mads:descriptionStandard>
+                               </xsl:if>
+                               <xsl:if test="substring(.,11,1)='c'">
+                                       <mads:descriptionStandard>
+                                               <xsl:text>aacr2</xsl:text>
+                                       </mads:descriptionStandard>
+                               </xsl:if>
+                               <xsl:if test="substring(.,11,1)='d'">
+                                       <mads:descriptionStandard>
+                                               <xsl:text>aacr2 compatible</xsl:text>
+                                       </mads:descriptionStandard>
+                               </xsl:if>
+                               <xsl:if test="substring(.,11,1)='z'">
+                                       <mads:descriptionStandard>
+                                               <xsl:text>other rules</xsl:text>
+                                       </mads:descriptionStandard>
+                               </xsl:if>
+                       </xsl:for-each>
+               </mads:recordInfo>
+       </xsl:template>
+
+       <!-- start of secondary templates -->
+
+       <!-- ======== xlink ======== -->
+
+       <!-- <xsl:template name="uri"> 
+    <xsl:for-each select="marc:subfield[@code='0']">
+      <xsl:attribute name="xlink:href">
+       <xsl:value-of select="."/>
+      </xsl:attribute>
+    </xsl:for-each>
+     </xsl:template> 
+   -->
+       <xsl:template match="marc:subfield[@code='i']">
+               <xsl:attribute name="otherType">
+                       <xsl:value-of select="."/>
+               </xsl:attribute>
+       </xsl:template>
+
+       <!-- No role/roleTerm mapped in MADS 06/24/2010
+       <xsl:template name="role">
+               <xsl:for-each select="marc:subfield[@code='e']">
+                       <mads:role>
+                               <mads:roleTerm type="text">
+                                       <xsl:value-of select="."/>
+                               </mads:roleTerm>
+                       </mads:role>
+               </xsl:for-each>
+       </xsl:template>
+-->
+
+       <xsl:template name="part">
+               <xsl:variable name="partNumber">
+                       <xsl:call-template name="specialSubfieldSelect">
+                               <xsl:with-param name="axis">n</xsl:with-param>
+                               <xsl:with-param name="anyCodes">n</xsl:with-param>
+                               <xsl:with-param name="afterCodes">fghkdlmor</xsl:with-param>
+                       </xsl:call-template>
+               </xsl:variable>
+               <xsl:variable name="partName">
+                       <xsl:call-template name="specialSubfieldSelect">
+                               <xsl:with-param name="axis">p</xsl:with-param>
+                               <xsl:with-param name="anyCodes">p</xsl:with-param>
+                               <xsl:with-param name="afterCodes">fghkdlmor</xsl:with-param>
+                       </xsl:call-template>
+               </xsl:variable>
+               <xsl:if test="string-length(normalize-space($partNumber))">
+                       <mads:partNumber>
+                               <xsl:call-template name="chopPunctuation">
+                                       <xsl:with-param name="chopString" select="$partNumber"/>
+                               </xsl:call-template>
+                       </mads:partNumber>
+               </xsl:if>
+               <xsl:if test="string-length(normalize-space($partName))">
+                       <mads:partName>
+                               <xsl:call-template name="chopPunctuation">
+                                       <xsl:with-param name="chopString" select="$partName"/>
+                               </xsl:call-template>
+                       </mads:partName>
+               </xsl:if>
+       </xsl:template>
+
+       <xsl:template name="nameABCDN">
+               <xsl:for-each select="marc:subfield[@code='a']">
+                       <mads:namePart>
+                               <xsl:call-template name="chopPunctuation">
+                                       <xsl:with-param name="chopString" select="."/>
+                               </xsl:call-template>
+                       </mads:namePart>
+               </xsl:for-each>
+               <xsl:for-each select="marc:subfield[@code='b']">
+                       <mads:namePart>
+                               <xsl:value-of select="."/>
+                       </mads:namePart>
+               </xsl:for-each>
+               <xsl:if
+                       test="marc:subfield[@code='c'] or marc:subfield[@code='d'] or marc:subfield[@code='n']">
+                       <mads:namePart>
+                               <xsl:call-template name="subfieldSelect">
+                                       <xsl:with-param name="codes">cdn</xsl:with-param>
+                               </xsl:call-template>
+                       </mads:namePart>
+               </xsl:if>
+       </xsl:template>
+
+       <xsl:template name="nameABCDQ">
+               <mads:namePart>
+                       <xsl:call-template name="chopPunctuation">
+                               <xsl:with-param name="chopString">
+                                       <xsl:call-template name="subfieldSelect">
+                                               <xsl:with-param name="codes">aq</xsl:with-param>
+                                       </xsl:call-template>
+                               </xsl:with-param>
+                       </xsl:call-template>
+               </mads:namePart>
+               <xsl:call-template name="termsOfAddress"/>
+               <xsl:call-template name="nameDate"/>
+       </xsl:template>
+
+       <xsl:template name="nameACDENQ">
+               <mads:namePart>
+                       <xsl:call-template name="subfieldSelect">
+                               <xsl:with-param name="codes">acdenq</xsl:with-param>
+                       </xsl:call-template>
+               </mads:namePart>
+       </xsl:template>
+
+       <xsl:template name="nameDate">
+               <xsl:for-each select="marc:subfield[@code='d']">
+                       <mads:namePart type="date">
+                               <xsl:call-template name="chopPunctuation">
+                                       <xsl:with-param name="chopString" select="."/>
+                               </xsl:call-template>
+                       </mads:namePart>
+               </xsl:for-each>
+       </xsl:template>
+
+       <xsl:template name="specialSubfieldSelect">
+               <xsl:param name="anyCodes"/>
+               <xsl:param name="axis"/>
+               <xsl:param name="beforeCodes"/>
+               <xsl:param name="afterCodes"/>
+               <xsl:variable name="str">
+                       <xsl:for-each select="marc:subfield">
+                               <xsl:if
+                                       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])">
+                                       <xsl:value-of select="text()"/>
+                                       <xsl:text> </xsl:text>
+                               </xsl:if>
+                       </xsl:for-each>
+               </xsl:variable>
+               <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+       </xsl:template>
+
+       <xsl:template name="termsOfAddress">
+               <xsl:if test="marc:subfield[@code='b' or @code='c']">
+                       <mads:namePart type="termsOfAddress">
+                               <xsl:call-template name="chopPunctuation">
+                                       <xsl:with-param name="chopString">
+                                               <xsl:call-template name="subfieldSelect">
+                                                       <xsl:with-param name="codes">bc</xsl:with-param>
+                                               </xsl:call-template>
+                                       </xsl:with-param>
+                               </xsl:call-template>
+                       </mads:namePart>
+               </xsl:if>
+       </xsl:template>
+
+       <xsl:template name="displayLabel">
+               <xsl:if test="marc:subfield[@code='z']">
+                       <xsl:attribute name="displayLabel">
+                               <xsl:value-of select="marc:subfield[@code='z']"/>
+                       </xsl:attribute>
+               </xsl:if>
+               <xsl:if test="marc:subfield[@code='3']">
+                       <xsl:attribute name="displayLabel">
+                               <xsl:value-of select="marc:subfield[@code='3']"/>
+                       </xsl:attribute>
+               </xsl:if>
+       </xsl:template>
+
+       <xsl:template name="isInvalid">
+               <xsl:if test="@code='z'">
+                       <xsl:attribute name="invalid">yes</xsl:attribute>
+               </xsl:if>
+       </xsl:template>
+
+       <xsl:template name="sub2Attribute">
+               <!-- 024 -->
+               <xsl:if test="../marc:subfield[@code='2']">
+                       <xsl:attribute name="type">
+                               <xsl:value-of select="../marc:subfield[@code='2']"/>
+                       </xsl:attribute>
+               </xsl:if>
+       </xsl:template>
+
+       <xsl:template match="marc:controlfield[@tag=001]">
+               <mads:recordIdentifier>
+                       <xsl:if test="../marc:controlfield[@tag=003]">
+                               <xsl:attribute name="source">
+                                       <xsl:value-of select="../marc:controlfield[@tag=003]"/>
+                               </xsl:attribute>
+                       </xsl:if>
+                       <xsl:value-of select="."/>
+               </mads:recordIdentifier>
+       </xsl:template>
+
+       <xsl:template match="marc:controlfield[@tag=005]">
+               <mads:recordChangeDate encoding="iso8601">
+                       <xsl:value-of select="."/>
+               </mads:recordChangeDate>
+       </xsl:template>
+
+       <xsl:template match="marc:controlfield[@tag=008]">
+               <mads:recordCreationDate encoding="marc">
+                       <xsl:value-of select="substring(.,1,6)"/>
+               </mads:recordCreationDate>
+       </xsl:template>
+
+       <xsl:template match="marc:datafield[@tag=010]">
+               <xsl:for-each select="marc:subfield">
+                       <mads:identifier type="lccn">
+                               <xsl:call-template name="isInvalid"/>
+                               <xsl:value-of select="."/>
+                       </mads:identifier>
+               </xsl:for-each>
+       </xsl:template>
+
+       <xsl:template match="marc:datafield[@tag=024]">
+               <xsl:for-each select="marc:subfield[not(@code=2)]">
+                       <mads:identifier>
+                               <xsl:call-template name="isInvalid"/>
+                               <xsl:call-template name="sub2Attribute"/>
+                               <xsl:value-of select="."/>
+                       </mads:identifier>
+               </xsl:for-each>
+       </xsl:template>
+
+       <!-- ========== 372 ========== -->
+       <xsl:template match="marc:datafield[@tag=372]">
+               <mads:fieldOfActivity>
+                       <xsl:call-template name="subfieldSelect">
+                               <xsl:with-param name="codes">a</xsl:with-param>
+                       </xsl:call-template>
+                       <xsl:text>-</xsl:text>
+                       <xsl:call-template name="subfieldSelect">
+                               <xsl:with-param name="codes">st</xsl:with-param>
+                       </xsl:call-template>
+               </mads:fieldOfActivity>
+       </xsl:template>
+
+
+       <!-- ========== 040 ========== -->
+       <xsl:template match="marc:datafield[@tag=040]/marc:subfield[@code='a']">
+               <mads:recordContentSource authority="marcorg">
+                       <xsl:value-of select="."/>
+               </mads:recordContentSource>
+       </xsl:template>
+
+       <xsl:template match="marc:datafield[@tag=040]/marc:subfield[@code='b']">
+               <mads:languageOfCataloging>
+                       <mads:languageTerm authority="iso639-2b" type="code">
+                               <xsl:value-of select="."/>
+                       </mads:languageTerm>
+               </mads:languageOfCataloging>
+       </xsl:template>
+
+       <xsl:template match="marc:datafield[@tag=040]/marc:subfield[@code='e']">
+               <mads:descriptionStandard>
+                       <xsl:value-of select="."/>
+               </mads:descriptionStandard>
+       </xsl:template>
+       
+       <!-- ========== classification 2.03 ========== -->
+       
+       <xsl:template match="marc:datafield[@tag=053]">
+               <mads:classification>
+                       <xsl:call-template name="subfieldSelect">
+                               <xsl:with-param name="codes">abcdxyz</xsl:with-param>
+                               <xsl:with-param name="delimeter">-</xsl:with-param>
+                       </xsl:call-template>
+               </mads:classification>
+       </xsl:template>
+       
+       <xsl:template match="marc:datafield[@tag=055]">
+               <mads:classification>
+                       <xsl:call-template name="subfieldSelect">
+                               <xsl:with-param name="codes">abcdxyz</xsl:with-param>
+                               <xsl:with-param name="delimeter">-</xsl:with-param>
+                       </xsl:call-template>
+               </mads:classification>
+       </xsl:template>
+       
+       <xsl:template match="marc:datafield[@tag=060]">
+               <mads:classification>
+                       <xsl:call-template name="subfieldSelect">
+                               <xsl:with-param name="codes">abcdxyz</xsl:with-param>
+                               <xsl:with-param name="delimeter">-</xsl:with-param>
+                       </xsl:call-template>
+               </mads:classification>
+       </xsl:template>
+       <xsl:template match="marc:datafield[@tag=065]">
+               <mads:classification>
+                       <xsl:attribute name="authority">
+                               <xsl:value-of select="marc:subfield[@code='2']"/>
+                       </xsl:attribute>
+                       <xsl:call-template name="subfieldSelect">
+                               <xsl:with-param name="codes">abcdxyz</xsl:with-param>
+                               <xsl:with-param name="delimeter">-</xsl:with-param>
+                       </xsl:call-template>
+               </mads:classification>
+       </xsl:template>
+       <xsl:template match="marc:datafield[@tag=070]">
+               <mads:classification>
+                       <xsl:call-template name="subfieldSelect">
+                               <xsl:with-param name="codes">abcdxyz5</xsl:with-param>
+                               <xsl:with-param name="delimeter">-</xsl:with-param>
+                       </xsl:call-template>
+               </mads:classification>
+       </xsl:template>
+       <xsl:template match="marc:datafield[@tag=080]">
+               <mads:classification>
+                       <xsl:attribute name="authority">
+                               <xsl:value-of select="marc:subfield[@code='2']"/>
+                       </xsl:attribute>
+                       <xsl:call-template name="subfieldSelect">
+                               <xsl:with-param name="codes">abcdxyz5</xsl:with-param>
+                               <xsl:with-param name="delimeter">-</xsl:with-param>
+                       </xsl:call-template>
+               </mads:classification>
+       </xsl:template>
+       <xsl:template match="marc:datafield[@tag=082]">
+               <mads:classification>
+                       <xsl:attribute name="authority">
+                               <xsl:value-of select="marc:subfield[@code='2']"/>
+                       </xsl:attribute>
+                       <xsl:call-template name="subfieldSelect">
+                               <xsl:with-param name="codes">abcdxyz5</xsl:with-param>
+                               <xsl:with-param name="delimeter">-</xsl:with-param>
+                       </xsl:call-template>
+               </mads:classification>
+       </xsl:template>
+       <xsl:template match="marc:datafield[@tag=083]">
+               <mads:classification>
+                       <xsl:attribute name="authority">
+                               <xsl:value-of select="marc:subfield[@code='2']"/>
+                       </xsl:attribute>
+                       <xsl:call-template name="subfieldSelect">
+                               <xsl:with-param name="codes">abcdxyz5</xsl:with-param>
+                               <xsl:with-param name="delimeter">-</xsl:with-param>
+                       </xsl:call-template>
+               </mads:classification>
+       </xsl:template>
+       <xsl:template match="marc:datafield[@tag=086]">
+               <mads:classification>
+                       <xsl:attribute name="authority">
+                               <xsl:value-of select="marc:subfield[@code='2']"/>
+                       </xsl:attribute>
+                       <xsl:call-template name="subfieldSelect">
+                               <xsl:with-param name="codes">abcdxyz5</xsl:with-param>
+                               <xsl:with-param name="delimeter">-</xsl:with-param>
+                       </xsl:call-template>
+               </mads:classification>
+       </xsl:template>
+       <xsl:template match="marc:datafield[@tag=087]">
+               <mads:classification>
+                       <xsl:attribute name="authority">
+                               <xsl:value-of select="marc:subfield[@code='2']"/>
+                       </xsl:attribute>
+                       <xsl:call-template name="subfieldSelect">
+                               <xsl:with-param name="codes">abcdxyz5</xsl:with-param>
+                               <xsl:with-param name="delimeter">-</xsl:with-param>
+                       </xsl:call-template>
+               </mads:classification>
+       </xsl:template>
+       
+
+       <!-- ========== names  ========== -->
+       <xsl:template match="marc:datafield[@tag=100]">
+               <mads:name type="personal">
+                       <xsl:call-template name="setAuthority"/>
+                       <xsl:call-template name="nameABCDQ"/>
+               </mads:name>
+               <xsl:apply-templates select="*[marc:subfield[not(contains('abcdeq',@code))]]"/>
+               <xsl:call-template name="title"/>
+               <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+       </xsl:template>
+
+       <xsl:template match="marc:datafield[@tag=110]">
+               <mads:name type="corporate">
+                       <xsl:call-template name="setAuthority"/>
+                       <xsl:call-template name="nameABCDN"/>
+               </mads:name>
+               <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+       </xsl:template>
+
+       <xsl:template match="marc:datafield[@tag=111]">
+               <mads:name type="conference">
+                       <xsl:call-template name="setAuthority"/>
+                       <xsl:call-template name="nameACDENQ"/>
+               </mads:name>
+               <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+       </xsl:template>
+
+       <xsl:template match="marc:datafield[@tag=400]">
+               <mads:variant>
+                       <xsl:call-template name="variantTypeAttribute"/>
+                       <mads:name type="personal">
+                               <xsl:call-template name="nameABCDQ"/>
+                       </mads:name>
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+                       <xsl:call-template name="title"/>
+               </mads:variant>
+       </xsl:template>
+
+       <xsl:template match="marc:datafield[@tag=410]">
+               <mads:variant>
+                       <xsl:call-template name="variantTypeAttribute"/>
+                       <mads:name type="corporate">
+                               <xsl:call-template name="nameABCDN"/>
+                       </mads:name>
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+               </mads:variant>
+       </xsl:template>
+
+       <xsl:template match="marc:datafield[@tag=411]">
+               <mads:variant>
+                       <xsl:call-template name="variantTypeAttribute"/>
+                       <mads:name type="conference">
+                               <xsl:call-template name="nameACDENQ"/>
+                       </mads:name>
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+               </mads:variant>
+       </xsl:template>
+
+       <xsl:template match="marc:datafield[@tag=500]|marc:datafield[@tag=700]">
+               <mads:related>
+                       <xsl:call-template name="relatedTypeAttribute"/>
+                       <!-- <xsl:call-template name="uri"/> -->
+                       <mads:name type="personal">
+                               <xsl:call-template name="setAuthority"/>
+                               <xsl:call-template name="nameABCDQ"/>
+                       </mads:name>
+                       <xsl:call-template name="title"/>
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+               </mads:related>
+       </xsl:template>
+
+       <xsl:template match="marc:datafield[@tag=510]|marc:datafield[@tag=710]">
+               <mads:related>
+                       <xsl:call-template name="relatedTypeAttribute"/>
+                       <!-- <xsl:call-template name="uri"/> -->
+                       <mads:name type="corporate">
+                               <xsl:call-template name="setAuthority"/>
+                               <xsl:call-template name="nameABCDN"/>
+                       </mads:name>
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+               </mads:related>
+       </xsl:template>
+
+       <xsl:template match="marc:datafield[@tag=511]|marc:datafield[@tag=711]">
+               <mads:related>
+                       <xsl:call-template name="relatedTypeAttribute"/>
+                       <!-- <xsl:call-template name="uri"/> -->
+                       <mads:name type="conference">
+                               <xsl:call-template name="setAuthority"/>
+                               <xsl:call-template name="nameACDENQ"/>
+                       </mads:name>
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+               </mads:related>
+       </xsl:template>
+
+       <!-- ========== titles  ========== -->
+       <xsl:template match="marc:datafield[@tag=130]">
+               <xsl:call-template name="uniform-title"/>
+               <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+       </xsl:template>
+
+       <xsl:template match="marc:datafield[@tag=430]">
+               <mads:variant>
+                       <xsl:call-template name="variantTypeAttribute"/>
+                       <xsl:call-template name="uniform-title"/>
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+               </mads:variant>
+       </xsl:template>
+
+       <xsl:template match="marc:datafield[@tag=530]|marc:datafield[@tag=730]">
+               <mads:related>
+                       <xsl:call-template name="relatedTypeAttribute"/>
+                       <xsl:call-template name="uniform-title"/>
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+               </mads:related>
+       </xsl:template>
+
+       <xsl:template name="title">
+               <xsl:variable name="hasTitle">
+                       <xsl:for-each select="marc:subfield">
+                               <xsl:if test="(contains('tfghklmors',@code) )">
+                                       <xsl:value-of select="@code"/>
+                               </xsl:if>
+                       </xsl:for-each>
+               </xsl:variable>
+               <xsl:if test="string-length($hasTitle) &gt; 0 ">
+                       <mads:titleInfo>
+                               <xsl:call-template name="setAuthority"/>
+                               <mads:title>
+                                       <xsl:variable name="str">
+                                               <xsl:for-each select="marc:subfield">
+                                                       <xsl:if test="(contains('atfghklmors',@code) )">
+                                                               <xsl:value-of select="text()"/>
+                                                               <xsl:text> </xsl:text>
+                                                       </xsl:if>
+                                               </xsl:for-each>
+                                       </xsl:variable>
+                                       <xsl:call-template name="chopPunctuation">
+                                               <xsl:with-param name="chopString">
+                                                       <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+                                               </xsl:with-param>
+                                       </xsl:call-template>
+                               </mads:title>
+                               <xsl:call-template name="part"/>
+                               <!-- <xsl:call-template name="uri"/> -->
+                       </mads:titleInfo>
+               </xsl:if>
+       </xsl:template>
+
+       <xsl:template name="uniform-title">
+               <xsl:variable name="hasTitle">
+                       <xsl:for-each select="marc:subfield">
+                               <xsl:if test="(contains('atfghklmors',@code) )">
+                                       <xsl:value-of select="@code"/>
+                               </xsl:if>
+                       </xsl:for-each>
+               </xsl:variable>
+               <xsl:if test="string-length($hasTitle) &gt; 0 ">
+                       <mads:titleInfo>
+                               <xsl:call-template name="setAuthority"/>
+                               <mads:title>
+                                       <xsl:variable name="str">
+                                               <xsl:for-each select="marc:subfield">
+                                                       <xsl:if test="(contains('adfghklmors',@code) )">
+                                                               <xsl:value-of select="text()"/>
+                                                               <xsl:text> </xsl:text>
+                                                       </xsl:if>
+                                               </xsl:for-each>
+                                       </xsl:variable>
+                                       <xsl:call-template name="chopPunctuation">
+                                               <xsl:with-param name="chopString">
+                                                       <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+                                               </xsl:with-param>
+                                       </xsl:call-template>
+                               </mads:title>
+                               <xsl:call-template name="part"/>
+                               <!-- <xsl:call-template name="uri"/> -->
+                       </mads:titleInfo>
+               </xsl:if>
+       </xsl:template>
+
+
+       <!-- ========== topics  ========== -->
+       <xsl:template match="marc:subfield[@code='x']">
+               <mads:topic>
+                       <xsl:call-template name="chopPunctuation">
+                               <xsl:with-param name="chopString">
+                                       <xsl:value-of select="."/>
+                               </xsl:with-param>
+                       </xsl:call-template>
+               </mads:topic>
+       </xsl:template>
+       
+       <!-- 2.06 fix -->
+       <xsl:template
+               match="marc:datafield[@tag=150][marc:subfield[@code='a' or @code='b']]|marc:datafield[@tag=180][marc:subfield[@code='x']]">
+               <xsl:call-template name="topic"/>
+               <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+       </xsl:template>
+       <xsl:template
+               match="marc:datafield[@tag=450][marc:subfield[@code='a' or @code='b']]|marc:datafield[@tag=480][marc:subfield[@code='x']]">
+               <mads:variant>
+                       <xsl:call-template name="variantTypeAttribute"/>
+                       <xsl:call-template name="topic"/>
+               </mads:variant>
+       </xsl:template>
+       <xsl:template
+               match="marc:datafield[@tag=550 or @tag=750][marc:subfield[@code='a' or @code='b']]">
+               <mads:related>
+                       <xsl:call-template name="relatedTypeAttribute"/>
+                       <!-- <xsl:call-template name="uri"/> -->
+                       <xsl:call-template name="topic"/>
+                       <xsl:apply-templates select="marc:subfield[@code='z']"/>
+               </mads:related>
+       </xsl:template>
+       <xsl:template name="topic">
+               <mads:topic>
+                       <xsl:call-template name="setAuthority"/>
+                       <!-- tmee2006 dedupe 550a
+                       <xsl:if test="@tag=550 or @tag=750">
+                               <xsl:call-template name="subfieldSelect">
+                                       <xsl:with-param name="codes">ab</xsl:with-param>
+                               </xsl:call-template>
+                       </xsl:if>       
+                       -->
+                       <xsl:choose>
+                               <xsl:when test="@tag=180 or @tag=480 or @tag=580 or @tag=780">
+                                       <xsl:call-template name="chopPunctuation">
+                                               <xsl:with-param name="chopString">
+                                                       <xsl:apply-templates select="marc:subfield[@code='x']"/>
+                                               </xsl:with-param>
+                                       </xsl:call-template>
+                               </xsl:when>
+                       </xsl:choose>
+                       <xsl:call-template name="chopPunctuation">
+                               <xsl:with-param name="chopString">
+                                       <xsl:choose>
+                                               <xsl:when test="@tag=180 or @tag=480 or @tag=580 or @tag=780">
+                                                       <xsl:apply-templates select="marc:subfield[@code='x']"/>
+                                               </xsl:when>
+                                               <xsl:otherwise>
+                                                       <xsl:call-template name="subfieldSelect">
+                                                               <xsl:with-param name="codes">ab</xsl:with-param>
+                                                       </xsl:call-template>
+                                               </xsl:otherwise>
+                                       </xsl:choose>
+                               </xsl:with-param>
+                       </xsl:call-template>
+               </mads:topic>
+       </xsl:template>
+
+       <!-- ========= temporals  ========== -->
+       <xsl:template match="marc:subfield[@code='y']">
+               <mads:temporal>
+                       <xsl:call-template name="chopPunctuation">
+                               <xsl:with-param name="chopString">
+                                       <xsl:value-of select="."/>
+                               </xsl:with-param>
+                       </xsl:call-template>
+               </mads:temporal>
+       </xsl:template>
+       <xsl:template
+               match="marc:datafield[@tag=148][marc:subfield[@code='a']]|marc:datafield[@tag=182 ][marc:subfield[@code='y']]">
+               <xsl:call-template name="temporal"/>
+       </xsl:template>
+       <xsl:template
+               match="marc:datafield[@tag=448][marc:subfield[@code='a']]|marc:datafield[@tag=482][marc:subfield[@code='y']]">
+               <mads:variant>
+                       <xsl:call-template name="variantTypeAttribute"/>
+                       <xsl:call-template name="temporal"/>
+               </mads:variant>
+       </xsl:template>
+       <xsl:template
+               match="marc:datafield[@tag=548 or @tag=748][marc:subfield[@code='a']]|marc:datafield[@tag=582 or @tag=782][marc:subfield[@code='y']]">
+               <mads:related>
+                       <xsl:call-template name="relatedTypeAttribute"/>
+                       <!-- <xsl:call-template name="uri"/> -->
+                       <xsl:call-template name="temporal"/>
+               </mads:related>
+       </xsl:template>
+       <xsl:template name="temporal">
+               <mads:temporal>
+                       <xsl:call-template name="setAuthority"/>
+                       <xsl:if test="@tag=548 or @tag=748">
+                               <xsl:value-of select="marc:subfield[@code='a']"/>
+                       </xsl:if>
+                       <xsl:call-template name="chopPunctuation">
+                               <xsl:with-param name="chopString">
+                                       <xsl:choose>
+                                               <xsl:when test="@tag=182 or @tag=482 or @tag=582 or @tag=782">
+                                                       <xsl:apply-templates select="marc:subfield[@code='y']"/>
+                                               </xsl:when>
+                                               <xsl:otherwise>
+                                                       <xsl:value-of select="marc:subfield[@code='a']"/>
+                                               </xsl:otherwise>
+                                       </xsl:choose>
+                               </xsl:with-param>
+                       </xsl:call-template>
+               </mads:temporal>
+               <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+       </xsl:template>
+
+       <!-- ========== genre  ========== -->
+       <xsl:template match="marc:subfield[@code='v']">
+               <mads:genre>
+                       <xsl:call-template name="chopPunctuation">
+                               <xsl:with-param name="chopString">
+                                       <xsl:value-of select="."/>
+                               </xsl:with-param>
+                       </xsl:call-template>
+               </mads:genre>
+       </xsl:template>
+       <xsl:template
+               match="marc:datafield[@tag=155][marc:subfield[@code='a']]|marc:datafield[@tag=185][marc:subfield[@code='v']]">
+               <xsl:call-template name="genre"/>
+       </xsl:template>
+       <xsl:template
+               match="marc:datafield[@tag=455][marc:subfield[@code='a']]|marc:datafield[@tag=485 ][marc:subfield[@code='v']]">
+               <mads:variant>
+                       <xsl:call-template name="variantTypeAttribute"/>
+                       <xsl:call-template name="genre"/>
+               </mads:variant>
+       </xsl:template>
+       <!--
+       <xsl:template match="marc:datafield[@tag=555]">
+               <mads:related>
+                       <xsl:call-template name="relatedTypeAttribute"/>
+                       <xsl:call-template name="uri"/>
+                       <xsl:call-template name="genre"/>
+               </mads:related>
+       </xsl:template>
+       -->
+       <xsl:template
+               match="marc:datafield[@tag=555 or @tag=755][marc:subfield[@code='a']]|marc:datafield[@tag=585][marc:subfield[@code='v']]">
+               <mads:related>
+                       <xsl:call-template name="relatedTypeAttribute"/>
+                       <xsl:call-template name="genre"/>
+               </mads:related>
+       </xsl:template>
+       <xsl:template name="genre">
+               <mads:genre>
+                       <xsl:if test="@tag=555">
+                               <xsl:value-of select="marc:subfield[@code='a']"/>
+                       </xsl:if>
+                       <xsl:call-template name="setAuthority"/>
+                       <xsl:call-template name="chopPunctuation">
+                               <xsl:with-param name="chopString">
+                                       <xsl:choose>
+                                               <!-- 2.07 fix -->
+                                               <xsl:when test="@tag='555'"/>
+                                               <xsl:when test="@tag=185 or @tag=485 or @tag=585">
+                                                       <xsl:apply-templates select="marc:subfield[@code='v']"/>
+                                               </xsl:when>
+                                               <xsl:otherwise>
+                                                       <xsl:value-of select="marc:subfield[@code='a']"/>
+                                               </xsl:otherwise>
+                                       </xsl:choose>
+                               </xsl:with-param>
+                       </xsl:call-template>
+               </mads:genre>
+               <xsl:apply-templates/>
+       </xsl:template>
+
+       <!-- ========= geographic  ========== -->
+       <xsl:template match="marc:subfield[@code='z']">
+               <mads:geographic>
+                       <xsl:call-template name="chopPunctuation">
+                               <xsl:with-param name="chopString">
+                                       <xsl:value-of select="."/>
+                               </xsl:with-param>
+                       </xsl:call-template>
+               </mads:geographic>
+       </xsl:template>
+       <xsl:template name="geographic">
+               <mads:geographic>
+                       <!-- 2.14 -->
+                       <xsl:call-template name="setAuthority"/>
+                       <!-- 2.13 -->
+                       <xsl:if test="@tag=151 or @tag=551">
+                               <xsl:value-of select="marc:subfield[@code='a']"/>
+                       </xsl:if>
+                       <xsl:call-template name="chopPunctuation">
+                               <xsl:with-param name="chopString">
+                                               <xsl:if test="@tag=181 or @tag=481 or @tag=581">
+                                                               <xsl:apply-templates select="marc:subfield[@code='z']"/>
+                                               </xsl:if>
+                                               <!-- 2.13
+                                                       <xsl:choose>
+                                               <xsl:when test="@tag=181 or @tag=481 or @tag=581">
+                                                       <xsl:apply-templates select="marc:subfield[@code='z']"/>
+                                               </xsl:when>
+                                       
+                                               <xsl:otherwise>
+                                                       <xsl:value-of select="marc:subfield[@code='a']"/>
+                                               </xsl:otherwise>
+                                               </xsl:choose>
+                                               -->
+                               </xsl:with-param>
+                       </xsl:call-template>
+               </mads:geographic>
+               <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+       </xsl:template>
+       <xsl:template
+               match="marc:datafield[@tag=151][marc:subfield[@code='a']]|marc:datafield[@tag=181][marc:subfield[@code='z']]">
+               <xsl:call-template name="geographic"/>
+       </xsl:template>
+       <xsl:template
+               match="marc:datafield[@tag=451][marc:subfield[@code='a']]|marc:datafield[@tag=481][marc:subfield[@code='z']]">
+               <mads:variant>
+                       <xsl:call-template name="variantTypeAttribute"/>
+                       <xsl:call-template name="geographic"/>
+               </mads:variant>
+       </xsl:template>
+       <xsl:template
+               match="marc:datafield[@tag=551]|marc:datafield[@tag=581][marc:subfield[@code='z']]">
+               <mads:related>
+                       <xsl:call-template name="relatedTypeAttribute"/>
+                       <!-- <xsl:call-template name="uri"/> -->
+                       <xsl:call-template name="geographic"/>
+               </mads:related>
+       </xsl:template>
+       <xsl:template match="marc:datafield[@tag=580]">
+               <mads:related>
+                       <xsl:call-template name="relatedTypeAttribute"/>
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+               </mads:related>
+       </xsl:template>
+       <xsl:template
+               match="marc:datafield[@tag=751][marc:subfield[@code='z']]|marc:datafield[@tag=781][marc:subfield[@code='z']]">
+               <mads:related>
+                       <xsl:call-template name="relatedTypeAttribute"/>
+                       <xsl:call-template name="geographic"/>
+               </mads:related>
+       </xsl:template>
+       <xsl:template match="marc:datafield[@tag=755]">
+               <mads:related>
+                       <xsl:call-template name="relatedTypeAttribute"/>
+                       <xsl:call-template name="genre"/>
+                       <xsl:call-template name="setAuthority"/>
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+               </mads:related>
+       </xsl:template>
+       <xsl:template match="marc:datafield[@tag=780]">
+               <mads:related>
+                       <xsl:call-template name="relatedTypeAttribute"/>
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+               </mads:related>
+       </xsl:template>
+       <xsl:template match="marc:datafield[@tag=785]">
+               <mads:related>
+                       <xsl:call-template name="relatedTypeAttribute"/>
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+               </mads:related>
+       </xsl:template>
+
+       <!-- ========== notes  ========== -->
+       <xsl:template match="marc:datafield[667 &lt;= @tag and @tag &lt;= 688]">
+               <mads:note>
+                       <xsl:choose>
+                               <xsl:when test="@tag=667">
+                                       <xsl:attribute name="type">nonpublic</xsl:attribute>
+                               </xsl:when>
+                               <xsl:when test="@tag=670">
+                                       <xsl:attribute name="type">source</xsl:attribute>
+                               </xsl:when>
+                               <xsl:when test="@tag=675">
+                                       <xsl:attribute name="type">notFound</xsl:attribute>
+                               </xsl:when>
+                               <xsl:when test="@tag=678">
+                                       <xsl:attribute name="type">history</xsl:attribute>
+                               </xsl:when>
+                               <xsl:when test="@tag=681">
+                                       <xsl:attribute name="type">subject example</xsl:attribute>
+                               </xsl:when>
+                               <xsl:when test="@tag=682">
+                                       <xsl:attribute name="type">deleted heading information</xsl:attribute>
+                               </xsl:when>
+                               <xsl:when test="@tag=688">
+                                       <xsl:attribute name="type">application history</xsl:attribute>
+                               </xsl:when>
+                       </xsl:choose>
+                       <xsl:call-template name="chopPunctuation">
+                               <xsl:with-param name="chopString">
+                                       <xsl:choose>
+                                               <xsl:when test="@tag=667 or @tag=675">
+                                                       <xsl:value-of select="marc:subfield[@code='a']"/>
+                                               </xsl:when>
+                                               <xsl:when test="@tag=670 or @tag=678">
+                                                       <xsl:call-template name="subfieldSelect">
+                                                               <xsl:with-param name="codes">ab</xsl:with-param>
+                                                       </xsl:call-template>
+                                               </xsl:when>
+                                               <xsl:when test="680 &lt;= @tag and @tag &lt;=688">
+                                                       <xsl:call-template name="subfieldSelect">
+                                                               <xsl:with-param name="codes">ai</xsl:with-param>
+                                                       </xsl:call-template>
+                                               </xsl:when>
+                                       </xsl:choose>
+                               </xsl:with-param>
+                       </xsl:call-template>
+               </mads:note>
+       </xsl:template>
+
+       <!-- ========== url  ========== -->
+       <xsl:template match="marc:datafield[@tag=856][marc:subfield[@code='u']]">
+               <mads:url>
+                       <xsl:if test="marc:subfield[@code='z' or @code='3']">
+                               <xsl:attribute name="displayLabel">
+                                       <xsl:call-template name="subfieldSelect">
+                                               <xsl:with-param name="codes">z3</xsl:with-param>
+                                       </xsl:call-template>
+                               </xsl:attribute>
+                       </xsl:if>
+                       <xsl:value-of select="marc:subfield[@code='u']"/>
+               </mads:url>
+       </xsl:template>
+
+       <xsl:template name="relatedTypeAttribute">
+               <xsl:choose>
+                       <xsl:when
+                               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">
+                               <xsl:if test="substring(marc:subfield[@code='w'],1,1)='a'">
+                                       <xsl:attribute name="type">earlier</xsl:attribute>
+                               </xsl:if>
+                               <xsl:if test="substring(marc:subfield[@code='w'],1,1)='b'">
+                                       <xsl:attribute name="type">later</xsl:attribute>
+                               </xsl:if>
+                               <xsl:if test="substring(marc:subfield[@code='w'],1,1)='t'">
+                                       <xsl:attribute name="type">parentOrg</xsl:attribute>
+                               </xsl:if>
+                               <xsl:if test="substring(marc:subfield[@code='w'],1,1)='g'">
+                                       <xsl:attribute name="type">broader</xsl:attribute>
+                               </xsl:if>
+                               <xsl:if test="substring(marc:subfield[@code='w'],1,1)='h'">
+                                       <xsl:attribute name="type">narrower</xsl:attribute>
+                               </xsl:if>
+                               <xsl:if test="substring(marc:subfield[@code='w'],1,1)='r'">
+                                       <xsl:attribute name="type">other</xsl:attribute>
+                               </xsl:if>
+                               <xsl:if test="contains('fin|', substring(marc:subfield[@code='w'],1,1))">
+                                       <xsl:attribute name="type">other</xsl:attribute>
+                               </xsl:if>
+                       </xsl:when>
+                       <xsl:when test="@tag=530 or @tag=730">
+                               <xsl:attribute name="type">other</xsl:attribute>
+                       </xsl:when>
+                       <xsl:otherwise>
+                               <!-- 7xx -->
+                               <xsl:attribute name="type">equivalent</xsl:attribute>
+                       </xsl:otherwise>
+               </xsl:choose>
+               <xsl:apply-templates select="marc:subfield[@code='i']"/>
+       </xsl:template>
+       
+
+
+       <xsl:template name="variantTypeAttribute">
+               <xsl:choose>
+                       <xsl:when
+                               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">
+                               <xsl:if test="substring(marc:subfield[@code='w'],1,1)='d'">
+                                       <xsl:attribute name="type">acronym</xsl:attribute>
+                               </xsl:if>
+                               <xsl:if test="substring(marc:subfield[@code='w'],1,1)='n'">
+                                       <xsl:attribute name="type">other</xsl:attribute>
+                               </xsl:if>
+                               <xsl:if test="contains('fit', substring(marc:subfield[@code='w'],1,1))">
+                                       <xsl:attribute name="type">other</xsl:attribute>
+                               </xsl:if>
+                       </xsl:when>
+                       <xsl:otherwise>
+                               <!-- 430  -->
+                               <xsl:attribute name="type">other</xsl:attribute>
+                       </xsl:otherwise>
+               </xsl:choose>
+               <xsl:apply-templates select="marc:subfield[@code='i']"/>
+       </xsl:template>
+
+       <xsl:template name="setAuthority">
+               <xsl:choose>
+                       <!-- can be called from the datafield or subfield level, so "..//@tag" means
+                       the tag can be at the subfield's parent level or at the datafields own level -->
+
+                       <xsl:when
+                               test="ancestor-or-self::marc:datafield/@tag=100 and (@ind1=0 or @ind1=1) and $controlField008-11='a' and $controlField008-14='a'">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>naf</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="ancestor-or-self::marc:datafield/@tag=100 and (@ind1=0 or @ind1=1) and $controlField008-11='a' and $controlField008-14='b'">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>lcsh</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="ancestor-or-self::marc:datafield/@tag=100 and (@ind1=0 or @ind1=1) and $controlField008-11='k'">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>lacnaf</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="ancestor-or-self::marc:datafield/@tag=100 and @ind1=3 and $controlField008-11='a' and $controlField008-14='b'">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>lcsh</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="ancestor-or-self::marc:datafield/@tag=100 and @ind1=3 and $controlField008-11='k' and $controlField008-14='b'">
+                               <xsl:attribute name="authority">cash</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="ancestor-or-self::marc:datafield/@tag=110 and $controlField008-11='a' and $controlField008-14='a'">
+                               <xsl:attribute name="authority">naf</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="ancestor-or-self::marc:datafield/@tag=110 and $controlField008-11='a' and $controlField008-14='b'">
+                               <xsl:attribute name="authority">lcsh</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="ancestor-or-self::marc:datafield/@tag=110 and $controlField008-11='k' and $controlField008-14='a'">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>lacnaf</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="ancestor-or-self::marc:datafield/@tag=110 and $controlField008-11='k' and $controlField008-14='b'">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>cash</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="100 &lt;= ancestor-or-self::marc:datafield/@tag and ancestor-or-self::marc:datafield/@tag &lt;= 155 and $controlField008-11='b'">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>lcshcl</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               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'">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>nlmnaf</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               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'">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>nalnaf</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="100 &lt;= ancestor-or-self::marc:datafield/@tag and ancestor-or-self::marc:datafield/@tag &lt;= 155 and $controlField008-11='r'">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>aat</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="100 &lt;= ancestor-or-self::marc:datafield/@tag and ancestor-or-self::marc:datafield/@tag &lt;= 155 and $controlField008-11='s'">
+                               <xsl:attribute name="authority">sears</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="100 &lt;= ancestor-or-self::marc:datafield/@tag and ancestor-or-self::marc:datafield/@tag &lt;= 155 and $controlField008-11='v'">
+                               <xsl:attribute name="authority">rvm</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="100 &lt;= ancestor-or-self::marc:datafield/@tag and ancestor-or-self::marc:datafield/@tag &lt;= 155 and $controlField008-11='z'">
+                               <xsl:attribute name="authority">
+                                       <xsl:value-of
+                                               select="../marc:datafield[ancestor-or-self::marc:datafield/@tag=040]/marc:subfield[@code='f']"
+                                       />
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="(ancestor-or-self::marc:datafield/@tag=111 or ancestor-or-self::marc:datafield/@tag=130) and $controlField008-11='a' and $controlField008-14='a'">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>naf</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="(ancestor-or-self::marc:datafield/@tag=111 or ancestor-or-self::marc:datafield/@tag=130) and $controlField008-11='a' and $controlField008-14='b'">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>lcsh</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="(ancestor-or-self::marc:datafield/@tag=111 or ancestor-or-self::marc:datafield/@tag=130) and $controlField008-11='k' ">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>lacnaf</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               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' ">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>lcsh</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               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' ">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>lcsh</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               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' ">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>mesh</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               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' ">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>nal</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               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' ">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>cash</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="ancestor-or-self::marc:datafield/@tag=151 and $controlField008-11='a' and $controlField008-14='a'">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>naf</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="ancestor-or-self::marc:datafield/@tag=151 and $controlField008-11='a' and $controlField008-14='b'">
+                               <xsl:attribute name="authority">lcsh</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="ancestor-or-self::marc:datafield/@tag=151 and $controlField008-11='k' and $controlField008-14='a'">
+                               <xsl:attribute name="authority">lacnaf</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="ancestor-or-self::marc:datafield/@tag=151 and $controlField008-11='k' and $controlField008-14='b'">
+                               <xsl:attribute name="authority">cash</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               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'">
+                               <xsl:attribute name="authority">lcsh</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="ancestor-or-self::marc:datafield/@tag=700 and (@ind1='0' or @ind1='1') and @ind2='0'">
+                               <xsl:attribute name="authority">naf</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="ancestor-or-self::marc:datafield/@tag=700 and (@ind1='0' or @ind1='1') and @ind2='5'">
+                               <xsl:attribute name="authority">lacnaf</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when test="ancestor-or-self::marc:datafield/@tag=700 and @ind1='3' and @ind2='0'">
+                               <xsl:attribute name="authority">lcsh</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when test="ancestor-or-self::marc:datafield/@tag=700 and @ind1='3' and @ind2='5'">
+                               <xsl:attribute name="authority">cash</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="(700 &lt;= ancestor-or-self::marc:datafield/@tag and ancestor-or-self::marc:datafield/@tag &lt;= 755 ) and @ind2='1'">
+                               <xsl:attribute name="authority">lcshcl</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               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'">
+                               <xsl:attribute name="authority">nlmnaf</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               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'">
+                               <xsl:attribute name="authority">nalnaf</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="(700 &lt;= ancestor-or-self::marc:datafield/@tag and ancestor-or-self::marc:datafield/@tag &lt;= 755 ) and @ind2='6'">
+                               <xsl:attribute name="authority">rvm</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="(700 &lt;= ancestor-or-self::marc:datafield/@tag and ancestor-or-self::marc:datafield/@tag &lt;= 755 ) and @ind2='7'">
+                               <xsl:attribute name="authority">
+                                       <xsl:value-of select="marc:subfield[@code='2']"/>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               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'">
+                               <xsl:attribute name="authority">lacnaf</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               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'">
+                               <xsl:attribute name="authority">naf</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               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'">
+                               <xsl:attribute name="authority">lcsh</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               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'">
+                               <xsl:attribute name="authority">mesh</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               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'">
+                               <xsl:attribute name="authority">nal</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               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'">
+                               <xsl:attribute name="authority">cash</xsl:attribute>
+                       </xsl:when>
+               </xsl:choose>
+       </xsl:template>
+       <xsl:template match="*"/>
+</xsl:stylesheet>$XSLT$);
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.MADS21-xsl.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.MADS21-xsl.sql
new file mode 100644 (file)
index 0000000..225be32
--- /dev/null
@@ -0,0 +1,1624 @@
+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"?>
+<xsl:stylesheet version="1.0" xmlns:mads="http://www.loc.gov/mads/v2"
+       xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:marc="http://www.loc.gov/MARC21/slim"
+       xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="marc">
+       <xsl:output method="xml" indent="yes" encoding="UTF-8"/>
+       <xsl:strip-space elements="*"/>
+
+       <xsl:variable name="ascii">
+               <xsl:text> !"#$%&amp;'()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~</xsl:text>
+       </xsl:variable>
+
+       <xsl:variable name="latin1">
+               <xsl:text> ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ</xsl:text>
+       </xsl:variable>
+       <!-- Characters that usually don't need to be escaped -->
+       <xsl:variable name="safe">
+               <xsl:text>!'()*-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~</xsl:text>
+       </xsl:variable>
+
+       <xsl:variable name="hex">0123456789ABCDEF</xsl:variable>
+
+
+       <xsl:template name="datafield">
+               <xsl:param name="tag"/>
+               <xsl:param name="ind1">
+                       <xsl:text> </xsl:text>
+               </xsl:param>
+               <xsl:param name="ind2">
+                       <xsl:text> </xsl:text>
+               </xsl:param>
+               <xsl:param name="subfields"/>
+               <xsl:element name="marc:datafield">
+                       <xsl:attribute name="tag">
+                               <xsl:value-of select="$tag"/>
+                       </xsl:attribute>
+                       <xsl:attribute name="ind1">
+                               <xsl:value-of select="$ind1"/>
+                       </xsl:attribute>
+                       <xsl:attribute name="ind2">
+                               <xsl:value-of select="$ind2"/>
+                       </xsl:attribute>
+                       <xsl:copy-of select="$subfields"/>
+               </xsl:element>
+       </xsl:template>
+
+       <xsl:template name="subfieldSelect">
+               <xsl:param name="codes">abcdefghijklmnopqrstuvwxyz</xsl:param>
+               <xsl:param name="delimeter">
+                       <xsl:text> </xsl:text>
+               </xsl:param>
+               <xsl:variable name="str">
+                       <xsl:for-each select="marc:subfield">
+                               <xsl:if test="contains($codes, @code)">
+                                       <xsl:value-of select="text()"/>
+                                       <xsl:value-of select="$delimeter"/>
+                               </xsl:if>
+                       </xsl:for-each>
+               </xsl:variable>
+               <xsl:value-of select="substring($str,1,string-length($str)-string-length($delimeter))"/>
+       </xsl:template>
+
+       <xsl:template name="buildSpaces">
+               <xsl:param name="spaces"/>
+               <xsl:param name="char">
+                       <xsl:text> </xsl:text>
+               </xsl:param>
+               <xsl:if test="$spaces>0">
+                       <xsl:value-of select="$char"/>
+                       <xsl:call-template name="buildSpaces">
+                               <xsl:with-param name="spaces" select="$spaces - 1"/>
+                               <xsl:with-param name="char" select="$char"/>
+                       </xsl:call-template>
+               </xsl:if>
+       </xsl:template>
+
+       <xsl:template name="chopPunctuation">
+               <xsl:param name="chopString"/>
+               <xsl:param name="punctuation">
+                       <xsl:text>.:,;/ </xsl:text>
+               </xsl:param>
+               <xsl:variable name="length" select="string-length($chopString)"/>
+               <xsl:choose>
+                       <xsl:when test="$length=0"/>
+                       <xsl:when test="contains($punctuation, substring($chopString,$length,1))">
+                               <xsl:call-template name="chopPunctuation">
+                                       <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
+                                       <xsl:with-param name="punctuation" select="$punctuation"/>
+                               </xsl:call-template>
+                       </xsl:when>
+                       <xsl:when test="not($chopString)"/>
+                       <xsl:otherwise>
+                               <xsl:value-of select="$chopString"/>
+                       </xsl:otherwise>
+               </xsl:choose>
+       </xsl:template>
+
+       <xsl:template name="chopPunctuationFront">
+               <xsl:param name="chopString"/>
+               <xsl:variable name="length" select="string-length($chopString)"/>
+               <xsl:choose>
+                       <xsl:when test="$length=0"/>
+                       <xsl:when test="contains('.:,;/[ ', substring($chopString,1,1))">
+                               <xsl:call-template name="chopPunctuationFront">
+                                       <xsl:with-param name="chopString" select="substring($chopString,2,$length - 1)"
+                                       />
+                               </xsl:call-template>
+                       </xsl:when>
+                       <xsl:when test="not($chopString)"/>
+                       <xsl:otherwise>
+                               <xsl:value-of select="$chopString"/>
+                       </xsl:otherwise>
+               </xsl:choose>
+       </xsl:template>
+
+       <xsl:template name="chopPunctuationBack">
+               <xsl:param name="chopString"/>
+               <xsl:param name="punctuation">
+                       <xsl:text>.:,;/] </xsl:text>
+               </xsl:param>
+               <xsl:variable name="length" select="string-length($chopString)"/>
+               <xsl:choose>
+                       <xsl:when test="$length=0"/>
+                       <xsl:when test="contains($punctuation, substring($chopString,$length,1))">
+                               <xsl:call-template name="chopPunctuation">
+                                       <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
+                                       <xsl:with-param name="punctuation" select="$punctuation"/>
+                               </xsl:call-template>
+                       </xsl:when>
+                       <xsl:when test="not($chopString)"/>
+                       <xsl:otherwise>
+                               <xsl:value-of select="$chopString"/>
+                       </xsl:otherwise>
+               </xsl:choose>
+       </xsl:template>
+
+       <!-- nate added 12/14/2007 for lccn.loc.gov: url encode ampersand, etc. -->
+       <xsl:template name="url-encode">
+
+               <xsl:param name="str"/>
+
+               <xsl:if test="$str">
+                       <xsl:variable name="first-char" select="substring($str,1,1)"/>
+                       <xsl:choose>
+                               <xsl:when test="contains($safe,$first-char)">
+                                       <xsl:value-of select="$first-char"/>
+                               </xsl:when>
+                               <xsl:otherwise>
+                                       <xsl:variable name="codepoint">
+                                               <xsl:choose>
+                                                       <xsl:when test="contains($ascii,$first-char)">
+                                                               <xsl:value-of
+                                                                       select="string-length(substring-before($ascii,$first-char)) + 32"
+                                                               />
+                                                       </xsl:when>
+                                                       <xsl:when test="contains($latin1,$first-char)">
+                                                               <xsl:value-of
+                                                                       select="string-length(substring-before($latin1,$first-char)) + 160"/>
+                                                               <!-- was 160 -->
+                                                       </xsl:when>
+                                                       <xsl:otherwise>
+                                                               <xsl:message terminate="no">Warning: string contains a character
+                                                                       that is out of range! Substituting "?".</xsl:message>
+                                                               <xsl:text>63</xsl:text>
+                                                       </xsl:otherwise>
+                                               </xsl:choose>
+                                       </xsl:variable>
+                                       <xsl:variable name="hex-digit1"
+                                               select="substring($hex,floor($codepoint div 16) + 1,1)"/>
+                                       <xsl:variable name="hex-digit2" select="substring($hex,$codepoint mod 16 + 1,1)"/>
+                                       <!-- <xsl:value-of select="concat('%',$hex-digit2)"/> -->
+                                       <xsl:value-of select="concat('%',$hex-digit1,$hex-digit2)"/>
+                               </xsl:otherwise>
+                       </xsl:choose>
+                       <xsl:if test="string-length($str) &gt; 1">
+                               <xsl:call-template name="url-encode">
+                                       <xsl:with-param name="str" select="substring($str,2)"/>
+                               </xsl:call-template>
+                       </xsl:if>
+               </xsl:if>
+       </xsl:template>
+
+
+<!--
+2.14    Fixed bug in mads:geographic attributes syntax                                      ws   05/04/2016            
+2.13   fixed repeating <geographic>                                                                                                            tmee 01/31/2014
+2.12   added $2 authority for <classification>                                                                                         tmee 09/18/2012
+2.11   added delimiters between <classification> subfields                                                                     tmee 09/18/2012
+2.10   fixed type="other" and type="otherType" for mads:related                                                        tmee 09/16/2011
+2.09   fixed professionTerm and genreTerm empty tag error                                                                      tmee 09/16/2011
+2.08   fixed marc:subfield @code='i' matching error                                                                            tmee 09/16/2011
+2.07   fixed 555 duplication error                                                                                                                     tmee 08/10/2011 
+2.06   fixed topic subfield error                                                                                                                      tmee 08/10/2011 
+2.05   fixed title subfield error                                                                                                                      tmee 06/20/2011 
+2.04   fixed geographicSubdivision mapping for authority element                                                       tmee 06/16/2011
+2.03   added classification for 053, 055, 060, 065, 070, 080, 082, 083, 086, 087                       tmee 06/03/2011         
+2.02   added descriptionStandard for 008/10                                                                                            tmee 04/27/2011
+2.01   added extensions for 046, 336, 370, 374, 375, 376                                                                       tmee 04/08/2011
+2.00   redefined imported MODS elements in version 1.0 to MADS elements in version 2.0         tmee 02/08/2011
+1.08   added 372 subfields $a $s $t for <fieldOfActivity>                                                                      tmee 06/24/2010
+1.07   removed role/roleTerm 100, 110, 111, 400, 410, 411, 500, 510, 511, 700, 710, 711        tmee 06/24/2010
+1.06   added strip-space                                                                                                                                       tmee 06/24/2010
+1.05   added subfield $a for 130, 430, 530                                                                                                     tmee 06/21/2010
+1.04   fixed 550 z omission                                                                                                                            ntra 08/11/2008
+1.03   removed duplication of 550 $a text                                                                                                      tmee 11/01/2006
+1.02   fixed namespace references between mads and mods                                                                        ntra 10/06/2006
+1.01   revised                                                                                                                                                         rgue/jrad 11/29/05
+1.00   adapted from MARC21Slim2MODS3.xsl                                                                                                       ntra 07/06/05
+-->
+
+       <!-- authority attribute defaults to 'naf' if not set using this authority parameter, for <authority> descriptors: name, titleInfo, geographic -->
+       <xsl:param name="authority"/>
+       <xsl:variable name="auth">
+               <xsl:choose>
+                       <xsl:when test="$authority">
+                               <xsl:value-of select="$authority"/>
+                       </xsl:when>
+                       <xsl:otherwise>naf</xsl:otherwise>
+               </xsl:choose>
+       </xsl:variable>
+       <xsl:variable name="controlField008" select="marc:controlfield[@tag='008']"/>
+       <xsl:variable name="controlField008-06"
+               select="substring(descendant-or-self::marc:controlfield[@tag=008],7,1)"/>
+       <xsl:variable name="controlField008-11"
+               select="substring(descendant-or-self::marc:controlfield[@tag=008],12,1)"/>
+       <xsl:variable name="controlField008-14"
+               select="substring(descendant-or-self::marc:controlfield[@tag=008],15,1)"/>
+       <xsl:template match="/">
+               <xsl:choose>
+                       <xsl:when test="descendant-or-self::marc:collection">
+                               <mads:madsCollection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+                                       xsi:schemaLocation="http://www.loc.gov/mads/v2 http://www.loc.gov/standards/mads/v2/mads-2-0.xsd">
+                                       <xsl:for-each select="descendant-or-self::marc:collection/marc:record">
+                                               <mads:mads version="2.0">
+                                                       <xsl:call-template name="marcRecord"/>
+                                               </mads:mads>
+                                       </xsl:for-each>
+                               </mads:madsCollection>
+                       </xsl:when>
+                       <xsl:otherwise>
+                               <mads:mads version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+                                       xsi:schemaLocation="http://www.loc.gov/mads/v2 http://www.loc.gov/standards/mads/mads-2-0.xsd">
+                                       <xsl:for-each select="descendant-or-self::marc:record">
+                                               <xsl:call-template name="marcRecord"/>
+                                       </xsl:for-each>
+                               </mads:mads>
+                       </xsl:otherwise>
+               </xsl:choose>
+       </xsl:template>
+
+       <xsl:template name="marcRecord">
+               <mads:authority>
+                       <!-- 2.04 -->
+                       <xsl:choose>
+                               <xsl:when test="$controlField008-06='d'">
+                                       <xsl:attribute name="geographicSubdivision">
+                                               <xsl:text>direct</xsl:text>
+                                       </xsl:attribute>
+                               </xsl:when>
+                               <xsl:when test="$controlField008-06='i'">
+                                       <xsl:attribute name="geographicSubdivision">
+                                               <xsl:text>indirect</xsl:text>
+                                       </xsl:attribute>
+                               </xsl:when>
+                               <xsl:when test="$controlField008-06='n'">
+                                       <xsl:attribute name="geographicSubdivision">
+                                               <xsl:text>not applicable</xsl:text>
+                                       </xsl:attribute>
+                               </xsl:when>
+                       </xsl:choose>
+                       
+                       <xsl:apply-templates select="marc:datafield[100 &lt;= @tag  and @tag &lt; 200]"/>               
+               </mads:authority>
+
+               <!-- related -->
+               <xsl:apply-templates
+                       select="marc:datafield[500 &lt;= @tag and @tag &lt;= 585]|marc:datafield[700 &lt;= @tag and @tag &lt;= 785]"/>
+
+               <!-- variant -->
+               <xsl:apply-templates select="marc:datafield[400 &lt;= @tag and @tag &lt;= 485]"/>
+
+               <!-- notes -->
+               <xsl:apply-templates select="marc:datafield[667 &lt;= @tag and @tag &lt;= 688]"/>
+
+               <!-- url -->
+               <xsl:apply-templates select="marc:datafield[@tag=856]"/>
+               <xsl:apply-templates select="marc:datafield[@tag=010]"/>
+               <xsl:apply-templates select="marc:datafield[@tag=024]"/>
+               <xsl:apply-templates select="marc:datafield[@tag=372]"/>
+               
+               <!-- classification -->
+               <xsl:apply-templates select="marc:datafield[@tag=053]"/>
+               <xsl:apply-templates select="marc:datafield[@tag=055]"/>
+               <xsl:apply-templates select="marc:datafield[@tag=060]"/>
+               <xsl:apply-templates select="marc:datafield[@tag=065]"/>
+               <xsl:apply-templates select="marc:datafield[@tag=070]"/>
+               <xsl:apply-templates select="marc:datafield[@tag=080]"/>
+               <xsl:apply-templates select="marc:datafield[@tag=082]"/>
+               <xsl:apply-templates select="marc:datafield[@tag=083]"/>
+               <xsl:apply-templates select="marc:datafield[@tag=086]"/>
+               <xsl:apply-templates select="marc:datafield[@tag=087]"/>
+
+               <!-- affiliation-->
+               <xsl:for-each select="marc:datafield[@tag=373]">
+                       <mads:affiliation>
+                               <mads:position>
+                                       <xsl:value-of select="marc:subfield[@code='a']"/>
+                               </mads:position>
+                               <mads:dateValid point="start">
+                                       <xsl:value-of select="marc:subfield[@code='s']"/>
+                               </mads:dateValid>
+                               <mads:dateValid point="end">
+                                       <xsl:value-of select="marc:subfield[@code='t']"/>
+                               </mads:dateValid>
+                       </mads:affiliation>
+               </xsl:for-each>
+               <xsl:for-each select="marc:datafield[@tag=371]">
+                       <mads:affiliation>
+                               <mads:address>
+                                       <mads:street>
+                                               <xsl:value-of select="marc:subfield[@code='a']"/>
+                                       </mads:street>
+                                       <mads:city>
+                                               <xsl:value-of select="marc:subfield[@code='b']"/>
+                                       </mads:city>
+                                       <mads:state>
+                                               <xsl:value-of select="marc:subfield[@code='c']"/>
+                                       </mads:state>
+                                       <mads:country>
+                                               <xsl:value-of select="marc:subfield[@code='d']"/>
+                                       </mads:country>
+                                       <mads:postcode>
+                                               <xsl:value-of select="marc:subfield[@code='e']"/>
+                                       </mads:postcode>
+                               </mads:address>
+                               <mads:email>
+                                       <xsl:value-of select="marc:subfield[@code='m']"/>
+                               </mads:email>
+                       </mads:affiliation>
+               </xsl:for-each>
+
+               <!-- extension-->
+               <xsl:for-each select="marc:datafield[@tag=336]">
+                       <mads:extension>
+                               <mads:contentType>
+                                       <mads:contentType type="text">
+                                               <xsl:value-of select="marc:subfield[@code='a']"/>
+                                       </mads:contentType>
+                                       <mads:contentType type="code">
+                                               <xsl:value-of select="marc:subfield[@code='b']"/>
+                                       </mads:contentType>
+                               </mads:contentType>
+                       </mads:extension>
+               </xsl:for-each>
+
+               <xsl:for-each select="marc:datafield[@tag=374]">
+                       <mads:extension>
+                               <mads:profession>
+                                       <xsl:choose>
+                                               <xsl:when test="marc:subfield[@code='a']">
+                                                       <mads:professionTerm>
+                                                               <xsl:value-of select="marc:subfield[@code='a']"/>
+                                                       </mads:professionTerm>
+                                               </xsl:when>
+                                               <xsl:when test="marc:subfield[@code='s']">
+                                                       <mads:dateValid point="start">
+                                                               <xsl:value-of select="marc:subfield[@code='s']"/>
+                                                       </mads:dateValid>
+                                               </xsl:when>
+                                               <xsl:when test="marc:subfield[@code='t']">
+                                                       <mads:dateValid point="end">
+                                                               <xsl:value-of select="marc:subfield[@code='t']"/>
+                                                       </mads:dateValid>
+                                               </xsl:when>
+                                       </xsl:choose>
+                               </mads:profession>
+                       </mads:extension>
+               </xsl:for-each>
+               
+               <xsl:for-each select="marc:datafield[@tag=375]">
+                       <mads:extension>
+                               <mads:gender>
+                                       <xsl:choose>
+                                               <xsl:when test="marc:subfield[@code='a']">
+                                                       <mads:genderTerm>
+                                                               <xsl:value-of select="marc:subfield[@code='a']"/>
+                                                       </mads:genderTerm>
+                                               </xsl:when>
+                                               <xsl:when test="marc:subfield[@code='s']">
+                                                       <mads:dateValid point="start">
+                                                               <xsl:value-of select="marc:subfield[@code='s']"/>
+                                                       </mads:dateValid>
+                                               </xsl:when>
+                                               <xsl:when test="marc:subfield[@code='t']">
+                                                       <mads:dateValid point="end">
+                                                               <xsl:value-of select="marc:subfield[@code='t']"/>
+                                                       </mads:dateValid>
+                                               </xsl:when>
+                                       </xsl:choose>
+                               </mads:gender>
+                       </mads:extension>
+               </xsl:for-each>
+
+               <xsl:for-each select="marc:datafield[@tag=376]">
+                       <mads:extension>
+                               <mads:familyInformation>
+                                       <mads:typeOfFamily>
+                                               <xsl:value-of select="marc:subfield[@code='a']"/>
+                                       </mads:typeOfFamily>
+                                       <mads:nameOfProminentMember>
+                                               <xsl:value-of select="marc:subfield[@code='b']"/>
+                                       </mads:nameOfProminentMember>
+                                       <mads:hereditaryTitle>
+                                               <xsl:value-of select="marc:subfield[@code='c']"/>
+                                       </mads:hereditaryTitle>
+                                       <mads:dateValid point="start">
+                                               <xsl:value-of select="marc:subfield[@code='s']"/>
+                                       </mads:dateValid>
+                                       <mads:dateValid point="end">
+                                               <xsl:value-of select="marc:subfield[@code='t']"/>
+                                       </mads:dateValid>
+                               </mads:familyInformation>
+                       </mads:extension>
+               </xsl:for-each>
+
+               <mads:recordInfo>
+                       <mads:recordOrigin>Converted from MARCXML to MADS version 2.0 (Revision 2.13)</mads:recordOrigin>
+                       <!-- <xsl:apply-templates select="marc:datafield[@tag=024]"/> -->
+
+                       <xsl:apply-templates select="marc:datafield[@tag=040]/marc:subfield[@code='a']"/>
+                       <xsl:apply-templates select="marc:controlfield[@tag=005]"/>
+                       <xsl:apply-templates select="marc:controlfield[@tag=001]"/>
+                       <xsl:apply-templates select="marc:datafield[@tag=040]/marc:subfield[@code='b']"/>
+                       <xsl:apply-templates select="marc:datafield[@tag=040]/marc:subfield[@code='e']"/>
+                       <xsl:for-each select="marc:controlfield[@tag=008]">
+                               <xsl:if test="substring(.,11,1)='a'">
+                                       <mads:descriptionStandard>
+                                               <xsl:text>earlier rules</xsl:text>
+                                       </mads:descriptionStandard>
+                               </xsl:if>
+                               <xsl:if test="substring(.,11,1)='b'">
+                                       <mads:descriptionStandard>
+                                               <xsl:text>aacr1</xsl:text>
+                                       </mads:descriptionStandard>
+                               </xsl:if>
+                               <xsl:if test="substring(.,11,1)='c'">
+                                       <mads:descriptionStandard>
+                                               <xsl:text>aacr2</xsl:text>
+                                       </mads:descriptionStandard>
+                               </xsl:if>
+                               <xsl:if test="substring(.,11,1)='d'">
+                                       <mads:descriptionStandard>
+                                               <xsl:text>aacr2 compatible</xsl:text>
+                                       </mads:descriptionStandard>
+                               </xsl:if>
+                               <xsl:if test="substring(.,11,1)='z'">
+                                       <mads:descriptionStandard>
+                                               <xsl:text>other rules</xsl:text>
+                                       </mads:descriptionStandard>
+                               </xsl:if>
+                       </xsl:for-each>
+               </mads:recordInfo>
+       </xsl:template>
+
+       <!-- start of secondary templates -->
+
+       <!-- ======== xlink ======== -->
+
+       <!-- <xsl:template name="uri"> 
+    <xsl:for-each select="marc:subfield[@code='0']">
+      <xsl:attribute name="xlink:href">
+       <xsl:value-of select="."/>
+      </xsl:attribute>
+    </xsl:for-each>
+     </xsl:template> 
+   -->
+       <xsl:template match="marc:subfield[@code='i']">
+               <xsl:attribute name="otherType">
+                       <xsl:value-of select="."/>
+               </xsl:attribute>
+       </xsl:template>
+
+       <!-- No role/roleTerm mapped in MADS 06/24/2010
+       <xsl:template name="role">
+               <xsl:for-each select="marc:subfield[@code='e']">
+                       <mads:role>
+                               <mads:roleTerm type="text">
+                                       <xsl:value-of select="."/>
+                               </mads:roleTerm>
+                       </mads:role>
+               </xsl:for-each>
+       </xsl:template>
+-->
+
+       <xsl:template name="part">
+               <xsl:variable name="partNumber">
+                       <xsl:call-template name="specialSubfieldSelect">
+                               <xsl:with-param name="axis">n</xsl:with-param>
+                               <xsl:with-param name="anyCodes">n</xsl:with-param>
+                               <xsl:with-param name="afterCodes">fghkdlmor</xsl:with-param>
+                       </xsl:call-template>
+               </xsl:variable>
+               <xsl:variable name="partName">
+                       <xsl:call-template name="specialSubfieldSelect">
+                               <xsl:with-param name="axis">p</xsl:with-param>
+                               <xsl:with-param name="anyCodes">p</xsl:with-param>
+                               <xsl:with-param name="afterCodes">fghkdlmor</xsl:with-param>
+                       </xsl:call-template>
+               </xsl:variable>
+               <xsl:if test="string-length(normalize-space($partNumber))">
+                       <mads:partNumber>
+                               <xsl:call-template name="chopPunctuation">
+                                       <xsl:with-param name="chopString" select="$partNumber"/>
+                               </xsl:call-template>
+                       </mads:partNumber>
+               </xsl:if>
+               <xsl:if test="string-length(normalize-space($partName))">
+                       <mads:partName>
+                               <xsl:call-template name="chopPunctuation">
+                                       <xsl:with-param name="chopString" select="$partName"/>
+                               </xsl:call-template>
+                       </mads:partName>
+               </xsl:if>
+       </xsl:template>
+
+       <xsl:template name="nameABCDN">
+               <xsl:for-each select="marc:subfield[@code='a']">
+                       <mads:namePart>
+                               <xsl:call-template name="chopPunctuation">
+                                       <xsl:with-param name="chopString" select="."/>
+                               </xsl:call-template>
+                       </mads:namePart>
+               </xsl:for-each>
+               <xsl:for-each select="marc:subfield[@code='b']">
+                       <mads:namePart>
+                               <xsl:value-of select="."/>
+                       </mads:namePart>
+               </xsl:for-each>
+               <xsl:if
+                       test="marc:subfield[@code='c'] or marc:subfield[@code='d'] or marc:subfield[@code='n']">
+                       <mads:namePart>
+                               <xsl:call-template name="subfieldSelect">
+                                       <xsl:with-param name="codes">cdn</xsl:with-param>
+                               </xsl:call-template>
+                       </mads:namePart>
+               </xsl:if>
+       </xsl:template>
+
+       <xsl:template name="nameABCDQ">
+               <mads:namePart>
+                       <xsl:call-template name="chopPunctuation">
+                               <xsl:with-param name="chopString">
+                                       <xsl:call-template name="subfieldSelect">
+                                               <xsl:with-param name="codes">aq</xsl:with-param>
+                                       </xsl:call-template>
+                               </xsl:with-param>
+                       </xsl:call-template>
+               </mads:namePart>
+               <xsl:call-template name="termsOfAddress"/>
+               <xsl:call-template name="nameDate"/>
+       </xsl:template>
+
+       <xsl:template name="nameACDENQ">
+               <mads:namePart>
+                       <xsl:call-template name="subfieldSelect">
+                               <xsl:with-param name="codes">acdenq</xsl:with-param>
+                       </xsl:call-template>
+               </mads:namePart>
+       </xsl:template>
+
+       <xsl:template name="nameDate">
+               <xsl:for-each select="marc:subfield[@code='d']">
+                       <mads:namePart type="date">
+                               <xsl:call-template name="chopPunctuation">
+                                       <xsl:with-param name="chopString" select="."/>
+                               </xsl:call-template>
+                       </mads:namePart>
+               </xsl:for-each>
+       </xsl:template>
+
+       <xsl:template name="specialSubfieldSelect">
+               <xsl:param name="anyCodes"/>
+               <xsl:param name="axis"/>
+               <xsl:param name="beforeCodes"/>
+               <xsl:param name="afterCodes"/>
+               <xsl:variable name="str">
+                       <xsl:for-each select="marc:subfield">
+                               <xsl:if
+                                       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])">
+                                       <xsl:value-of select="text()"/>
+                                       <xsl:text> </xsl:text>
+                               </xsl:if>
+                       </xsl:for-each>
+               </xsl:variable>
+               <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+       </xsl:template>
+
+       <xsl:template name="termsOfAddress">
+               <xsl:if test="marc:subfield[@code='b' or @code='c']">
+                       <mads:namePart type="termsOfAddress">
+                               <xsl:call-template name="chopPunctuation">
+                                       <xsl:with-param name="chopString">
+                                               <xsl:call-template name="subfieldSelect">
+                                                       <xsl:with-param name="codes">bc</xsl:with-param>
+                                               </xsl:call-template>
+                                       </xsl:with-param>
+                               </xsl:call-template>
+                       </mads:namePart>
+               </xsl:if>
+       </xsl:template>
+
+       <xsl:template name="displayLabel">
+               <xsl:if test="marc:subfield[@code='z']">
+                       <xsl:attribute name="displayLabel">
+                               <xsl:value-of select="marc:subfield[@code='z']"/>
+                       </xsl:attribute>
+               </xsl:if>
+               <xsl:if test="marc:subfield[@code='3']">
+                       <xsl:attribute name="displayLabel">
+                               <xsl:value-of select="marc:subfield[@code='3']"/>
+                       </xsl:attribute>
+               </xsl:if>
+       </xsl:template>
+
+       <xsl:template name="isInvalid">
+               <xsl:if test="@code='z'">
+                       <xsl:attribute name="invalid">yes</xsl:attribute>
+               </xsl:if>
+       </xsl:template>
+
+       <xsl:template name="sub2Attribute">
+               <!-- 024 -->
+               <xsl:if test="../marc:subfield[@code='2']">
+                       <xsl:attribute name="type">
+                               <xsl:value-of select="../marc:subfield[@code='2']"/>
+                       </xsl:attribute>
+               </xsl:if>
+       </xsl:template>
+
+       <xsl:template match="marc:controlfield[@tag=001]">
+               <mads:recordIdentifier>
+                       <xsl:if test="../marc:controlfield[@tag=003]">
+                               <xsl:attribute name="source">
+                                       <xsl:value-of select="../marc:controlfield[@tag=003]"/>
+                               </xsl:attribute>
+                       </xsl:if>
+                       <xsl:value-of select="."/>
+               </mads:recordIdentifier>
+       </xsl:template>
+
+       <xsl:template match="marc:controlfield[@tag=005]">
+               <mads:recordChangeDate encoding="iso8601">
+                       <xsl:value-of select="."/>
+               </mads:recordChangeDate>
+       </xsl:template>
+
+       <xsl:template match="marc:controlfield[@tag=008]">
+               <mads:recordCreationDate encoding="marc">
+                       <xsl:value-of select="substring(.,1,6)"/>
+               </mads:recordCreationDate>
+       </xsl:template>
+
+       <xsl:template match="marc:datafield[@tag=010]">
+               <xsl:for-each select="marc:subfield">
+                       <mads:identifier type="lccn">
+                               <xsl:call-template name="isInvalid"/>
+                               <xsl:value-of select="."/>
+                       </mads:identifier>
+               </xsl:for-each>
+       </xsl:template>
+
+       <xsl:template match="marc:datafield[@tag=024]">
+               <xsl:for-each select="marc:subfield[not(@code=2)]">
+                       <mads:identifier>
+                               <xsl:call-template name="isInvalid"/>
+                               <xsl:call-template name="sub2Attribute"/>
+                               <xsl:value-of select="."/>
+                       </mads:identifier>
+               </xsl:for-each>
+       </xsl:template>
+
+       <!-- ========== 372 ========== -->
+       <xsl:template match="marc:datafield[@tag=372]">
+               <mads:fieldOfActivity>
+                       <xsl:call-template name="subfieldSelect">
+                               <xsl:with-param name="codes">a</xsl:with-param>
+                       </xsl:call-template>
+                       <xsl:text>-</xsl:text>
+                       <xsl:call-template name="subfieldSelect">
+                               <xsl:with-param name="codes">st</xsl:with-param>
+                       </xsl:call-template>
+               </mads:fieldOfActivity>
+       </xsl:template>
+
+
+       <!-- ========== 040 ========== -->
+       <xsl:template match="marc:datafield[@tag=040]/marc:subfield[@code='a']">
+               <mads:recordContentSource authority="marcorg">
+                       <xsl:value-of select="."/>
+               </mads:recordContentSource>
+       </xsl:template>
+
+       <xsl:template match="marc:datafield[@tag=040]/marc:subfield[@code='b']">
+               <mads:languageOfCataloging>
+                       <mads:languageTerm authority="iso639-2b" type="code">
+                               <xsl:value-of select="."/>
+                       </mads:languageTerm>
+               </mads:languageOfCataloging>
+       </xsl:template>
+
+       <xsl:template match="marc:datafield[@tag=040]/marc:subfield[@code='e']">
+               <mads:descriptionStandard>
+                       <xsl:value-of select="."/>
+               </mads:descriptionStandard>
+       </xsl:template>
+       
+       <!-- ========== classification 2.03 ========== -->
+       
+       <xsl:template match="marc:datafield[@tag=053]">
+               <mads:classification>
+                       <xsl:call-template name="subfieldSelect">
+                               <xsl:with-param name="codes">abcdxyz</xsl:with-param>
+                               <xsl:with-param name="delimeter">-</xsl:with-param>
+                       </xsl:call-template>
+               </mads:classification>
+       </xsl:template>
+       
+       <xsl:template match="marc:datafield[@tag=055]">
+               <mads:classification>
+                       <xsl:call-template name="subfieldSelect">
+                               <xsl:with-param name="codes">abcdxyz</xsl:with-param>
+                               <xsl:with-param name="delimeter">-</xsl:with-param>
+                       </xsl:call-template>
+               </mads:classification>
+       </xsl:template>
+       
+       <xsl:template match="marc:datafield[@tag=060]">
+               <mads:classification>
+                       <xsl:call-template name="subfieldSelect">
+                               <xsl:with-param name="codes">abcdxyz</xsl:with-param>
+                               <xsl:with-param name="delimeter">-</xsl:with-param>
+                       </xsl:call-template>
+               </mads:classification>
+       </xsl:template>
+       <xsl:template match="marc:datafield[@tag=065]">
+               <mads:classification>
+                       <xsl:attribute name="authority">
+                               <xsl:value-of select="marc:subfield[@code='2']"/>
+                       </xsl:attribute>
+                       <xsl:call-template name="subfieldSelect">
+                               <xsl:with-param name="codes">abcdxyz</xsl:with-param>
+                               <xsl:with-param name="delimeter">-</xsl:with-param>
+                       </xsl:call-template>
+               </mads:classification>
+       </xsl:template>
+       <xsl:template match="marc:datafield[@tag=070]">
+               <mads:classification>
+                       <xsl:call-template name="subfieldSelect">
+                               <xsl:with-param name="codes">abcdxyz5</xsl:with-param>
+                               <xsl:with-param name="delimeter">-</xsl:with-param>
+                       </xsl:call-template>
+               </mads:classification>
+       </xsl:template>
+       <xsl:template match="marc:datafield[@tag=080]">
+               <mads:classification>
+                       <xsl:attribute name="authority">
+                               <xsl:value-of select="marc:subfield[@code='2']"/>
+                       </xsl:attribute>
+                       <xsl:call-template name="subfieldSelect">
+                               <xsl:with-param name="codes">abcdxyz5</xsl:with-param>
+                               <xsl:with-param name="delimeter">-</xsl:with-param>
+                       </xsl:call-template>
+               </mads:classification>
+       </xsl:template>
+       <xsl:template match="marc:datafield[@tag=082]">
+               <mads:classification>
+                       <xsl:attribute name="authority">
+                               <xsl:value-of select="marc:subfield[@code='2']"/>
+                       </xsl:attribute>
+                       <xsl:call-template name="subfieldSelect">
+                               <xsl:with-param name="codes">abcdxyz5</xsl:with-param>
+                               <xsl:with-param name="delimeter">-</xsl:with-param>
+                       </xsl:call-template>
+               </mads:classification>
+       </xsl:template>
+       <xsl:template match="marc:datafield[@tag=083]">
+               <mads:classification>
+                       <xsl:attribute name="authority">
+                               <xsl:value-of select="marc:subfield[@code='2']"/>
+                       </xsl:attribute>
+                       <xsl:call-template name="subfieldSelect">
+                               <xsl:with-param name="codes">abcdxyz5</xsl:with-param>
+                               <xsl:with-param name="delimeter">-</xsl:with-param>
+                       </xsl:call-template>
+               </mads:classification>
+       </xsl:template>
+       <xsl:template match="marc:datafield[@tag=086]">
+               <mads:classification>
+                       <xsl:attribute name="authority">
+                               <xsl:value-of select="marc:subfield[@code='2']"/>
+                       </xsl:attribute>
+                       <xsl:call-template name="subfieldSelect">
+                               <xsl:with-param name="codes">abcdxyz5</xsl:with-param>
+                               <xsl:with-param name="delimeter">-</xsl:with-param>
+                       </xsl:call-template>
+               </mads:classification>
+       </xsl:template>
+       <xsl:template match="marc:datafield[@tag=087]">
+               <mads:classification>
+                       <xsl:attribute name="authority">
+                               <xsl:value-of select="marc:subfield[@code='2']"/>
+                       </xsl:attribute>
+                       <xsl:call-template name="subfieldSelect">
+                               <xsl:with-param name="codes">abcdxyz5</xsl:with-param>
+                               <xsl:with-param name="delimeter">-</xsl:with-param>
+                       </xsl:call-template>
+               </mads:classification>
+       </xsl:template>
+       
+
+       <!-- ========== names  ========== -->
+       <xsl:template match="marc:datafield[@tag=100]">
+               <mads:name type="personal">
+                       <xsl:call-template name="setAuthority"/>
+                       <xsl:call-template name="nameABCDQ"/>
+               </mads:name>
+               <xsl:apply-templates select="*[marc:subfield[not(contains('abcdeq',@code))]]"/>
+               <xsl:call-template name="title"/>
+               <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+       </xsl:template>
+
+       <xsl:template match="marc:datafield[@tag=110]">
+               <mads:name type="corporate">
+                       <xsl:call-template name="setAuthority"/>
+                       <xsl:call-template name="nameABCDN"/>
+               </mads:name>
+               <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+       </xsl:template>
+
+       <xsl:template match="marc:datafield[@tag=111]">
+               <mads:name type="conference">
+                       <xsl:call-template name="setAuthority"/>
+                       <xsl:call-template name="nameACDENQ"/>
+               </mads:name>
+               <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+       </xsl:template>
+
+       <xsl:template match="marc:datafield[@tag=400]">
+               <mads:variant>
+                       <xsl:call-template name="variantTypeAttribute"/>
+                       <mads:name type="personal">
+                               <xsl:call-template name="nameABCDQ"/>
+                       </mads:name>
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+                       <xsl:call-template name="title"/>
+               </mads:variant>
+       </xsl:template>
+
+       <xsl:template match="marc:datafield[@tag=410]">
+               <mads:variant>
+                       <xsl:call-template name="variantTypeAttribute"/>
+                       <mads:name type="corporate">
+                               <xsl:call-template name="nameABCDN"/>
+                       </mads:name>
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+               </mads:variant>
+       </xsl:template>
+
+       <xsl:template match="marc:datafield[@tag=411]">
+               <mads:variant>
+                       <xsl:call-template name="variantTypeAttribute"/>
+                       <mads:name type="conference">
+                               <xsl:call-template name="nameACDENQ"/>
+                       </mads:name>
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+               </mads:variant>
+       </xsl:template>
+
+       <xsl:template match="marc:datafield[@tag=500]|marc:datafield[@tag=700]">
+               <mads:related>
+                       <xsl:call-template name="relatedTypeAttribute"/>
+                       <!-- <xsl:call-template name="uri"/> -->
+                       <mads:name type="personal">
+                               <xsl:call-template name="setAuthority"/>
+                               <xsl:call-template name="nameABCDQ"/>
+                       </mads:name>
+                       <xsl:call-template name="title"/>
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+               </mads:related>
+       </xsl:template>
+
+       <xsl:template match="marc:datafield[@tag=510]|marc:datafield[@tag=710]">
+               <mads:related>
+                       <xsl:call-template name="relatedTypeAttribute"/>
+                       <!-- <xsl:call-template name="uri"/> -->
+                       <mads:name type="corporate">
+                               <xsl:call-template name="setAuthority"/>
+                               <xsl:call-template name="nameABCDN"/>
+                       </mads:name>
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+               </mads:related>
+       </xsl:template>
+
+       <xsl:template match="marc:datafield[@tag=511]|marc:datafield[@tag=711]">
+               <mads:related>
+                       <xsl:call-template name="relatedTypeAttribute"/>
+                       <!-- <xsl:call-template name="uri"/> -->
+                       <mads:name type="conference">
+                               <xsl:call-template name="setAuthority"/>
+                               <xsl:call-template name="nameACDENQ"/>
+                       </mads:name>
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+               </mads:related>
+       </xsl:template>
+
+       <!-- ========== titles  ========== -->
+       <xsl:template match="marc:datafield[@tag=130]">
+               <xsl:call-template name="uniform-title"/>
+               <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+       </xsl:template>
+
+       <xsl:template match="marc:datafield[@tag=430]">
+               <mads:variant>
+                       <xsl:call-template name="variantTypeAttribute"/>
+                       <xsl:call-template name="uniform-title"/>
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+               </mads:variant>
+       </xsl:template>
+
+       <xsl:template match="marc:datafield[@tag=530]|marc:datafield[@tag=730]">
+               <mads:related>
+                       <xsl:call-template name="relatedTypeAttribute"/>
+                       <xsl:call-template name="uniform-title"/>
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+               </mads:related>
+       </xsl:template>
+
+       <xsl:template name="title">
+               <xsl:variable name="hasTitle">
+                       <xsl:for-each select="marc:subfield">
+                               <xsl:if test="(contains('tfghklmors',@code) )">
+                                       <xsl:value-of select="@code"/>
+                               </xsl:if>
+                       </xsl:for-each>
+               </xsl:variable>
+               <xsl:if test="string-length($hasTitle) &gt; 0 ">
+                       <mads:titleInfo>
+                               <xsl:call-template name="setAuthority"/>
+                               <mads:title>
+                                       <xsl:variable name="str">
+                                               <xsl:for-each select="marc:subfield">
+                                                       <xsl:if test="(contains('atfghklmors',@code) )">
+                                                               <xsl:value-of select="text()"/>
+                                                               <xsl:text> </xsl:text>
+                                                       </xsl:if>
+                                               </xsl:for-each>
+                                       </xsl:variable>
+                                       <xsl:call-template name="chopPunctuation">
+                                               <xsl:with-param name="chopString">
+                                                       <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+                                               </xsl:with-param>
+                                       </xsl:call-template>
+                               </mads:title>
+                               <xsl:call-template name="part"/>
+                               <!-- <xsl:call-template name="uri"/> -->
+                       </mads:titleInfo>
+               </xsl:if>
+       </xsl:template>
+
+       <xsl:template name="uniform-title">
+               <xsl:variable name="hasTitle">
+                       <xsl:for-each select="marc:subfield">
+                               <xsl:if test="(contains('atfghklmors',@code) )">
+                                       <xsl:value-of select="@code"/>
+                               </xsl:if>
+                       </xsl:for-each>
+               </xsl:variable>
+               <xsl:if test="string-length($hasTitle) &gt; 0 ">
+                       <mads:titleInfo>
+                               <xsl:call-template name="setAuthority"/>
+                               <mads:title>
+                                       <xsl:variable name="str">
+                                               <xsl:for-each select="marc:subfield">
+                                                       <xsl:if test="(contains('adfghklmors',@code) )">
+                                                               <xsl:value-of select="text()"/>
+                                                               <xsl:text> </xsl:text>
+                                                       </xsl:if>
+                                               </xsl:for-each>
+                                       </xsl:variable>
+                                       <xsl:call-template name="chopPunctuation">
+                                               <xsl:with-param name="chopString">
+                                                       <xsl:value-of select="substring($str,1,string-length($str)-1)"/>
+                                               </xsl:with-param>
+                                       </xsl:call-template>
+                               </mads:title>
+                               <xsl:call-template name="part"/>
+                               <!-- <xsl:call-template name="uri"/> -->
+                       </mads:titleInfo>
+               </xsl:if>
+       </xsl:template>
+
+
+       <!-- ========== topics  ========== -->
+       <xsl:template match="marc:subfield[@code='x']">
+               <mads:topic>
+                       <xsl:call-template name="chopPunctuation">
+                               <xsl:with-param name="chopString">
+                                       <xsl:value-of select="."/>
+                               </xsl:with-param>
+                       </xsl:call-template>
+               </mads:topic>
+       </xsl:template>
+       
+       <!-- 2.06 fix -->
+       <xsl:template
+               match="marc:datafield[@tag=150][marc:subfield[@code='a' or @code='b']]|marc:datafield[@tag=180][marc:subfield[@code='x']]">
+               <xsl:call-template name="topic"/>
+               <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+       </xsl:template>
+       <xsl:template
+               match="marc:datafield[@tag=450][marc:subfield[@code='a' or @code='b']]|marc:datafield[@tag=480][marc:subfield[@code='x']]">
+               <mads:variant>
+                       <xsl:call-template name="variantTypeAttribute"/>
+                       <xsl:call-template name="topic"/>
+               </mads:variant>
+       </xsl:template>
+       <xsl:template
+               match="marc:datafield[@tag=550 or @tag=750][marc:subfield[@code='a' or @code='b']]">
+               <mads:related>
+                       <xsl:call-template name="relatedTypeAttribute"/>
+                       <!-- <xsl:call-template name="uri"/> -->
+                       <xsl:call-template name="topic"/>
+                       <xsl:apply-templates select="marc:subfield[@code='z']"/>
+               </mads:related>
+       </xsl:template>
+       <xsl:template name="topic">
+               <mads:topic>
+                       <xsl:call-template name="setAuthority"/>
+                       <!-- tmee2006 dedupe 550a
+                       <xsl:if test="@tag=550 or @tag=750">
+                               <xsl:call-template name="subfieldSelect">
+                                       <xsl:with-param name="codes">ab</xsl:with-param>
+                               </xsl:call-template>
+                       </xsl:if>       
+                       -->
+                       <xsl:choose>
+                               <xsl:when test="@tag=180 or @tag=480 or @tag=580 or @tag=780">
+                                       <xsl:call-template name="chopPunctuation">
+                                               <xsl:with-param name="chopString">
+                                                       <xsl:apply-templates select="marc:subfield[@code='x']"/>
+                                               </xsl:with-param>
+                                       </xsl:call-template>
+                               </xsl:when>
+                       </xsl:choose>
+                       <xsl:call-template name="chopPunctuation">
+                               <xsl:with-param name="chopString">
+                                       <xsl:choose>
+                                               <xsl:when test="@tag=180 or @tag=480 or @tag=580 or @tag=780">
+                                                       <xsl:apply-templates select="marc:subfield[@code='x']"/>
+                                               </xsl:when>
+                                               <xsl:otherwise>
+                                                       <xsl:call-template name="subfieldSelect">
+                                                               <xsl:with-param name="codes">ab</xsl:with-param>
+                                                       </xsl:call-template>
+                                               </xsl:otherwise>
+                                       </xsl:choose>
+                               </xsl:with-param>
+                       </xsl:call-template>
+               </mads:topic>
+       </xsl:template>
+
+       <!-- ========= temporals  ========== -->
+       <xsl:template match="marc:subfield[@code='y']">
+               <mads:temporal>
+                       <xsl:call-template name="chopPunctuation">
+                               <xsl:with-param name="chopString">
+                                       <xsl:value-of select="."/>
+                               </xsl:with-param>
+                       </xsl:call-template>
+               </mads:temporal>
+       </xsl:template>
+       <xsl:template
+               match="marc:datafield[@tag=148][marc:subfield[@code='a']]|marc:datafield[@tag=182 ][marc:subfield[@code='y']]">
+               <xsl:call-template name="temporal"/>
+       </xsl:template>
+       <xsl:template
+               match="marc:datafield[@tag=448][marc:subfield[@code='a']]|marc:datafield[@tag=482][marc:subfield[@code='y']]">
+               <mads:variant>
+                       <xsl:call-template name="variantTypeAttribute"/>
+                       <xsl:call-template name="temporal"/>
+               </mads:variant>
+       </xsl:template>
+       <xsl:template
+               match="marc:datafield[@tag=548 or @tag=748][marc:subfield[@code='a']]|marc:datafield[@tag=582 or @tag=782][marc:subfield[@code='y']]">
+               <mads:related>
+                       <xsl:call-template name="relatedTypeAttribute"/>
+                       <!-- <xsl:call-template name="uri"/> -->
+                       <xsl:call-template name="temporal"/>
+               </mads:related>
+       </xsl:template>
+       <xsl:template name="temporal">
+               <mads:temporal>
+                       <xsl:call-template name="setAuthority"/>
+                       <xsl:if test="@tag=548 or @tag=748">
+                               <xsl:value-of select="marc:subfield[@code='a']"/>
+                       </xsl:if>
+                       <xsl:call-template name="chopPunctuation">
+                               <xsl:with-param name="chopString">
+                                       <xsl:choose>
+                                               <xsl:when test="@tag=182 or @tag=482 or @tag=582 or @tag=782">
+                                                       <xsl:apply-templates select="marc:subfield[@code='y']"/>
+                                               </xsl:when>
+                                               <xsl:otherwise>
+                                                       <xsl:value-of select="marc:subfield[@code='a']"/>
+                                               </xsl:otherwise>
+                                       </xsl:choose>
+                               </xsl:with-param>
+                       </xsl:call-template>
+               </mads:temporal>
+               <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+       </xsl:template>
+
+       <!-- ========== genre  ========== -->
+       <xsl:template match="marc:subfield[@code='v']">
+               <mads:genre>
+                       <xsl:call-template name="chopPunctuation">
+                               <xsl:with-param name="chopString">
+                                       <xsl:value-of select="."/>
+                               </xsl:with-param>
+                       </xsl:call-template>
+               </mads:genre>
+       </xsl:template>
+       <xsl:template
+               match="marc:datafield[@tag=155][marc:subfield[@code='a']]|marc:datafield[@tag=185][marc:subfield[@code='v']]">
+               <xsl:call-template name="genre"/>
+       </xsl:template>
+       <xsl:template
+               match="marc:datafield[@tag=455][marc:subfield[@code='a']]|marc:datafield[@tag=485 ][marc:subfield[@code='v']]">
+               <mads:variant>
+                       <xsl:call-template name="variantTypeAttribute"/>
+                       <xsl:call-template name="genre"/>
+               </mads:variant>
+       </xsl:template>
+       <!--
+       <xsl:template match="marc:datafield[@tag=555]">
+               <mads:related>
+                       <xsl:call-template name="relatedTypeAttribute"/>
+                       <xsl:call-template name="uri"/>
+                       <xsl:call-template name="genre"/>
+               </mads:related>
+       </xsl:template>
+       -->
+       <xsl:template
+               match="marc:datafield[@tag=555 or @tag=755][marc:subfield[@code='a']]|marc:datafield[@tag=585][marc:subfield[@code='v']]">
+               <mads:related>
+                       <xsl:call-template name="relatedTypeAttribute"/>
+                       <xsl:call-template name="genre"/>
+               </mads:related>
+       </xsl:template>
+       <xsl:template name="genre">
+               <mads:genre>
+                       <xsl:if test="@tag=555">
+                               <xsl:value-of select="marc:subfield[@code='a']"/>
+                       </xsl:if>
+                       <xsl:call-template name="setAuthority"/>
+                       <xsl:call-template name="chopPunctuation">
+                               <xsl:with-param name="chopString">
+                                       <xsl:choose>
+                                               <!-- 2.07 fix -->
+                                               <xsl:when test="@tag='555'"/>
+                                               <xsl:when test="@tag=185 or @tag=485 or @tag=585">
+                                                       <xsl:apply-templates select="marc:subfield[@code='v']"/>
+                                               </xsl:when>
+                                               <xsl:otherwise>
+                                                       <xsl:value-of select="marc:subfield[@code='a']"/>
+                                               </xsl:otherwise>
+                                       </xsl:choose>
+                               </xsl:with-param>
+                       </xsl:call-template>
+               </mads:genre>
+               <xsl:apply-templates/>
+       </xsl:template>
+
+       <!-- ========= geographic  ========== -->
+       <xsl:template match="marc:subfield[@code='z']">
+               <mads:geographic>
+                       <xsl:call-template name="chopPunctuation">
+                               <xsl:with-param name="chopString">
+                                       <xsl:value-of select="."/>
+                               </xsl:with-param>
+                       </xsl:call-template>
+               </mads:geographic>
+       </xsl:template>
+       <xsl:template name="geographic">
+               <mads:geographic>
+                       <!-- 2.14 -->
+                       <xsl:call-template name="setAuthority"/>
+                       <!-- 2.13 -->
+                       <xsl:if test="@tag=151 or @tag=551">
+                               <xsl:value-of select="marc:subfield[@code='a']"/>
+                       </xsl:if>
+                       <xsl:call-template name="chopPunctuation">
+                               <xsl:with-param name="chopString">
+                                               <xsl:if test="@tag=181 or @tag=481 or @tag=581">
+                                                               <xsl:apply-templates select="marc:subfield[@code='z']"/>
+                                               </xsl:if>
+                                               <!-- 2.13
+                                                       <xsl:choose>
+                                               <xsl:when test="@tag=181 or @tag=481 or @tag=581">
+                                                       <xsl:apply-templates select="marc:subfield[@code='z']"/>
+                                               </xsl:when>
+                                       
+                                               <xsl:otherwise>
+                                                       <xsl:value-of select="marc:subfield[@code='a']"/>
+                                               </xsl:otherwise>
+                                               </xsl:choose>
+                                               -->
+                               </xsl:with-param>
+                       </xsl:call-template>
+               </mads:geographic>
+               <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+       </xsl:template>
+       <xsl:template
+               match="marc:datafield[@tag=151][marc:subfield[@code='a']]|marc:datafield[@tag=181][marc:subfield[@code='z']]">
+               <xsl:call-template name="geographic"/>
+       </xsl:template>
+       <xsl:template
+               match="marc:datafield[@tag=451][marc:subfield[@code='a']]|marc:datafield[@tag=481][marc:subfield[@code='z']]">
+               <mads:variant>
+                       <xsl:call-template name="variantTypeAttribute"/>
+                       <xsl:call-template name="geographic"/>
+               </mads:variant>
+       </xsl:template>
+       <xsl:template
+               match="marc:datafield[@tag=551]|marc:datafield[@tag=581][marc:subfield[@code='z']]">
+               <mads:related>
+                       <xsl:call-template name="relatedTypeAttribute"/>
+                       <!-- <xsl:call-template name="uri"/> -->
+                       <xsl:call-template name="geographic"/>
+               </mads:related>
+       </xsl:template>
+       <xsl:template match="marc:datafield[@tag=580]">
+               <mads:related>
+                       <xsl:call-template name="relatedTypeAttribute"/>
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+               </mads:related>
+       </xsl:template>
+       <xsl:template
+               match="marc:datafield[@tag=751][marc:subfield[@code='z']]|marc:datafield[@tag=781][marc:subfield[@code='z']]">
+               <mads:related>
+                       <xsl:call-template name="relatedTypeAttribute"/>
+                       <xsl:call-template name="geographic"/>
+               </mads:related>
+       </xsl:template>
+       <xsl:template match="marc:datafield[@tag=755]">
+               <mads:related>
+                       <xsl:call-template name="relatedTypeAttribute"/>
+                       <xsl:call-template name="genre"/>
+                       <xsl:call-template name="setAuthority"/>
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+               </mads:related>
+       </xsl:template>
+       <xsl:template match="marc:datafield[@tag=780]">
+               <mads:related>
+                       <xsl:call-template name="relatedTypeAttribute"/>
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+               </mads:related>
+       </xsl:template>
+       <xsl:template match="marc:datafield[@tag=785]">
+               <mads:related>
+                       <xsl:call-template name="relatedTypeAttribute"/>
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>
+               </mads:related>
+       </xsl:template>
+
+       <!-- ========== notes  ========== -->
+       <xsl:template match="marc:datafield[667 &lt;= @tag and @tag &lt;= 688]">
+               <mads:note>
+                       <xsl:choose>
+                               <xsl:when test="@tag=667">
+                                       <xsl:attribute name="type">nonpublic</xsl:attribute>
+                               </xsl:when>
+                               <xsl:when test="@tag=670">
+                                       <xsl:attribute name="type">source</xsl:attribute>
+                               </xsl:when>
+                               <xsl:when test="@tag=675">
+                                       <xsl:attribute name="type">notFound</xsl:attribute>
+                               </xsl:when>
+                               <xsl:when test="@tag=678">
+                                       <xsl:attribute name="type">history</xsl:attribute>
+                               </xsl:when>
+                               <xsl:when test="@tag=681">
+                                       <xsl:attribute name="type">subject example</xsl:attribute>
+                               </xsl:when>
+                               <xsl:when test="@tag=682">
+                                       <xsl:attribute name="type">deleted heading information</xsl:attribute>
+                               </xsl:when>
+                               <xsl:when test="@tag=688">
+                                       <xsl:attribute name="type">application history</xsl:attribute>
+                               </xsl:when>
+                       </xsl:choose>
+                       <xsl:call-template name="chopPunctuation">
+                               <xsl:with-param name="chopString">
+                                       <xsl:choose>
+                                               <xsl:when test="@tag=667 or @tag=675">
+                                                       <xsl:value-of select="marc:subfield[@code='a']"/>
+                                               </xsl:when>
+                                               <xsl:when test="@tag=670 or @tag=678">
+                                                       <xsl:call-template name="subfieldSelect">
+                                                               <xsl:with-param name="codes">ab</xsl:with-param>
+                                                       </xsl:call-template>
+                                               </xsl:when>
+                                               <xsl:when test="680 &lt;= @tag and @tag &lt;=688">
+                                                       <xsl:call-template name="subfieldSelect">
+                                                               <xsl:with-param name="codes">ai</xsl:with-param>
+                                                       </xsl:call-template>
+                                               </xsl:when>
+                                       </xsl:choose>
+                               </xsl:with-param>
+                       </xsl:call-template>
+               </mads:note>
+       </xsl:template>
+
+       <!-- ========== url  ========== -->
+       <xsl:template match="marc:datafield[@tag=856][marc:subfield[@code='u']]">
+               <mads:url>
+                       <xsl:if test="marc:subfield[@code='z' or @code='3']">
+                               <xsl:attribute name="displayLabel">
+                                       <xsl:call-template name="subfieldSelect">
+                                               <xsl:with-param name="codes">z3</xsl:with-param>
+                                       </xsl:call-template>
+                               </xsl:attribute>
+                       </xsl:if>
+                       <xsl:value-of select="marc:subfield[@code='u']"/>
+               </mads:url>
+       </xsl:template>
+
+       <xsl:template name="relatedTypeAttribute">
+               <xsl:choose>
+                       <xsl:when
+                               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">
+                               <xsl:if test="substring(marc:subfield[@code='w'],1,1)='a'">
+                                       <xsl:attribute name="type">earlier</xsl:attribute>
+                               </xsl:if>
+                               <xsl:if test="substring(marc:subfield[@code='w'],1,1)='b'">
+                                       <xsl:attribute name="type">later</xsl:attribute>
+                               </xsl:if>
+                               <xsl:if test="substring(marc:subfield[@code='w'],1,1)='t'">
+                                       <xsl:attribute name="type">parentOrg</xsl:attribute>
+                               </xsl:if>
+                               <xsl:if test="substring(marc:subfield[@code='w'],1,1)='g'">
+                                       <xsl:attribute name="type">broader</xsl:attribute>
+                               </xsl:if>
+                               <xsl:if test="substring(marc:subfield[@code='w'],1,1)='h'">
+                                       <xsl:attribute name="type">narrower</xsl:attribute>
+                               </xsl:if>
+                               <xsl:if test="substring(marc:subfield[@code='w'],1,1)='r'">
+                                       <xsl:attribute name="type">other</xsl:attribute>
+                               </xsl:if>
+                               <xsl:if test="contains('fin|', substring(marc:subfield[@code='w'],1,1))">
+                                       <xsl:attribute name="type">other</xsl:attribute>
+                               </xsl:if>
+                       </xsl:when>
+                       <xsl:when test="@tag=530 or @tag=730">
+                               <xsl:attribute name="type">other</xsl:attribute>
+                       </xsl:when>
+                       <xsl:otherwise>
+                               <!-- 7xx -->
+                               <xsl:attribute name="type">equivalent</xsl:attribute>
+                       </xsl:otherwise>
+               </xsl:choose>
+               <xsl:apply-templates select="marc:subfield[@code='i']"/>
+       </xsl:template>
+       
+
+
+       <xsl:template name="variantTypeAttribute">
+               <xsl:choose>
+                       <xsl:when
+                               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">
+                               <xsl:if test="substring(marc:subfield[@code='w'],1,1)='d'">
+                                       <xsl:attribute name="type">acronym</xsl:attribute>
+                               </xsl:if>
+                               <xsl:if test="substring(marc:subfield[@code='w'],1,1)='n'">
+                                       <xsl:attribute name="type">other</xsl:attribute>
+                               </xsl:if>
+                               <xsl:if test="contains('fit', substring(marc:subfield[@code='w'],1,1))">
+                                       <xsl:attribute name="type">other</xsl:attribute>
+                               </xsl:if>
+                       </xsl:when>
+                       <xsl:otherwise>
+                               <!-- 430  -->
+                               <xsl:attribute name="type">other</xsl:attribute>
+                       </xsl:otherwise>
+               </xsl:choose>
+               <xsl:apply-templates select="marc:subfield[@code='i']"/>
+       </xsl:template>
+
+       <xsl:template name="setAuthority">
+               <xsl:choose>
+                       <!-- can be called from the datafield or subfield level, so "..//@tag" means
+                       the tag can be at the subfield's parent level or at the datafields own level -->
+
+                       <xsl:when
+                               test="ancestor-or-self::marc:datafield/@tag=100 and (@ind1=0 or @ind1=1) and $controlField008-11='a' and $controlField008-14='a'">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>naf</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="ancestor-or-self::marc:datafield/@tag=100 and (@ind1=0 or @ind1=1) and $controlField008-11='a' and $controlField008-14='b'">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>lcsh</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="ancestor-or-self::marc:datafield/@tag=100 and (@ind1=0 or @ind1=1) and $controlField008-11='k'">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>lacnaf</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="ancestor-or-self::marc:datafield/@tag=100 and @ind1=3 and $controlField008-11='a' and $controlField008-14='b'">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>lcsh</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="ancestor-or-self::marc:datafield/@tag=100 and @ind1=3 and $controlField008-11='k' and $controlField008-14='b'">
+                               <xsl:attribute name="authority">cash</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="ancestor-or-self::marc:datafield/@tag=110 and $controlField008-11='a' and $controlField008-14='a'">
+                               <xsl:attribute name="authority">naf</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="ancestor-or-self::marc:datafield/@tag=110 and $controlField008-11='a' and $controlField008-14='b'">
+                               <xsl:attribute name="authority">lcsh</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="ancestor-or-self::marc:datafield/@tag=110 and $controlField008-11='k' and $controlField008-14='a'">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>lacnaf</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="ancestor-or-self::marc:datafield/@tag=110 and $controlField008-11='k' and $controlField008-14='b'">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>cash</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="100 &lt;= ancestor-or-self::marc:datafield/@tag and ancestor-or-self::marc:datafield/@tag &lt;= 155 and $controlField008-11='b'">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>lcshcl</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               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'">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>nlmnaf</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               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'">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>nalnaf</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="100 &lt;= ancestor-or-self::marc:datafield/@tag and ancestor-or-self::marc:datafield/@tag &lt;= 155 and $controlField008-11='r'">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>aat</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="100 &lt;= ancestor-or-self::marc:datafield/@tag and ancestor-or-self::marc:datafield/@tag &lt;= 155 and $controlField008-11='s'">
+                               <xsl:attribute name="authority">sears</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="100 &lt;= ancestor-or-self::marc:datafield/@tag and ancestor-or-self::marc:datafield/@tag &lt;= 155 and $controlField008-11='v'">
+                               <xsl:attribute name="authority">rvm</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="100 &lt;= ancestor-or-self::marc:datafield/@tag and ancestor-or-self::marc:datafield/@tag &lt;= 155 and $controlField008-11='z'">
+                               <xsl:attribute name="authority">
+                                       <xsl:value-of
+                                               select="../marc:datafield[ancestor-or-self::marc:datafield/@tag=040]/marc:subfield[@code='f']"
+                                       />
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="(ancestor-or-self::marc:datafield/@tag=111 or ancestor-or-self::marc:datafield/@tag=130) and $controlField008-11='a' and $controlField008-14='a'">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>naf</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="(ancestor-or-self::marc:datafield/@tag=111 or ancestor-or-self::marc:datafield/@tag=130) and $controlField008-11='a' and $controlField008-14='b'">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>lcsh</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="(ancestor-or-self::marc:datafield/@tag=111 or ancestor-or-self::marc:datafield/@tag=130) and $controlField008-11='k' ">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>lacnaf</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               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' ">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>lcsh</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               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' ">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>lcsh</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               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' ">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>mesh</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               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' ">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>nal</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               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' ">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>cash</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="ancestor-or-self::marc:datafield/@tag=151 and $controlField008-11='a' and $controlField008-14='a'">
+                               <xsl:attribute name="authority">
+                                       <xsl:text>naf</xsl:text>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="ancestor-or-self::marc:datafield/@tag=151 and $controlField008-11='a' and $controlField008-14='b'">
+                               <xsl:attribute name="authority">lcsh</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="ancestor-or-self::marc:datafield/@tag=151 and $controlField008-11='k' and $controlField008-14='a'">
+                               <xsl:attribute name="authority">lacnaf</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="ancestor-or-self::marc:datafield/@tag=151 and $controlField008-11='k' and $controlField008-14='b'">
+                               <xsl:attribute name="authority">cash</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               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'">
+                               <xsl:attribute name="authority">lcsh</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="ancestor-or-self::marc:datafield/@tag=700 and (@ind1='0' or @ind1='1') and @ind2='0'">
+                               <xsl:attribute name="authority">naf</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="ancestor-or-self::marc:datafield/@tag=700 and (@ind1='0' or @ind1='1') and @ind2='5'">
+                               <xsl:attribute name="authority">lacnaf</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when test="ancestor-or-self::marc:datafield/@tag=700 and @ind1='3' and @ind2='0'">
+                               <xsl:attribute name="authority">lcsh</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when test="ancestor-or-self::marc:datafield/@tag=700 and @ind1='3' and @ind2='5'">
+                               <xsl:attribute name="authority">cash</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="(700 &lt;= ancestor-or-self::marc:datafield/@tag and ancestor-or-self::marc:datafield/@tag &lt;= 755 ) and @ind2='1'">
+                               <xsl:attribute name="authority">lcshcl</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               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'">
+                               <xsl:attribute name="authority">nlmnaf</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               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'">
+                               <xsl:attribute name="authority">nalnaf</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="(700 &lt;= ancestor-or-self::marc:datafield/@tag and ancestor-or-self::marc:datafield/@tag &lt;= 755 ) and @ind2='6'">
+                               <xsl:attribute name="authority">rvm</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               test="(700 &lt;= ancestor-or-self::marc:datafield/@tag and ancestor-or-self::marc:datafield/@tag &lt;= 755 ) and @ind2='7'">
+                               <xsl:attribute name="authority">
+                                       <xsl:value-of select="marc:subfield[@code='2']"/>
+                               </xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               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'">
+                               <xsl:attribute name="authority">lacnaf</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               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'">
+                               <xsl:attribute name="authority">naf</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               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'">
+                               <xsl:attribute name="authority">lcsh</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               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'">
+                               <xsl:attribute name="authority">mesh</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               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'">
+                               <xsl:attribute name="authority">nal</xsl:attribute>
+                       </xsl:when>
+                       <xsl:when
+                               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'">
+                               <xsl:attribute name="authority">cash</xsl:attribute>
+                       </xsl:when>
+               </xsl:choose>
+       </xsl:template>
+       <xsl:template match="*"/>
+</xsl:stylesheet>$XSLT$);
diff --git a/Open-ILS/xsl/MARC21slim2MADS.xsl b/Open-ILS/xsl/MARC21slim2MADS.xsl
new file mode 100644 (file)
index 0000000..645406a
--- /dev/null
@@ -0,0 +1,1451 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<xsl:stylesheet version="1.0" xmlns:mads="http://www.loc.gov/mads/v2"\r
+       xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:marc="http://www.loc.gov/MARC21/slim"\r
+       xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="marc">\r
+\r
+       <xsl:include href="MARC21slimUtils.xsl"/>\r
+       <xsl:output method="xml" indent="yes" encoding="UTF-8"/>\r
+       <xsl:strip-space elements="*"/>\r
+\r
+<!--\r
+2.14    Fixed bug in mads:geographic attributes syntax                                      ws   05/04/2016            \r
+2.13   fixed repeating <geographic>                                                                                                            tmee 01/31/2014\r
+2.12   added $2 authority for <classification>                                                                                         tmee 09/18/2012\r
+2.11   added delimiters between <classification> subfields                                                                     tmee 09/18/2012\r
+2.10   fixed type="other" and type="otherType" for mads:related                                                        tmee 09/16/2011\r
+2.09   fixed professionTerm and genreTerm empty tag error                                                                      tmee 09/16/2011\r
+2.08   fixed marc:subfield @code='i' matching error                                                                            tmee 09/16/2011\r
+2.07   fixed 555 duplication error                                                                                                                     tmee 08/10/2011 \r
+2.06   fixed topic subfield error                                                                                                                      tmee 08/10/2011 \r
+2.05   fixed title subfield error                                                                                                                      tmee 06/20/2011 \r
+2.04   fixed geographicSubdivision mapping for authority element                                                       tmee 06/16/2011\r
+2.03   added classification for 053, 055, 060, 065, 070, 080, 082, 083, 086, 087                       tmee 06/03/2011         \r
+2.02   added descriptionStandard for 008/10                                                                                            tmee 04/27/2011\r
+2.01   added extensions for 046, 336, 370, 374, 375, 376                                                                       tmee 04/08/2011\r
+2.00   redefined imported MODS elements in version 1.0 to MADS elements in version 2.0         tmee 02/08/2011\r
+1.08   added 372 subfields $a $s $t for <fieldOfActivity>                                                                      tmee 06/24/2010\r
+1.07   removed role/roleTerm 100, 110, 111, 400, 410, 411, 500, 510, 511, 700, 710, 711        tmee 06/24/2010\r
+1.06   added strip-space                                                                                                                                       tmee 06/24/2010\r
+1.05   added subfield $a for 130, 430, 530                                                                                                     tmee 06/21/2010\r
+1.04   fixed 550 z omission                                                                                                                            ntra 08/11/2008\r
+1.03   removed duplication of 550 $a text                                                                                                      tmee 11/01/2006\r
+1.02   fixed namespace references between mads and mods                                                                        ntra 10/06/2006\r
+1.01   revised                                                                                                                                                         rgue/jrad 11/29/05\r
+1.00   adapted from MARC21Slim2MODS3.xsl                                                                                                       ntra 07/06/05\r
+-->\r
+\r
+       <!-- authority attribute defaults to 'naf' if not set using this authority parameter, for <authority> descriptors: name, titleInfo, geographic -->\r
+       <xsl:param name="authority"/>\r
+       <xsl:variable name="auth">\r
+               <xsl:choose>\r
+                       <xsl:when test="$authority">\r
+                               <xsl:value-of select="$authority"/>\r
+                       </xsl:when>\r
+                       <xsl:otherwise>naf</xsl:otherwise>\r
+               </xsl:choose>\r
+       </xsl:variable>\r
+       <xsl:variable name="controlField008" select="marc:controlfield[@tag='008']"/>\r
+       <xsl:variable name="controlField008-06"\r
+               select="substring(descendant-or-self::marc:controlfield[@tag=008],7,1)"/>\r
+       <xsl:variable name="controlField008-11"\r
+               select="substring(descendant-or-self::marc:controlfield[@tag=008],12,1)"/>\r
+       <xsl:variable name="controlField008-14"\r
+               select="substring(descendant-or-self::marc:controlfield[@tag=008],15,1)"/>\r
+       <xsl:template match="/">\r
+               <xsl:choose>\r
+                       <xsl:when test="descendant-or-self::marc:collection">\r
+                               <mads:madsCollection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
+                                       xsi:schemaLocation="http://www.loc.gov/mads/v2 http://www.loc.gov/standards/mads/v2/mads-2-0.xsd">\r
+                                       <xsl:for-each select="descendant-or-self::marc:collection/marc:record">\r
+                                               <mads:mads version="2.0">\r
+                                                       <xsl:call-template name="marcRecord"/>\r
+                                               </mads:mads>\r
+                                       </xsl:for-each>\r
+                               </mads:madsCollection>\r
+                       </xsl:when>\r
+                       <xsl:otherwise>\r
+                               <mads:mads version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
+                                       xsi:schemaLocation="http://www.loc.gov/mads/v2 http://www.loc.gov/standards/mads/mads-2-0.xsd">\r
+                                       <xsl:for-each select="descendant-or-self::marc:record">\r
+                                               <xsl:call-template name="marcRecord"/>\r
+                                       </xsl:for-each>\r
+                               </mads:mads>\r
+                       </xsl:otherwise>\r
+               </xsl:choose>\r
+       </xsl:template>\r
+\r
+       <xsl:template name="marcRecord">\r
+               <mads:authority>\r
+                       <!-- 2.04 -->\r
+                       <xsl:choose>\r
+                               <xsl:when test="$controlField008-06='d'">\r
+                                       <xsl:attribute name="geographicSubdivision">\r
+                                               <xsl:text>direct</xsl:text>\r
+                                       </xsl:attribute>\r
+                               </xsl:when>\r
+                               <xsl:when test="$controlField008-06='i'">\r
+                                       <xsl:attribute name="geographicSubdivision">\r
+                                               <xsl:text>indirect</xsl:text>\r
+                                       </xsl:attribute>\r
+                               </xsl:when>\r
+                               <xsl:when test="$controlField008-06='n'">\r
+                                       <xsl:attribute name="geographicSubdivision">\r
+                                               <xsl:text>not applicable</xsl:text>\r
+                                       </xsl:attribute>\r
+                               </xsl:when>\r
+                       </xsl:choose>\r
+                       \r
+                       <xsl:apply-templates select="marc:datafield[100 &lt;= @tag  and @tag &lt; 200]"/>               \r
+               </mads:authority>\r
+\r
+               <!-- related -->\r
+               <xsl:apply-templates\r
+                       select="marc:datafield[500 &lt;= @tag and @tag &lt;= 585]|marc:datafield[700 &lt;= @tag and @tag &lt;= 785]"/>\r
+\r
+               <!-- variant -->\r
+               <xsl:apply-templates select="marc:datafield[400 &lt;= @tag and @tag &lt;= 485]"/>\r
+\r
+               <!-- notes -->\r
+               <xsl:apply-templates select="marc:datafield[667 &lt;= @tag and @tag &lt;= 688]"/>\r
+\r
+               <!-- url -->\r
+               <xsl:apply-templates select="marc:datafield[@tag=856]"/>\r
+               <xsl:apply-templates select="marc:datafield[@tag=010]"/>\r
+               <xsl:apply-templates select="marc:datafield[@tag=024]"/>\r
+               <xsl:apply-templates select="marc:datafield[@tag=372]"/>\r
+               \r
+               <!-- classification -->\r
+               <xsl:apply-templates select="marc:datafield[@tag=053]"/>\r
+               <xsl:apply-templates select="marc:datafield[@tag=055]"/>\r
+               <xsl:apply-templates select="marc:datafield[@tag=060]"/>\r
+               <xsl:apply-templates select="marc:datafield[@tag=065]"/>\r
+               <xsl:apply-templates select="marc:datafield[@tag=070]"/>\r
+               <xsl:apply-templates select="marc:datafield[@tag=080]"/>\r
+               <xsl:apply-templates select="marc:datafield[@tag=082]"/>\r
+               <xsl:apply-templates select="marc:datafield[@tag=083]"/>\r
+               <xsl:apply-templates select="marc:datafield[@tag=086]"/>\r
+               <xsl:apply-templates select="marc:datafield[@tag=087]"/>\r
+\r
+               <!-- affiliation-->\r
+               <xsl:for-each select="marc:datafield[@tag=373]">\r
+                       <mads:affiliation>\r
+                               <mads:position>\r
+                                       <xsl:value-of select="marc:subfield[@code='a']"/>\r
+                               </mads:position>\r
+                               <mads:dateValid point="start">\r
+                                       <xsl:value-of select="marc:subfield[@code='s']"/>\r
+                               </mads:dateValid>\r
+                               <mads:dateValid point="end">\r
+                                       <xsl:value-of select="marc:subfield[@code='t']"/>\r
+                               </mads:dateValid>\r
+                       </mads:affiliation>\r
+               </xsl:for-each>\r
+               <xsl:for-each select="marc:datafield[@tag=371]">\r
+                       <mads:affiliation>\r
+                               <mads:address>\r
+                                       <mads:street>\r
+                                               <xsl:value-of select="marc:subfield[@code='a']"/>\r
+                                       </mads:street>\r
+                                       <mads:city>\r
+                                               <xsl:value-of select="marc:subfield[@code='b']"/>\r
+                                       </mads:city>\r
+                                       <mads:state>\r
+                                               <xsl:value-of select="marc:subfield[@code='c']"/>\r
+                                       </mads:state>\r
+                                       <mads:country>\r
+                                               <xsl:value-of select="marc:subfield[@code='d']"/>\r
+                                       </mads:country>\r
+                                       <mads:postcode>\r
+                                               <xsl:value-of select="marc:subfield[@code='e']"/>\r
+                                       </mads:postcode>\r
+                               </mads:address>\r
+                               <mads:email>\r
+                                       <xsl:value-of select="marc:subfield[@code='m']"/>\r
+                               </mads:email>\r
+                       </mads:affiliation>\r
+               </xsl:for-each>\r
+\r
+               <!-- extension-->\r
+               <xsl:for-each select="marc:datafield[@tag=336]">\r
+                       <mads:extension>\r
+                               <mads:contentType>\r
+                                       <mads:contentType type="text">\r
+                                               <xsl:value-of select="marc:subfield[@code='a']"/>\r
+                                       </mads:contentType>\r
+                                       <mads:contentType type="code">\r
+                                               <xsl:value-of select="marc:subfield[@code='b']"/>\r
+                                       </mads:contentType>\r
+                               </mads:contentType>\r
+                       </mads:extension>\r
+               </xsl:for-each>\r
+\r
+               <xsl:for-each select="marc:datafield[@tag=374]">\r
+                       <mads:extension>\r
+                               <mads:profession>\r
+                                       <xsl:choose>\r
+                                               <xsl:when test="marc:subfield[@code='a']">\r
+                                                       <mads:professionTerm>\r
+                                                               <xsl:value-of select="marc:subfield[@code='a']"/>\r
+                                                       </mads:professionTerm>\r
+                                               </xsl:when>\r
+                                               <xsl:when test="marc:subfield[@code='s']">\r
+                                                       <mads:dateValid point="start">\r
+                                                               <xsl:value-of select="marc:subfield[@code='s']"/>\r
+                                                       </mads:dateValid>\r
+                                               </xsl:when>\r
+                                               <xsl:when test="marc:subfield[@code='t']">\r
+                                                       <mads:dateValid point="end">\r
+                                                               <xsl:value-of select="marc:subfield[@code='t']"/>\r
+                                                       </mads:dateValid>\r
+                                               </xsl:when>\r
+                                       </xsl:choose>\r
+                               </mads:profession>\r
+                       </mads:extension>\r
+               </xsl:for-each>\r
+               \r
+               <xsl:for-each select="marc:datafield[@tag=375]">\r
+                       <mads:extension>\r
+                               <mads:gender>\r
+                                       <xsl:choose>\r
+                                               <xsl:when test="marc:subfield[@code='a']">\r
+                                                       <mads:genderTerm>\r
+                                                               <xsl:value-of select="marc:subfield[@code='a']"/>\r
+                                                       </mads:genderTerm>\r
+                                               </xsl:when>\r
+                                               <xsl:when test="marc:subfield[@code='s']">\r
+                                                       <mads:dateValid point="start">\r
+                                                               <xsl:value-of select="marc:subfield[@code='s']"/>\r
+                                                       </mads:dateValid>\r
+                                               </xsl:when>\r
+                                               <xsl:when test="marc:subfield[@code='t']">\r
+                                                       <mads:dateValid point="end">\r
+                                                               <xsl:value-of select="marc:subfield[@code='t']"/>\r
+                                                       </mads:dateValid>\r
+                                               </xsl:when>\r
+                                       </xsl:choose>\r
+                               </mads:gender>\r
+                       </mads:extension>\r
+               </xsl:for-each>\r
+\r
+               <xsl:for-each select="marc:datafield[@tag=376]">\r
+                       <mads:extension>\r
+                               <mads:familyInformation>\r
+                                       <mads:typeOfFamily>\r
+                                               <xsl:value-of select="marc:subfield[@code='a']"/>\r
+                                       </mads:typeOfFamily>\r
+                                       <mads:nameOfProminentMember>\r
+                                               <xsl:value-of select="marc:subfield[@code='b']"/>\r
+                                       </mads:nameOfProminentMember>\r
+                                       <mads:hereditaryTitle>\r
+                                               <xsl:value-of select="marc:subfield[@code='c']"/>\r
+                                       </mads:hereditaryTitle>\r
+                                       <mads:dateValid point="start">\r
+                                               <xsl:value-of select="marc:subfield[@code='s']"/>\r
+                                       </mads:dateValid>\r
+                                       <mads:dateValid point="end">\r
+                                               <xsl:value-of select="marc:subfield[@code='t']"/>\r
+                                       </mads:dateValid>\r
+                               </mads:familyInformation>\r
+                       </mads:extension>\r
+               </xsl:for-each>\r
+\r
+               <mads:recordInfo>\r
+                       <mads:recordOrigin>Converted from MARCXML to MADS version 2.0 (Revision 2.13)</mads:recordOrigin>\r
+                       <!-- <xsl:apply-templates select="marc:datafield[@tag=024]"/> -->\r
+\r
+                       <xsl:apply-templates select="marc:datafield[@tag=040]/marc:subfield[@code='a']"/>\r
+                       <xsl:apply-templates select="marc:controlfield[@tag=005]"/>\r
+                       <xsl:apply-templates select="marc:controlfield[@tag=001]"/>\r
+                       <xsl:apply-templates select="marc:datafield[@tag=040]/marc:subfield[@code='b']"/>\r
+                       <xsl:apply-templates select="marc:datafield[@tag=040]/marc:subfield[@code='e']"/>\r
+                       <xsl:for-each select="marc:controlfield[@tag=008]">\r
+                               <xsl:if test="substring(.,11,1)='a'">\r
+                                       <mads:descriptionStandard>\r
+                                               <xsl:text>earlier rules</xsl:text>\r
+                                       </mads:descriptionStandard>\r
+                               </xsl:if>\r
+                               <xsl:if test="substring(.,11,1)='b'">\r
+                                       <mads:descriptionStandard>\r
+                                               <xsl:text>aacr1</xsl:text>\r
+                                       </mads:descriptionStandard>\r
+                               </xsl:if>\r
+                               <xsl:if test="substring(.,11,1)='c'">\r
+                                       <mads:descriptionStandard>\r
+                                               <xsl:text>aacr2</xsl:text>\r
+                                       </mads:descriptionStandard>\r
+                               </xsl:if>\r
+                               <xsl:if test="substring(.,11,1)='d'">\r
+                                       <mads:descriptionStandard>\r
+                                               <xsl:text>aacr2 compatible</xsl:text>\r
+                                       </mads:descriptionStandard>\r
+                               </xsl:if>\r
+                               <xsl:if test="substring(.,11,1)='z'">\r
+                                       <mads:descriptionStandard>\r
+                                               <xsl:text>other rules</xsl:text>\r
+                                       </mads:descriptionStandard>\r
+                               </xsl:if>\r
+                       </xsl:for-each>\r
+               </mads:recordInfo>\r
+       </xsl:template>\r
+\r
+       <!-- start of secondary templates -->\r
+\r
+       <!-- ======== xlink ======== -->\r
+\r
+       <!-- <xsl:template name="uri"> \r
+    <xsl:for-each select="marc:subfield[@code='0']">\r
+      <xsl:attribute name="xlink:href">\r
+       <xsl:value-of select="."/>\r
+      </xsl:attribute>\r
+    </xsl:for-each>\r
+     </xsl:template> \r
+   -->\r
+       <xsl:template match="marc:subfield[@code='i']">\r
+               <xsl:attribute name="otherType">\r
+                       <xsl:value-of select="."/>\r
+               </xsl:attribute>\r
+       </xsl:template>\r
+\r
+       <!-- No role/roleTerm mapped in MADS 06/24/2010\r
+       <xsl:template name="role">\r
+               <xsl:for-each select="marc:subfield[@code='e']">\r
+                       <mads:role>\r
+                               <mads:roleTerm type="text">\r
+                                       <xsl:value-of select="."/>\r
+                               </mads:roleTerm>\r
+                       </mads:role>\r
+               </xsl:for-each>\r
+       </xsl:template>\r
+-->\r
+\r
+       <xsl:template name="part">\r
+               <xsl:variable name="partNumber">\r
+                       <xsl:call-template name="specialSubfieldSelect">\r
+                               <xsl:with-param name="axis">n</xsl:with-param>\r
+                               <xsl:with-param name="anyCodes">n</xsl:with-param>\r
+                               <xsl:with-param name="afterCodes">fghkdlmor</xsl:with-param>\r
+                       </xsl:call-template>\r
+               </xsl:variable>\r
+               <xsl:variable name="partName">\r
+                       <xsl:call-template name="specialSubfieldSelect">\r
+                               <xsl:with-param name="axis">p</xsl:with-param>\r
+                               <xsl:with-param name="anyCodes">p</xsl:with-param>\r
+                               <xsl:with-param name="afterCodes">fghkdlmor</xsl:with-param>\r
+                       </xsl:call-template>\r
+               </xsl:variable>\r
+               <xsl:if test="string-length(normalize-space($partNumber))">\r
+                       <mads:partNumber>\r
+                               <xsl:call-template name="chopPunctuation">\r
+                                       <xsl:with-param name="chopString" select="$partNumber"/>\r
+                               </xsl:call-template>\r
+                       </mads:partNumber>\r
+               </xsl:if>\r
+               <xsl:if test="string-length(normalize-space($partName))">\r
+                       <mads:partName>\r
+                               <xsl:call-template name="chopPunctuation">\r
+                                       <xsl:with-param name="chopString" select="$partName"/>\r
+                               </xsl:call-template>\r
+                       </mads:partName>\r
+               </xsl:if>\r
+       </xsl:template>\r
+\r
+       <xsl:template name="nameABCDN">\r
+               <xsl:for-each select="marc:subfield[@code='a']">\r
+                       <mads:namePart>\r
+                               <xsl:call-template name="chopPunctuation">\r
+                                       <xsl:with-param name="chopString" select="."/>\r
+                               </xsl:call-template>\r
+                       </mads:namePart>\r
+               </xsl:for-each>\r
+               <xsl:for-each select="marc:subfield[@code='b']">\r
+                       <mads:namePart>\r
+                               <xsl:value-of select="."/>\r
+                       </mads:namePart>\r
+               </xsl:for-each>\r
+               <xsl:if\r
+                       test="marc:subfield[@code='c'] or marc:subfield[@code='d'] or marc:subfield[@code='n']">\r
+                       <mads:namePart>\r
+                               <xsl:call-template name="subfieldSelect">\r
+                                       <xsl:with-param name="codes">cdn</xsl:with-param>\r
+                               </xsl:call-template>\r
+                       </mads:namePart>\r
+               </xsl:if>\r
+       </xsl:template>\r
+\r
+       <xsl:template name="nameABCDQ">\r
+               <mads:namePart>\r
+                       <xsl:call-template name="chopPunctuation">\r
+                               <xsl:with-param name="chopString">\r
+                                       <xsl:call-template name="subfieldSelect">\r
+                                               <xsl:with-param name="codes">aq</xsl:with-param>\r
+                                       </xsl:call-template>\r
+                               </xsl:with-param>\r
+                       </xsl:call-template>\r
+               </mads:namePart>\r
+               <xsl:call-template name="termsOfAddress"/>\r
+               <xsl:call-template name="nameDate"/>\r
+       </xsl:template>\r
+\r
+       <xsl:template name="nameACDENQ">\r
+               <mads:namePart>\r
+                       <xsl:call-template name="subfieldSelect">\r
+                               <xsl:with-param name="codes">acdenq</xsl:with-param>\r
+                       </xsl:call-template>\r
+               </mads:namePart>\r
+       </xsl:template>\r
+\r
+       <xsl:template name="nameDate">\r
+               <xsl:for-each select="marc:subfield[@code='d']">\r
+                       <mads:namePart type="date">\r
+                               <xsl:call-template name="chopPunctuation">\r
+                                       <xsl:with-param name="chopString" select="."/>\r
+                               </xsl:call-template>\r
+                       </mads:namePart>\r
+               </xsl:for-each>\r
+       </xsl:template>\r
+\r
+       <xsl:template name="specialSubfieldSelect">\r
+               <xsl:param name="anyCodes"/>\r
+               <xsl:param name="axis"/>\r
+               <xsl:param name="beforeCodes"/>\r
+               <xsl:param name="afterCodes"/>\r
+               <xsl:variable name="str">\r
+                       <xsl:for-each select="marc:subfield">\r
+                               <xsl:if\r
+                                       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])">\r
+                                       <xsl:value-of select="text()"/>\r
+                                       <xsl:text> </xsl:text>\r
+                               </xsl:if>\r
+                       </xsl:for-each>\r
+               </xsl:variable>\r
+               <xsl:value-of select="substring($str,1,string-length($str)-1)"/>\r
+       </xsl:template>\r
+\r
+       <xsl:template name="termsOfAddress">\r
+               <xsl:if test="marc:subfield[@code='b' or @code='c']">\r
+                       <mads:namePart type="termsOfAddress">\r
+                               <xsl:call-template name="chopPunctuation">\r
+                                       <xsl:with-param name="chopString">\r
+                                               <xsl:call-template name="subfieldSelect">\r
+                                                       <xsl:with-param name="codes">bc</xsl:with-param>\r
+                                               </xsl:call-template>\r
+                                       </xsl:with-param>\r
+                               </xsl:call-template>\r
+                       </mads:namePart>\r
+               </xsl:if>\r
+       </xsl:template>\r
+\r
+       <xsl:template name="displayLabel">\r
+               <xsl:if test="marc:subfield[@code='z']">\r
+                       <xsl:attribute name="displayLabel">\r
+                               <xsl:value-of select="marc:subfield[@code='z']"/>\r
+                       </xsl:attribute>\r
+               </xsl:if>\r
+               <xsl:if test="marc:subfield[@code='3']">\r
+                       <xsl:attribute name="displayLabel">\r
+                               <xsl:value-of select="marc:subfield[@code='3']"/>\r
+                       </xsl:attribute>\r
+               </xsl:if>\r
+       </xsl:template>\r
+\r
+       <xsl:template name="isInvalid">\r
+               <xsl:if test="@code='z'">\r
+                       <xsl:attribute name="invalid">yes</xsl:attribute>\r
+               </xsl:if>\r
+       </xsl:template>\r
+\r
+       <xsl:template name="sub2Attribute">\r
+               <!-- 024 -->\r
+               <xsl:if test="../marc:subfield[@code='2']">\r
+                       <xsl:attribute name="type">\r
+                               <xsl:value-of select="../marc:subfield[@code='2']"/>\r
+                       </xsl:attribute>\r
+               </xsl:if>\r
+       </xsl:template>\r
+\r
+       <xsl:template match="marc:controlfield[@tag=001]">\r
+               <mads:recordIdentifier>\r
+                       <xsl:if test="../marc:controlfield[@tag=003]">\r
+                               <xsl:attribute name="source">\r
+                                       <xsl:value-of select="../marc:controlfield[@tag=003]"/>\r
+                               </xsl:attribute>\r
+                       </xsl:if>\r
+                       <xsl:value-of select="."/>\r
+               </mads:recordIdentifier>\r
+       </xsl:template>\r
+\r
+       <xsl:template match="marc:controlfield[@tag=005]">\r
+               <mads:recordChangeDate encoding="iso8601">\r
+                       <xsl:value-of select="."/>\r
+               </mads:recordChangeDate>\r
+       </xsl:template>\r
+\r
+       <xsl:template match="marc:controlfield[@tag=008]">\r
+               <mads:recordCreationDate encoding="marc">\r
+                       <xsl:value-of select="substring(.,1,6)"/>\r
+               </mads:recordCreationDate>\r
+       </xsl:template>\r
+\r
+       <xsl:template match="marc:datafield[@tag=010]">\r
+               <xsl:for-each select="marc:subfield">\r
+                       <mads:identifier type="lccn">\r
+                               <xsl:call-template name="isInvalid"/>\r
+                               <xsl:value-of select="."/>\r
+                       </mads:identifier>\r
+               </xsl:for-each>\r
+       </xsl:template>\r
+\r
+       <xsl:template match="marc:datafield[@tag=024]">\r
+               <xsl:for-each select="marc:subfield[not(@code=2)]">\r
+                       <mads:identifier>\r
+                               <xsl:call-template name="isInvalid"/>\r
+                               <xsl:call-template name="sub2Attribute"/>\r
+                               <xsl:value-of select="."/>\r
+                       </mads:identifier>\r
+               </xsl:for-each>\r
+       </xsl:template>\r
+\r
+       <!-- ========== 372 ========== -->\r
+       <xsl:template match="marc:datafield[@tag=372]">\r
+               <mads:fieldOfActivity>\r
+                       <xsl:call-template name="subfieldSelect">\r
+                               <xsl:with-param name="codes">a</xsl:with-param>\r
+                       </xsl:call-template>\r
+                       <xsl:text>-</xsl:text>\r
+                       <xsl:call-template name="subfieldSelect">\r
+                               <xsl:with-param name="codes">st</xsl:with-param>\r
+                       </xsl:call-template>\r
+               </mads:fieldOfActivity>\r
+       </xsl:template>\r
+\r
+\r
+       <!-- ========== 040 ========== -->\r
+       <xsl:template match="marc:datafield[@tag=040]/marc:subfield[@code='a']">\r
+               <mads:recordContentSource authority="marcorg">\r
+                       <xsl:value-of select="."/>\r
+               </mads:recordContentSource>\r
+       </xsl:template>\r
+\r
+       <xsl:template match="marc:datafield[@tag=040]/marc:subfield[@code='b']">\r
+               <mads:languageOfCataloging>\r
+                       <mads:languageTerm authority="iso639-2b" type="code">\r
+                               <xsl:value-of select="."/>\r
+                       </mads:languageTerm>\r
+               </mads:languageOfCataloging>\r
+       </xsl:template>\r
+\r
+       <xsl:template match="marc:datafield[@tag=040]/marc:subfield[@code='e']">\r
+               <mads:descriptionStandard>\r
+                       <xsl:value-of select="."/>\r
+               </mads:descriptionStandard>\r
+       </xsl:template>\r
+       \r
+       <!-- ========== classification 2.03 ========== -->\r
+       \r
+       <xsl:template match="marc:datafield[@tag=053]">\r
+               <mads:classification>\r
+                       <xsl:call-template name="subfieldSelect">\r
+                               <xsl:with-param name="codes">abcdxyz</xsl:with-param>\r
+                               <xsl:with-param name="delimeter">-</xsl:with-param>\r
+                       </xsl:call-template>\r
+               </mads:classification>\r
+       </xsl:template>\r
+       \r
+       <xsl:template match="marc:datafield[@tag=055]">\r
+               <mads:classification>\r
+                       <xsl:call-template name="subfieldSelect">\r
+                               <xsl:with-param name="codes">abcdxyz</xsl:with-param>\r
+                               <xsl:with-param name="delimeter">-</xsl:with-param>\r
+                       </xsl:call-template>\r
+               </mads:classification>\r
+       </xsl:template>\r
+       \r
+       <xsl:template match="marc:datafield[@tag=060]">\r
+               <mads:classification>\r
+                       <xsl:call-template name="subfieldSelect">\r
+                               <xsl:with-param name="codes">abcdxyz</xsl:with-param>\r
+                               <xsl:with-param name="delimeter">-</xsl:with-param>\r
+                       </xsl:call-template>\r
+               </mads:classification>\r
+       </xsl:template>\r
+       <xsl:template match="marc:datafield[@tag=065]">\r
+               <mads:classification>\r
+                       <xsl:attribute name="authority">\r
+                               <xsl:value-of select="marc:subfield[@code='2']"/>\r
+                       </xsl:attribute>\r
+                       <xsl:call-template name="subfieldSelect">\r
+                               <xsl:with-param name="codes">abcdxyz</xsl:with-param>\r
+                               <xsl:with-param name="delimeter">-</xsl:with-param>\r
+                       </xsl:call-template>\r
+               </mads:classification>\r
+       </xsl:template>\r
+       <xsl:template match="marc:datafield[@tag=070]">\r
+               <mads:classification>\r
+                       <xsl:call-template name="subfieldSelect">\r
+                               <xsl:with-param name="codes">abcdxyz5</xsl:with-param>\r
+                               <xsl:with-param name="delimeter">-</xsl:with-param>\r
+                       </xsl:call-template>\r
+               </mads:classification>\r
+       </xsl:template>\r
+       <xsl:template match="marc:datafield[@tag=080]">\r
+               <mads:classification>\r
+                       <xsl:attribute name="authority">\r
+                               <xsl:value-of select="marc:subfield[@code='2']"/>\r
+                       </xsl:attribute>\r
+                       <xsl:call-template name="subfieldSelect">\r
+                               <xsl:with-param name="codes">abcdxyz5</xsl:with-param>\r
+                               <xsl:with-param name="delimeter">-</xsl:with-param>\r
+                       </xsl:call-template>\r
+               </mads:classification>\r
+       </xsl:template>\r
+       <xsl:template match="marc:datafield[@tag=082]">\r
+               <mads:classification>\r
+                       <xsl:attribute name="authority">\r
+                               <xsl:value-of select="marc:subfield[@code='2']"/>\r
+                       </xsl:attribute>\r
+                       <xsl:call-template name="subfieldSelect">\r
+                               <xsl:with-param name="codes">abcdxyz5</xsl:with-param>\r
+                               <xsl:with-param name="delimeter">-</xsl:with-param>\r
+                       </xsl:call-template>\r
+               </mads:classification>\r
+       </xsl:template>\r
+       <xsl:template match="marc:datafield[@tag=083]">\r
+               <mads:classification>\r
+                       <xsl:attribute name="authority">\r
+                               <xsl:value-of select="marc:subfield[@code='2']"/>\r
+                       </xsl:attribute>\r
+                       <xsl:call-template name="subfieldSelect">\r
+                               <xsl:with-param name="codes">abcdxyz5</xsl:with-param>\r
+                               <xsl:with-param name="delimeter">-</xsl:with-param>\r
+                       </xsl:call-template>\r
+               </mads:classification>\r
+       </xsl:template>\r
+       <xsl:template match="marc:datafield[@tag=086]">\r
+               <mads:classification>\r
+                       <xsl:attribute name="authority">\r
+                               <xsl:value-of select="marc:subfield[@code='2']"/>\r
+                       </xsl:attribute>\r
+                       <xsl:call-template name="subfieldSelect">\r
+                               <xsl:with-param name="codes">abcdxyz5</xsl:with-param>\r
+                               <xsl:with-param name="delimeter">-</xsl:with-param>\r
+                       </xsl:call-template>\r
+               </mads:classification>\r
+       </xsl:template>\r
+       <xsl:template match="marc:datafield[@tag=087]">\r
+               <mads:classification>\r
+                       <xsl:attribute name="authority">\r
+                               <xsl:value-of select="marc:subfield[@code='2']"/>\r
+                       </xsl:attribute>\r
+                       <xsl:call-template name="subfieldSelect">\r
+                               <xsl:with-param name="codes">abcdxyz5</xsl:with-param>\r
+                               <xsl:with-param name="delimeter">-</xsl:with-param>\r
+                       </xsl:call-template>\r
+               </mads:classification>\r
+       </xsl:template>\r
+       \r
+\r
+       <!-- ========== names  ========== -->\r
+       <xsl:template match="marc:datafield[@tag=100]">\r
+               <mads:name type="personal">\r
+                       <xsl:call-template name="setAuthority"/>\r
+                       <xsl:call-template name="nameABCDQ"/>\r
+               </mads:name>\r
+               <xsl:apply-templates select="*[marc:subfield[not(contains('abcdeq',@code))]]"/>\r
+               <xsl:call-template name="title"/>\r
+               <xsl:apply-templates select="marc:subfield[@code!='i']"/>\r
+       </xsl:template>\r
+\r
+       <xsl:template match="marc:datafield[@tag=110]">\r
+               <mads:name type="corporate">\r
+                       <xsl:call-template name="setAuthority"/>\r
+                       <xsl:call-template name="nameABCDN"/>\r
+               </mads:name>\r
+               <xsl:apply-templates select="marc:subfield[@code!='i']"/>\r
+       </xsl:template>\r
+\r
+       <xsl:template match="marc:datafield[@tag=111]">\r
+               <mads:name type="conference">\r
+                       <xsl:call-template name="setAuthority"/>\r
+                       <xsl:call-template name="nameACDENQ"/>\r
+               </mads:name>\r
+               <xsl:apply-templates select="marc:subfield[@code!='i']"/>\r
+       </xsl:template>\r
+\r
+       <xsl:template match="marc:datafield[@tag=400]">\r
+               <mads:variant>\r
+                       <xsl:call-template name="variantTypeAttribute"/>\r
+                       <mads:name type="personal">\r
+                               <xsl:call-template name="nameABCDQ"/>\r
+                       </mads:name>\r
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>\r
+                       <xsl:call-template name="title"/>\r
+               </mads:variant>\r
+       </xsl:template>\r
+\r
+       <xsl:template match="marc:datafield[@tag=410]">\r
+               <mads:variant>\r
+                       <xsl:call-template name="variantTypeAttribute"/>\r
+                       <mads:name type="corporate">\r
+                               <xsl:call-template name="nameABCDN"/>\r
+                       </mads:name>\r
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>\r
+               </mads:variant>\r
+       </xsl:template>\r
+\r
+       <xsl:template match="marc:datafield[@tag=411]">\r
+               <mads:variant>\r
+                       <xsl:call-template name="variantTypeAttribute"/>\r
+                       <mads:name type="conference">\r
+                               <xsl:call-template name="nameACDENQ"/>\r
+                       </mads:name>\r
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>\r
+               </mads:variant>\r
+       </xsl:template>\r
+\r
+       <xsl:template match="marc:datafield[@tag=500]|marc:datafield[@tag=700]">\r
+               <mads:related>\r
+                       <xsl:call-template name="relatedTypeAttribute"/>\r
+                       <!-- <xsl:call-template name="uri"/> -->\r
+                       <mads:name type="personal">\r
+                               <xsl:call-template name="setAuthority"/>\r
+                               <xsl:call-template name="nameABCDQ"/>\r
+                       </mads:name>\r
+                       <xsl:call-template name="title"/>\r
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>\r
+               </mads:related>\r
+       </xsl:template>\r
+\r
+       <xsl:template match="marc:datafield[@tag=510]|marc:datafield[@tag=710]">\r
+               <mads:related>\r
+                       <xsl:call-template name="relatedTypeAttribute"/>\r
+                       <!-- <xsl:call-template name="uri"/> -->\r
+                       <mads:name type="corporate">\r
+                               <xsl:call-template name="setAuthority"/>\r
+                               <xsl:call-template name="nameABCDN"/>\r
+                       </mads:name>\r
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>\r
+               </mads:related>\r
+       </xsl:template>\r
+\r
+       <xsl:template match="marc:datafield[@tag=511]|marc:datafield[@tag=711]">\r
+               <mads:related>\r
+                       <xsl:call-template name="relatedTypeAttribute"/>\r
+                       <!-- <xsl:call-template name="uri"/> -->\r
+                       <mads:name type="conference">\r
+                               <xsl:call-template name="setAuthority"/>\r
+                               <xsl:call-template name="nameACDENQ"/>\r
+                       </mads:name>\r
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>\r
+               </mads:related>\r
+       </xsl:template>\r
+\r
+       <!-- ========== titles  ========== -->\r
+       <xsl:template match="marc:datafield[@tag=130]">\r
+               <xsl:call-template name="uniform-title"/>\r
+               <xsl:apply-templates select="marc:subfield[@code!='i']"/>\r
+       </xsl:template>\r
+\r
+       <xsl:template match="marc:datafield[@tag=430]">\r
+               <mads:variant>\r
+                       <xsl:call-template name="variantTypeAttribute"/>\r
+                       <xsl:call-template name="uniform-title"/>\r
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>\r
+               </mads:variant>\r
+       </xsl:template>\r
+\r
+       <xsl:template match="marc:datafield[@tag=530]|marc:datafield[@tag=730]">\r
+               <mads:related>\r
+                       <xsl:call-template name="relatedTypeAttribute"/>\r
+                       <xsl:call-template name="uniform-title"/>\r
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>\r
+               </mads:related>\r
+       </xsl:template>\r
+\r
+       <xsl:template name="title">\r
+               <xsl:variable name="hasTitle">\r
+                       <xsl:for-each select="marc:subfield">\r
+                               <xsl:if test="(contains('tfghklmors',@code) )">\r
+                                       <xsl:value-of select="@code"/>\r
+                               </xsl:if>\r
+                       </xsl:for-each>\r
+               </xsl:variable>\r
+               <xsl:if test="string-length($hasTitle) &gt; 0 ">\r
+                       <mads:titleInfo>\r
+                               <xsl:call-template name="setAuthority"/>\r
+                               <mads:title>\r
+                                       <xsl:variable name="str">\r
+                                               <xsl:for-each select="marc:subfield">\r
+                                                       <xsl:if test="(contains('atfghklmors',@code) )">\r
+                                                               <xsl:value-of select="text()"/>\r
+                                                               <xsl:text> </xsl:text>\r
+                                                       </xsl:if>\r
+                                               </xsl:for-each>\r
+                                       </xsl:variable>\r
+                                       <xsl:call-template name="chopPunctuation">\r
+                                               <xsl:with-param name="chopString">\r
+                                                       <xsl:value-of select="substring($str,1,string-length($str)-1)"/>\r
+                                               </xsl:with-param>\r
+                                       </xsl:call-template>\r
+                               </mads:title>\r
+                               <xsl:call-template name="part"/>\r
+                               <!-- <xsl:call-template name="uri"/> -->\r
+                       </mads:titleInfo>\r
+               </xsl:if>\r
+       </xsl:template>\r
+\r
+       <xsl:template name="uniform-title">\r
+               <xsl:variable name="hasTitle">\r
+                       <xsl:for-each select="marc:subfield">\r
+                               <xsl:if test="(contains('atfghklmors',@code) )">\r
+                                       <xsl:value-of select="@code"/>\r
+                               </xsl:if>\r
+                       </xsl:for-each>\r
+               </xsl:variable>\r
+               <xsl:if test="string-length($hasTitle) &gt; 0 ">\r
+                       <mads:titleInfo>\r
+                               <xsl:call-template name="setAuthority"/>\r
+                               <mads:title>\r
+                                       <xsl:variable name="str">\r
+                                               <xsl:for-each select="marc:subfield">\r
+                                                       <xsl:if test="(contains('adfghklmors',@code) )">\r
+                                                               <xsl:value-of select="text()"/>\r
+                                                               <xsl:text> </xsl:text>\r
+                                                       </xsl:if>\r
+                                               </xsl:for-each>\r
+                                       </xsl:variable>\r
+                                       <xsl:call-template name="chopPunctuation">\r
+                                               <xsl:with-param name="chopString">\r
+                                                       <xsl:value-of select="substring($str,1,string-length($str)-1)"/>\r
+                                               </xsl:with-param>\r
+                                       </xsl:call-template>\r
+                               </mads:title>\r
+                               <xsl:call-template name="part"/>\r
+                               <!-- <xsl:call-template name="uri"/> -->\r
+                       </mads:titleInfo>\r
+               </xsl:if>\r
+       </xsl:template>\r
+\r
+\r
+       <!-- ========== topics  ========== -->\r
+       <xsl:template match="marc:subfield[@code='x']">\r
+               <mads:topic>\r
+                       <xsl:call-template name="chopPunctuation">\r
+                               <xsl:with-param name="chopString">\r
+                                       <xsl:value-of select="."/>\r
+                               </xsl:with-param>\r
+                       </xsl:call-template>\r
+               </mads:topic>\r
+       </xsl:template>\r
+       \r
+       <!-- 2.06 fix -->\r
+       <xsl:template\r
+               match="marc:datafield[@tag=150][marc:subfield[@code='a' or @code='b']]|marc:datafield[@tag=180][marc:subfield[@code='x']]">\r
+               <xsl:call-template name="topic"/>\r
+               <xsl:apply-templates select="marc:subfield[@code!='i']"/>\r
+       </xsl:template>\r
+       <xsl:template\r
+               match="marc:datafield[@tag=450][marc:subfield[@code='a' or @code='b']]|marc:datafield[@tag=480][marc:subfield[@code='x']]">\r
+               <mads:variant>\r
+                       <xsl:call-template name="variantTypeAttribute"/>\r
+                       <xsl:call-template name="topic"/>\r
+               </mads:variant>\r
+       </xsl:template>\r
+       <xsl:template\r
+               match="marc:datafield[@tag=550 or @tag=750][marc:subfield[@code='a' or @code='b']]">\r
+               <mads:related>\r
+                       <xsl:call-template name="relatedTypeAttribute"/>\r
+                       <!-- <xsl:call-template name="uri"/> -->\r
+                       <xsl:call-template name="topic"/>\r
+                       <xsl:apply-templates select="marc:subfield[@code='z']"/>\r
+               </mads:related>\r
+       </xsl:template>\r
+       <xsl:template name="topic">\r
+               <mads:topic>\r
+                       <xsl:call-template name="setAuthority"/>\r
+                       <!-- tmee2006 dedupe 550a\r
+                       <xsl:if test="@tag=550 or @tag=750">\r
+                               <xsl:call-template name="subfieldSelect">\r
+                                       <xsl:with-param name="codes">ab</xsl:with-param>\r
+                               </xsl:call-template>\r
+                       </xsl:if>       \r
+                       -->\r
+                       <xsl:choose>\r
+                               <xsl:when test="@tag=180 or @tag=480 or @tag=580 or @tag=780">\r
+                                       <xsl:call-template name="chopPunctuation">\r
+                                               <xsl:with-param name="chopString">\r
+                                                       <xsl:apply-templates select="marc:subfield[@code='x']"/>\r
+                                               </xsl:with-param>\r
+                                       </xsl:call-template>\r
+                               </xsl:when>\r
+                       </xsl:choose>\r
+                       <xsl:call-template name="chopPunctuation">\r
+                               <xsl:with-param name="chopString">\r
+                                       <xsl:choose>\r
+                                               <xsl:when test="@tag=180 or @tag=480 or @tag=580 or @tag=780">\r
+                                                       <xsl:apply-templates select="marc:subfield[@code='x']"/>\r
+                                               </xsl:when>\r
+                                               <xsl:otherwise>\r
+                                                       <xsl:call-template name="subfieldSelect">\r
+                                                               <xsl:with-param name="codes">ab</xsl:with-param>\r
+                                                       </xsl:call-template>\r
+                                               </xsl:otherwise>\r
+                                       </xsl:choose>\r
+                               </xsl:with-param>\r
+                       </xsl:call-template>\r
+               </mads:topic>\r
+       </xsl:template>\r
+\r
+       <!-- ========= temporals  ========== -->\r
+       <xsl:template match="marc:subfield[@code='y']">\r
+               <mads:temporal>\r
+                       <xsl:call-template name="chopPunctuation">\r
+                               <xsl:with-param name="chopString">\r
+                                       <xsl:value-of select="."/>\r
+                               </xsl:with-param>\r
+                       </xsl:call-template>\r
+               </mads:temporal>\r
+       </xsl:template>\r
+       <xsl:template\r
+               match="marc:datafield[@tag=148][marc:subfield[@code='a']]|marc:datafield[@tag=182 ][marc:subfield[@code='y']]">\r
+               <xsl:call-template name="temporal"/>\r
+       </xsl:template>\r
+       <xsl:template\r
+               match="marc:datafield[@tag=448][marc:subfield[@code='a']]|marc:datafield[@tag=482][marc:subfield[@code='y']]">\r
+               <mads:variant>\r
+                       <xsl:call-template name="variantTypeAttribute"/>\r
+                       <xsl:call-template name="temporal"/>\r
+               </mads:variant>\r
+       </xsl:template>\r
+       <xsl:template\r
+               match="marc:datafield[@tag=548 or @tag=748][marc:subfield[@code='a']]|marc:datafield[@tag=582 or @tag=782][marc:subfield[@code='y']]">\r
+               <mads:related>\r
+                       <xsl:call-template name="relatedTypeAttribute"/>\r
+                       <!-- <xsl:call-template name="uri"/> -->\r
+                       <xsl:call-template name="temporal"/>\r
+               </mads:related>\r
+       </xsl:template>\r
+       <xsl:template name="temporal">\r
+               <mads:temporal>\r
+                       <xsl:call-template name="setAuthority"/>\r
+                       <xsl:if test="@tag=548 or @tag=748">\r
+                               <xsl:value-of select="marc:subfield[@code='a']"/>\r
+                       </xsl:if>\r
+                       <xsl:call-template name="chopPunctuation">\r
+                               <xsl:with-param name="chopString">\r
+                                       <xsl:choose>\r
+                                               <xsl:when test="@tag=182 or @tag=482 or @tag=582 or @tag=782">\r
+                                                       <xsl:apply-templates select="marc:subfield[@code='y']"/>\r
+                                               </xsl:when>\r
+                                               <xsl:otherwise>\r
+                                                       <xsl:value-of select="marc:subfield[@code='a']"/>\r
+                                               </xsl:otherwise>\r
+                                       </xsl:choose>\r
+                               </xsl:with-param>\r
+                       </xsl:call-template>\r
+               </mads:temporal>\r
+               <xsl:apply-templates select="marc:subfield[@code!='i']"/>\r
+       </xsl:template>\r
+\r
+       <!-- ========== genre  ========== -->\r
+       <xsl:template match="marc:subfield[@code='v']">\r
+               <mads:genre>\r
+                       <xsl:call-template name="chopPunctuation">\r
+                               <xsl:with-param name="chopString">\r
+                                       <xsl:value-of select="."/>\r
+                               </xsl:with-param>\r
+                       </xsl:call-template>\r
+               </mads:genre>\r
+       </xsl:template>\r
+       <xsl:template\r
+               match="marc:datafield[@tag=155][marc:subfield[@code='a']]|marc:datafield[@tag=185][marc:subfield[@code='v']]">\r
+               <xsl:call-template name="genre"/>\r
+       </xsl:template>\r
+       <xsl:template\r
+               match="marc:datafield[@tag=455][marc:subfield[@code='a']]|marc:datafield[@tag=485 ][marc:subfield[@code='v']]">\r
+               <mads:variant>\r
+                       <xsl:call-template name="variantTypeAttribute"/>\r
+                       <xsl:call-template name="genre"/>\r
+               </mads:variant>\r
+       </xsl:template>\r
+       <!--\r
+       <xsl:template match="marc:datafield[@tag=555]">\r
+               <mads:related>\r
+                       <xsl:call-template name="relatedTypeAttribute"/>\r
+                       <xsl:call-template name="uri"/>\r
+                       <xsl:call-template name="genre"/>\r
+               </mads:related>\r
+       </xsl:template>\r
+       -->\r
+       <xsl:template\r
+               match="marc:datafield[@tag=555 or @tag=755][marc:subfield[@code='a']]|marc:datafield[@tag=585][marc:subfield[@code='v']]">\r
+               <mads:related>\r
+                       <xsl:call-template name="relatedTypeAttribute"/>\r
+                       <xsl:call-template name="genre"/>\r
+               </mads:related>\r
+       </xsl:template>\r
+       <xsl:template name="genre">\r
+               <mads:genre>\r
+                       <xsl:if test="@tag=555">\r
+                               <xsl:value-of select="marc:subfield[@code='a']"/>\r
+                       </xsl:if>\r
+                       <xsl:call-template name="setAuthority"/>\r
+                       <xsl:call-template name="chopPunctuation">\r
+                               <xsl:with-param name="chopString">\r
+                                       <xsl:choose>\r
+                                               <!-- 2.07 fix -->\r
+                                               <xsl:when test="@tag='555'"/>\r
+                                               <xsl:when test="@tag=185 or @tag=485 or @tag=585">\r
+                                                       <xsl:apply-templates select="marc:subfield[@code='v']"/>\r
+                                               </xsl:when>\r
+                                               <xsl:otherwise>\r
+                                                       <xsl:value-of select="marc:subfield[@code='a']"/>\r
+                                               </xsl:otherwise>\r
+                                       </xsl:choose>\r
+                               </xsl:with-param>\r
+                       </xsl:call-template>\r
+               </mads:genre>\r
+               <xsl:apply-templates/>\r
+       </xsl:template>\r
+\r
+       <!-- ========= geographic  ========== -->\r
+       <xsl:template match="marc:subfield[@code='z']">\r
+               <mads:geographic>\r
+                       <xsl:call-template name="chopPunctuation">\r
+                               <xsl:with-param name="chopString">\r
+                                       <xsl:value-of select="."/>\r
+                               </xsl:with-param>\r
+                       </xsl:call-template>\r
+               </mads:geographic>\r
+       </xsl:template>\r
+       <xsl:template name="geographic">\r
+               <mads:geographic>\r
+                       <!-- 2.14 -->\r
+                       <xsl:call-template name="setAuthority"/>\r
+                       <!-- 2.13 -->\r
+                       <xsl:if test="@tag=151 or @tag=551">\r
+                               <xsl:value-of select="marc:subfield[@code='a']"/>\r
+                       </xsl:if>\r
+                       <xsl:call-template name="chopPunctuation">\r
+                               <xsl:with-param name="chopString">\r
+                                               <xsl:if test="@tag=181 or @tag=481 or @tag=581">\r
+                                                               <xsl:apply-templates select="marc:subfield[@code='z']"/>\r
+                                               </xsl:if>\r
+                                               <!-- 2.13\r
+                                                       <xsl:choose>\r
+                                               <xsl:when test="@tag=181 or @tag=481 or @tag=581">\r
+                                                       <xsl:apply-templates select="marc:subfield[@code='z']"/>\r
+                                               </xsl:when>\r
+                                       \r
+                                               <xsl:otherwise>\r
+                                                       <xsl:value-of select="marc:subfield[@code='a']"/>\r
+                                               </xsl:otherwise>\r
+                                               </xsl:choose>\r
+                                               -->\r
+                               </xsl:with-param>\r
+                       </xsl:call-template>\r
+               </mads:geographic>\r
+               <xsl:apply-templates select="marc:subfield[@code!='i']"/>\r
+       </xsl:template>\r
+       <xsl:template\r
+               match="marc:datafield[@tag=151][marc:subfield[@code='a']]|marc:datafield[@tag=181][marc:subfield[@code='z']]">\r
+               <xsl:call-template name="geographic"/>\r
+       </xsl:template>\r
+       <xsl:template\r
+               match="marc:datafield[@tag=451][marc:subfield[@code='a']]|marc:datafield[@tag=481][marc:subfield[@code='z']]">\r
+               <mads:variant>\r
+                       <xsl:call-template name="variantTypeAttribute"/>\r
+                       <xsl:call-template name="geographic"/>\r
+               </mads:variant>\r
+       </xsl:template>\r
+       <xsl:template\r
+               match="marc:datafield[@tag=551]|marc:datafield[@tag=581][marc:subfield[@code='z']]">\r
+               <mads:related>\r
+                       <xsl:call-template name="relatedTypeAttribute"/>\r
+                       <!-- <xsl:call-template name="uri"/> -->\r
+                       <xsl:call-template name="geographic"/>\r
+               </mads:related>\r
+       </xsl:template>\r
+       <xsl:template match="marc:datafield[@tag=580]">\r
+               <mads:related>\r
+                       <xsl:call-template name="relatedTypeAttribute"/>\r
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>\r
+               </mads:related>\r
+       </xsl:template>\r
+       <xsl:template\r
+               match="marc:datafield[@tag=751][marc:subfield[@code='z']]|marc:datafield[@tag=781][marc:subfield[@code='z']]">\r
+               <mads:related>\r
+                       <xsl:call-template name="relatedTypeAttribute"/>\r
+                       <xsl:call-template name="geographic"/>\r
+               </mads:related>\r
+       </xsl:template>\r
+       <xsl:template match="marc:datafield[@tag=755]">\r
+               <mads:related>\r
+                       <xsl:call-template name="relatedTypeAttribute"/>\r
+                       <xsl:call-template name="genre"/>\r
+                       <xsl:call-template name="setAuthority"/>\r
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>\r
+               </mads:related>\r
+       </xsl:template>\r
+       <xsl:template match="marc:datafield[@tag=780]">\r
+               <mads:related>\r
+                       <xsl:call-template name="relatedTypeAttribute"/>\r
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>\r
+               </mads:related>\r
+       </xsl:template>\r
+       <xsl:template match="marc:datafield[@tag=785]">\r
+               <mads:related>\r
+                       <xsl:call-template name="relatedTypeAttribute"/>\r
+                       <xsl:apply-templates select="marc:subfield[@code!='i']"/>\r
+               </mads:related>\r
+       </xsl:template>\r
+\r
+       <!-- ========== notes  ========== -->\r
+       <xsl:template match="marc:datafield[667 &lt;= @tag and @tag &lt;= 688]">\r
+               <mads:note>\r
+                       <xsl:choose>\r
+                               <xsl:when test="@tag=667">\r
+                                       <xsl:attribute name="type">nonpublic</xsl:attribute>\r
+                               </xsl:when>\r
+                               <xsl:when test="@tag=670">\r
+                                       <xsl:attribute name="type">source</xsl:attribute>\r
+                               </xsl:when>\r
+                               <xsl:when test="@tag=675">\r
+                                       <xsl:attribute name="type">notFound</xsl:attribute>\r
+                               </xsl:when>\r
+                               <xsl:when test="@tag=678">\r
+                                       <xsl:attribute name="type">history</xsl:attribute>\r
+                               </xsl:when>\r
+                               <xsl:when test="@tag=681">\r
+                                       <xsl:attribute name="type">subject example</xsl:attribute>\r
+                               </xsl:when>\r
+                               <xsl:when test="@tag=682">\r
+                                       <xsl:attribute name="type">deleted heading information</xsl:attribute>\r
+                               </xsl:when>\r
+                               <xsl:when test="@tag=688">\r
+                                       <xsl:attribute name="type">application history</xsl:attribute>\r
+                               </xsl:when>\r
+                       </xsl:choose>\r
+                       <xsl:call-template name="chopPunctuation">\r
+                               <xsl:with-param name="chopString">\r
+                                       <xsl:choose>\r
+                                               <xsl:when test="@tag=667 or @tag=675">\r
+                                                       <xsl:value-of select="marc:subfield[@code='a']"/>\r
+                                               </xsl:when>\r
+                                               <xsl:when test="@tag=670 or @tag=678">\r
+                                                       <xsl:call-template name="subfieldSelect">\r
+                                                               <xsl:with-param name="codes">ab</xsl:with-param>\r
+                                                       </xsl:call-template>\r
+                                               </xsl:when>\r
+                                               <xsl:when test="680 &lt;= @tag and @tag &lt;=688">\r
+                                                       <xsl:call-template name="subfieldSelect">\r
+                                                               <xsl:with-param name="codes">ai</xsl:with-param>\r
+                                                       </xsl:call-template>\r
+                                               </xsl:when>\r
+                                       </xsl:choose>\r
+                               </xsl:with-param>\r
+                       </xsl:call-template>\r
+               </mads:note>\r
+       </xsl:template>\r
+\r
+       <!-- ========== url  ========== -->\r
+       <xsl:template match="marc:datafield[@tag=856][marc:subfield[@code='u']]">\r
+               <mads:url>\r
+                       <xsl:if test="marc:subfield[@code='z' or @code='3']">\r
+                               <xsl:attribute name="displayLabel">\r
+                                       <xsl:call-template name="subfieldSelect">\r
+                                               <xsl:with-param name="codes">z3</xsl:with-param>\r
+                                       </xsl:call-template>\r
+                               </xsl:attribute>\r
+                       </xsl:if>\r
+                       <xsl:value-of select="marc:subfield[@code='u']"/>\r
+               </mads:url>\r
+       </xsl:template>\r
+\r
+       <xsl:template name="relatedTypeAttribute">\r
+               <xsl:choose>\r
+                       <xsl:when\r
+                               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">\r
+                               <xsl:if test="substring(marc:subfield[@code='w'],1,1)='a'">\r
+                                       <xsl:attribute name="type">earlier</xsl:attribute>\r
+                               </xsl:if>\r
+                               <xsl:if test="substring(marc:subfield[@code='w'],1,1)='b'">\r
+                                       <xsl:attribute name="type">later</xsl:attribute>\r
+                               </xsl:if>\r
+                               <xsl:if test="substring(marc:subfield[@code='w'],1,1)='t'">\r
+                                       <xsl:at