2 <!DOCTYPE stylesheet [<!ENTITY nbsp " " >]>
3 <xsl:stylesheet version="1.0" xmlns:marc="http://www.loc.gov/MARC21/slim"
4 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
6 <!-- 08/08/08: tmee added corrected chopPunctuation templates for 260c -->
7 <!-- 08/19/04: ntra added "marc:" prefix to datafield element -->
8 <!-- 12/14/07: ntra added url encoding template -->
11 <xsl:variable name="ascii">
12 <xsl:text> !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~</xsl:text>
15 <xsl:variable name="latin1">
16 <xsl:text> ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ</xsl:text>
18 <!-- Characters that usually don't need to be escaped -->
19 <xsl:variable name="safe">
20 <xsl:text>!'()*-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~</xsl:text>
23 <xsl:variable name="hex">0123456789ABCDEF</xsl:variable>
26 <xsl:template name="datafield">
27 <xsl:param name="tag"/>
28 <xsl:param name="ind1">
29 <xsl:text> </xsl:text>
31 <xsl:param name="ind2">
32 <xsl:text> </xsl:text>
34 <xsl:param name="subfields"/>
35 <xsl:element name="marc:datafield">
36 <xsl:attribute name="tag">
37 <xsl:value-of select="$tag"/>
39 <xsl:attribute name="ind1">
40 <xsl:value-of select="$ind1"/>
42 <xsl:attribute name="ind2">
43 <xsl:value-of select="$ind2"/>
45 <xsl:copy-of select="$subfields"/>
49 <xsl:template name="subfieldSelect">
50 <xsl:param name="codes">abcdefghijklmnopqrstuvwxyz</xsl:param>
51 <xsl:param name="delimeter">
52 <xsl:text> </xsl:text>
54 <xsl:variable name="str">
55 <xsl:for-each select="marc:subfield">
56 <xsl:if test="contains($codes, @code)">
57 <xsl:value-of select="text()"/>
58 <xsl:value-of select="$delimeter"/>
62 <xsl:value-of select="substring($str,1,string-length($str)-string-length($delimeter))"/>
65 <xsl:template name="buildSpaces">
66 <xsl:param name="spaces"/>
67 <xsl:param name="char">
68 <xsl:text> </xsl:text>
70 <xsl:if test="$spaces>0">
71 <xsl:value-of select="$char"/>
72 <xsl:call-template name="buildSpaces">
73 <xsl:with-param name="spaces" select="$spaces - 1"/>
74 <xsl:with-param name="char" select="$char"/>
79 <xsl:template name="chopPunctuation">
80 <xsl:param name="chopString"/>
81 <xsl:param name="punctuation">
82 <xsl:text>.:,;/ </xsl:text>
84 <xsl:variable name="length" select="string-length($chopString)"/>
86 <xsl:when test="$length=0"/>
87 <xsl:when test="contains($punctuation, substring($chopString,$length,1))">
88 <xsl:call-template name="chopPunctuation">
89 <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
90 <xsl:with-param name="punctuation" select="$punctuation"/>
93 <xsl:when test="not($chopString)"/>
95 <xsl:value-of select="$chopString"/>
100 <xsl:template name="chopPunctuationFront">
101 <xsl:param name="chopString"/>
102 <xsl:variable name="length" select="string-length($chopString)"/>
104 <xsl:when test="$length=0"/>
105 <xsl:when test="contains('.:,;/[ ', substring($chopString,1,1))">
106 <xsl:call-template name="chopPunctuationFront">
107 <xsl:with-param name="chopString" select="substring($chopString,2,$length - 1)"
111 <xsl:when test="not($chopString)"/>
113 <xsl:value-of select="$chopString"/>
118 <xsl:template name="chopPunctuationBack">
119 <xsl:param name="chopString"/>
120 <xsl:param name="punctuation">
121 <xsl:text>.:,;/] </xsl:text>
123 <xsl:variable name="length" select="string-length($chopString)"/>
125 <xsl:when test="$length=0"/>
126 <xsl:when test="contains($punctuation, substring($chopString,$length,1))">
127 <xsl:call-template name="chopPunctuation">
128 <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
129 <xsl:with-param name="punctuation" select="$punctuation"/>
132 <xsl:when test="not($chopString)"/>
134 <xsl:value-of select="$chopString"/>
139 <!-- nate added 12/14/2007 for lccn.loc.gov: url encode ampersand, etc. -->
140 <xsl:template name="url-encode">
142 <xsl:param name="str"/>
145 <xsl:variable name="first-char" select="substring($str,1,1)"/>
147 <xsl:when test="contains($safe,$first-char)">
148 <xsl:value-of select="$first-char"/>
151 <xsl:variable name="codepoint">
153 <xsl:when test="contains($ascii,$first-char)">
155 select="string-length(substring-before($ascii,$first-char)) + 32"
158 <xsl:when test="contains($latin1,$first-char)">
160 select="string-length(substring-before($latin1,$first-char)) + 160"/>
164 <xsl:message terminate="no">Warning: string contains a character
165 that is out of range! Substituting "?".</xsl:message>
166 <xsl:text>63</xsl:text>
170 <xsl:variable name="hex-digit1"
171 select="substring($hex,floor($codepoint div 16) + 1,1)"/>
172 <xsl:variable name="hex-digit2" select="substring($hex,$codepoint mod 16 + 1,1)"/>
173 <!-- <xsl:value-of select="concat('%',$hex-digit2)"/> -->
174 <xsl:value-of select="concat('%',$hex-digit1,$hex-digit2)"/>
177 <xsl:if test="string-length($str) > 1">
178 <xsl:call-template name="url-encode">
179 <xsl:with-param name="str" select="substring($str,2)"/>
185 <!-- Stylus Studio meta-information - (c)1998-2002 eXcelon Corp.
187 <scenarios/><MapperInfo srcSchemaPath="" srcSchemaRoot="" srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/>