forked from cnelsonFLVC/FLVC_Islandora_XSLTs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
MARC21slimUtils.xsl
188 lines (174 loc) · 6.47 KB
/
MARC21slimUtils.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:marc="http://www.loc.gov/MARC21/slim"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- 08/08/08: tmee added corrected chopPunctuation templates for 260c -->
<!-- 08/19/04: ntra added "marc:" prefix to datafield element -->
<!-- 12/14/07: ntra added url encoding template -->
<!-- url encoding -->
<xsl:variable name="ascii">
<xsl:text> !"#$%&'()*+,-./0123456789:;<=>?@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) > 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>
</xsl:stylesheet>
<!-- Stylus Studio meta-information - (c)1998-2002 eXcelon Corp.
<metaInformation>
<scenarios/><MapperInfo srcSchemaPath="" srcSchemaRoot="" srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/>
</metaInformation>
-->