Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 182 lines (168 sloc) 6.609 kB
d1f1238 @mjsuhonos first commit
authored
1 <?xml version="1.0" encoding="UTF-8"?>
2 <xsl:stylesheet version="1.0" xmlns:marc="http://www.loc.gov/MARC21/slim" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
3
4 <!-- 08/08/08: tmee added corrected chopPunctuation templates for 260c -->
5 <!-- 08/19/04: ntra added "marc:" prefix to datafield element -->
6 <!-- 12/14/07: ntra added url encoding template -->
7 <!-- url encoding -->
8
9 <xsl:variable name="ascii">
10 <xsl:text> !"#$%&amp;'()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~</xsl:text>
11 </xsl:variable>
12
13 <xsl:variable name="latin1">
14 <xsl:text> ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ</xsl:text>
15 </xsl:variable>
16 <!-- Characters that usually don't need to be escaped -->
17 <xsl:variable name="safe">
18 <xsl:text>!'()*-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~</xsl:text>
19 </xsl:variable>
20
21 <xsl:variable name="hex">0123456789ABCDEF</xsl:variable>
22
23
24 <xsl:template name="datafield">
25 <xsl:param name="tag"/>
26 <xsl:param name="ind1">
27 <xsl:text> </xsl:text>
28 </xsl:param>
29 <xsl:param name="ind2">
30 <xsl:text> </xsl:text>
31 </xsl:param>
32 <xsl:param name="subfields"/>
33 <xsl:element name="marc:datafield">
34 <xsl:attribute name="tag">
35 <xsl:value-of select="$tag"/>
36 </xsl:attribute>
37 <xsl:attribute name="ind1">
38 <xsl:value-of select="$ind1"/>
39 </xsl:attribute>
40 <xsl:attribute name="ind2">
41 <xsl:value-of select="$ind2"/>
42 </xsl:attribute>
43 <xsl:copy-of select="$subfields"/>
44 </xsl:element>
45 </xsl:template>
46
47 <xsl:template name="subfieldSelect">
48 <xsl:param name="codes">abcdefghijklmnopqrstuvwxyz</xsl:param>
49 <xsl:param name="delimeter">
50 <xsl:text> </xsl:text>
51 </xsl:param>
52 <xsl:variable name="str">
53 <xsl:for-each select="marc:subfield">
54 <xsl:if test="contains($codes, @code)">
55 <xsl:value-of select="text()"/>
56 <xsl:value-of select="$delimeter"/>
57 </xsl:if>
58 </xsl:for-each>
59 </xsl:variable>
60 <xsl:value-of select="substring($str,1,string-length($str)-string-length($delimeter))"/>
61 </xsl:template>
62
63 <xsl:template name="buildSpaces">
64 <xsl:param name="spaces"/>
65 <xsl:param name="char">
66 <xsl:text> </xsl:text>
67 </xsl:param>
68 <xsl:if test="$spaces&gt;0">
69 <xsl:value-of select="$char"/>
70 <xsl:call-template name="buildSpaces">
71 <xsl:with-param name="spaces" select="$spaces - 1"/>
72 <xsl:with-param name="char" select="$char"/>
73 </xsl:call-template>
74 </xsl:if>
75 </xsl:template>
76
77 <xsl:template name="chopPunctuation">
78 <xsl:param name="chopString"/>
79 <xsl:param name="punctuation">
80 <xsl:text>.:,;/ </xsl:text>
81 </xsl:param>
82 <xsl:variable name="length" select="string-length($chopString)"/>
83 <xsl:choose>
84 <xsl:when test="$length=0"/>
85 <xsl:when test="contains($punctuation, substring($chopString,$length,1))">
86 <xsl:call-template name="chopPunctuation">
87 <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
88 <xsl:with-param name="punctuation" select="$punctuation"/>
89 </xsl:call-template>
90 </xsl:when>
91 <xsl:when test="not($chopString)"/>
92 <xsl:otherwise>
93 <xsl:value-of select="$chopString"/>
94 </xsl:otherwise>
95 </xsl:choose>
96 </xsl:template>
97
98 <xsl:template name="chopPunctuationFront">
99 <xsl:param name="chopString"/>
100 <xsl:variable name="length" select="string-length($chopString)"/>
101 <xsl:choose>
102 <xsl:when test="$length=0"/>
103 <xsl:when test="contains('.:,;/[ ', substring($chopString,1,1))">
104 <xsl:call-template name="chopPunctuationFront">
105 <xsl:with-param name="chopString" select="substring($chopString,2,$length - 1)"/>
106 </xsl:call-template>
107 </xsl:when>
108 <xsl:when test="not($chopString)"/>
109 <xsl:otherwise>
110 <xsl:value-of select="$chopString"/>
111 </xsl:otherwise>
112 </xsl:choose>
113 </xsl:template>
114
115 <xsl:template name="chopPunctuationBack">
116 <xsl:param name="chopString"/>
117 <xsl:param name="punctuation">
118 <xsl:text>.:,;/] </xsl:text>
119 </xsl:param>
120 <xsl:variable name="length" select="string-length($chopString)"/>
121 <xsl:choose>
122 <xsl:when test="$length=0"/>
123 <xsl:when test="contains($punctuation, substring($chopString,$length,1))">
124 <xsl:call-template name="chopPunctuation">
125 <xsl:with-param name="chopString" select="substring($chopString,1,$length - 1)"/>
126 <xsl:with-param name="punctuation" select="$punctuation"/>
127 </xsl:call-template>
128 </xsl:when>
129 <xsl:when test="not($chopString)"/>
130 <xsl:otherwise>
131 <xsl:value-of select="$chopString"/>
132 </xsl:otherwise>
133 </xsl:choose>
134 </xsl:template>
135
136 <!-- nate added 12/14/2007 for lccn.loc.gov: url encode ampersand, etc. -->
137 <xsl:template name="url-encode">
138
139 <xsl:param name="str"/>
140
141 <xsl:if test="$str">
142 <xsl:variable name="first-char" select="substring($str,1,1)"/>
143 <xsl:choose>
144 <xsl:when test="contains($safe,$first-char)">
145 <xsl:value-of select="$first-char"/>
146 </xsl:when>
147 <xsl:otherwise>
148 <xsl:variable name="codepoint">
149 <xsl:choose>
150 <xsl:when test="contains($ascii,$first-char)">
151 <xsl:value-of select="string-length(substring-before($ascii,$first-char)) + 32"/>
152 </xsl:when>
153 <xsl:when test="contains($latin1,$first-char)">
154 <xsl:value-of select="string-length(substring-before($latin1,$first-char)) + 160"/>
155 <!-- was 160 -->
156 </xsl:when>
157 <xsl:otherwise>
158 <xsl:message terminate="no">Warning: string contains a character
159 that is out of range! Substituting "?".</xsl:message>
160 <xsl:text>63</xsl:text>
161 </xsl:otherwise>
162 </xsl:choose>
163 </xsl:variable>
164 <xsl:variable name="hex-digit1" select="substring($hex,floor($codepoint div 16) + 1,1)"/>
165 <xsl:variable name="hex-digit2" select="substring($hex,$codepoint mod 16 + 1,1)"/>
166 <!-- <xsl:value-of select="concat('%',$hex-digit2)"/> -->
167 <xsl:value-of select="concat('%',$hex-digit1,$hex-digit2)"/>
168 </xsl:otherwise>
169 </xsl:choose>
170 <xsl:if test="string-length($str) &gt; 1">
171 <xsl:call-template name="url-encode">
172 <xsl:with-param name="str" select="substring($str,2)"/>
173 </xsl:call-template>
174 </xsl:if>
175 </xsl:if>
176 </xsl:template>
177 </xsl:stylesheet>
178 <!-- Stylus Studio meta-information - (c)1998-2002 eXcelon Corp.
179 <metaInformation>
180 <scenarios/><MapperInfo srcSchemaPath="" srcSchemaRoot="" srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/>
181 </metaInformation>
182 -->
Something went wrong with that request. Please try again.