Project

General

Profile

1 5965 berkley
<xsl:stylesheet xmlns="http://www.w3.org/1999/xhtml" xmlns:i18n="http://apache.org/cocoon/i18n/2.1"
2
    xmlns:dri="http://di.tamu.edu/DRI/1.0/" xmlns:mets="http://www.loc.gov/METS/"
3
    xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dim="http://www.dspace.org/xmlns/dspace/dim"
4
    xmlns:mods="http://www.loc.gov/mods/v3" xmlns:xlink="http://www.w3.org/TR/xlink/"
5
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xalan"
6
    xmlns:datetime="http://exslt.org/dates-and-times" xmlns:encoder="xalan://java.net.URLEncoder"
7
    xmlns:strings="http://exslt.org/strings"
8
    exclude-result-prefixes="xalan strings encoder datetime" version="1.0">
9
10
    <xsl:variable name="ascii"> !"#$%&amp;'()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~</xsl:variable>
11
    <xsl:variable name="latin1">&#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;&#189;&#190;&#191;&#192;&#193;&#194;&#195;&#196;&#197;&#198;&#199;&#200;&#201;&#202;&#203;&#204;&#205;&#206;&#207;&#208;&#209;&#210;&#211;&#212;&#213;&#214;&#215;&#216;&#217;&#218;&#219;&#220;&#221;&#222;&#223;&#224;&#225;&#226;&#227;&#228;&#229;&#230;&#231;&#232;&#233;&#234;&#235;&#236;&#237;&#238;&#239;&#240;&#241;&#242;&#243;&#244;&#245;&#246;&#247;&#248;&#249;&#250;&#251;&#252;&#253;&#254;&#255;</xsl:variable>
12
13
    <!-- Characters that usually don't need to be escaped -->
14
    <xsl:variable name="safe">!'()*-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~</xsl:variable>
15
16
    <xsl:variable name="hex" >0123456789ABCDEF</xsl:variable>
17
18
    <xsl:template name="name-parse">
19
        <xsl:param name="name"/>
20
        <xsl:variable name="names"
21
            select="strings:split(normalize-space(translate($name, '.', ' ')))"/>
22
        <xsl:variable name="count" select="count($names)"/>
23
        <xsl:if test="$count &gt; 0">
24
            <!-- handle the last name, first -->
25
            <xsl:value-of select="$names[$count]"/>
26
            <xsl:if test="$count &gt; 1">
27
                <!--<xsl:text>, </xsl:text>-->
28
            		<xsl:text> </xsl:text>
29
                <!-- now the first and middle names -->
30
                <xsl:for-each select="$names">
31
                    <xsl:choose>
32
                        <xsl:when test="position() = $count"/>
33
                        <xsl:otherwise>
34
                            <xsl:value-of select="substring(., 1, 1)"/>
35
                            <!--<xsl:text>.</xsl:text>-->
36
                        </xsl:otherwise>
37
                    </xsl:choose>
38
                </xsl:for-each>
39
            </xsl:if>
40
        </xsl:if>
41
    </xsl:template>
42
    <xsl:template name="name-parse-reverse">
43
        <xsl:param name="name"/>
44
        <xsl:variable name="names" select="strings:split(translate($name, '.', ' '), ',')"/>
45
        <xsl:value-of select="normalize-space($names[1])"/>
46
        <xsl:text> </xsl:text>
47
        <xsl:for-each select="strings:split(normalize-space($names[2]), ' ')">
48
        	<xsl:value-of select="substring(., 1, 1)"/>
49
        </xsl:for-each>
50
    </xsl:template>
51
    <datetime:month-lengths xmlns:date="http://exslt.org/dates-and-times">
52
        <datetime:month>31</datetime:month>
53
        <datetime:month>28</datetime:month>
54
        <datetime:month>31</datetime:month>
55
        <datetime:month>30</datetime:month>
56
        <datetime:month>31</datetime:month>
57
        <datetime:month>30</datetime:month>
58
        <datetime:month>31</datetime:month>
59
        <datetime:month>31</datetime:month>
60
        <datetime:month>30</datetime:month>
61
        <datetime:month>31</datetime:month>
62
        <datetime:month>30</datetime:month>
63
        <datetime:month>31</datetime:month>
64
    </datetime:month-lengths>
65
    <xsl:template name="datetime:difference">
66
        <xsl:param name="start"/>
67
        <xsl:param name="end"/>
68
        <xsl:variable name="start-neg" select="starts-with($start, '-')"/>
69
        <xsl:variable name="start-no-neg">
70
            <xsl:choose>
71
                <xsl:when test="$start-neg or starts-with($start, '+')">
72
                    <xsl:value-of select="substring($start, 2)"/>
73
                </xsl:when>
74
                <xsl:otherwise>
75
                    <xsl:value-of select="$start"/>
76
                </xsl:otherwise>
77
            </xsl:choose>
78
        </xsl:variable>
79
        <xsl:variable name="start-no-neg-length" select="string-length($start-no-neg)"/>
80
        <xsl:variable name="start-timezone">
81
            <xsl:choose>
82
                <xsl:when test="substring($start-no-neg, $start-no-neg-length) = 'Z'">Z</xsl:when>
83
                <xsl:otherwise>
84
                    <xsl:variable name="tz"
85
                        select="substring($start-no-neg, $start-no-neg-length - 5)"/>
86
                    <xsl:if
87
                        test="(substring($tz, 1, 1) = '-' or substring($tz, 1, 1) = '+') and substring($tz, 4, 1) = ':'">
88
                        <xsl:value-of select="$tz"/>
89
                    </xsl:if>
90
                </xsl:otherwise>
91
            </xsl:choose>
92
        </xsl:variable>
93
        <xsl:variable name="end-neg" select="starts-with($end, '-')"/>
94
        <xsl:variable name="end-no-neg">
95
            <xsl:choose>
96
                <xsl:when test="$end-neg or starts-with($end, '+')">
97
                    <xsl:value-of select="substring($end, 2)"/>
98
                </xsl:when>
99
                <xsl:otherwise>
100
                    <xsl:value-of select="$end"/>
101
                </xsl:otherwise>
102
            </xsl:choose>
103
        </xsl:variable>
104
        <xsl:variable name="end-no-neg-length" select="string-length($end-no-neg)"/>
105
        <xsl:variable name="end-timezone">
106
            <xsl:choose>
107
                <xsl:when test="substring($end-no-neg, $end-no-neg-length) = 'Z'">Z</xsl:when>
108
                <xsl:otherwise>
109
                    <xsl:variable name="tz" select="substring($end-no-neg, $end-no-neg-length - 5)"/>
110
                    <xsl:if
111
                        test="(substring($tz, 1, 1) = '-' or substring($tz, 1, 1) = '+') and substring($tz, 4, 1) = ':'">
112
                        <xsl:value-of select="$tz"/>
113
                    </xsl:if>
114
                </xsl:otherwise>
115
            </xsl:choose>
116
        </xsl:variable>
117
        <xsl:variable name="difference">
118
            <xsl:if
119
                test="(not(string($start-timezone)) or $start-timezone = 'Z' or (substring($start-timezone, 2, 2) &lt;= 23 and substring($start-timezone, 5, 2) &lt;= 59)) and (not(string($end-timezone)) or $end-timezone = 'Z' or (substring($end-timezone, 2, 2) &lt;= 23 and substring($end-timezone, 5, 2) &lt;= 59))">
120
                <xsl:variable name="start-dt"
121
                    select="substring($start-no-neg, 1, $start-no-neg-length - string-length($start-timezone))"/>
122
                <xsl:variable name="start-dt-length" select="string-length($start-dt)"/>
123
                <xsl:variable name="end-dt"
124
                    select="substring($end-no-neg, 1, $end-no-neg-length - string-length($end-timezone))"/>
125
                <xsl:variable name="end-dt-length" select="string-length($end-dt)"/>
126
                <xsl:variable name="start-year"
127
                    select="substring($start-dt, 1, 4) * (($start-neg * -2) + 1)"/>
128
                <xsl:variable name="end-year"
129
                    select="substring($end-dt, 1, 4) * (($end-neg * -2) + 1)"/>
130
                <xsl:variable name="diff-year" select="$end-year - $start-year"/>
131
                <xsl:choose>
132
                    <xsl:when test="not(number($start-year) and number($end-year))"/>
133
                    <xsl:when test="$start-dt-length = 4 or $end-dt-length = 4">
134
                        <xsl:choose>
135
                            <xsl:when test="$diff-year &lt; 0">-P <xsl:value-of
136
                                    select="$diff-year * -1"/> Y</xsl:when>
137
                            <xsl:otherwise>P <xsl:value-of select="$diff-year"/> Y</xsl:otherwise>
138
                        </xsl:choose>
139
                    </xsl:when>
140
                    <xsl:when
141
                        test="substring($start-dt, 5, 1) = '-' and substring($end-dt, 5, 1) = '-'">
142
                        <xsl:variable name="start-month" select="substring($start-dt, 6, 2)"/>
143
                        <xsl:variable name="end-month" select="substring($end-dt, 6, 2)"/>
144
                        <xsl:variable name="diff-month" select="$end-month - $start-month"/>
145
                        <xsl:choose>
146
                            <xsl:when test="not($start-month &lt;= 12 and $end-month &lt;= 12)"/>
147
                            <xsl:when test="$start-dt-length = 7 or $end-dt-length = 7">
148
                                <xsl:variable name="months" select="$diff-month + ($diff-year * 12)"/>
149
                                <xsl:variable name="abs-months"
150
                                    select="$months * ((($months >= 0) * 2) - 1)"/>
151
                                <xsl:variable name="y" select="floor($abs-months div 12)"/>
152
                                <xsl:variable name="m" select="$abs-months mod 12"/>
153
                                <xsl:if test="$months &lt; 0">-</xsl:if>
154
                                <xsl:text>P</xsl:text>
155
                                <xsl:if test="$y">
156
                                    <xsl:value-of select="$y"/> Y</xsl:if>
157
                                <xsl:if test="$m">
158
                                    <xsl:value-of select="$m"/> M</xsl:if>
159
                            </xsl:when>
160
                            <xsl:when
161
                                test="substring($start-dt, 8, 1) = '-' and substring($end-dt, 8, 1) = '-'">
162
                                <xsl:variable name="start-day" select="substring($start-dt, 9, 2)"/>
163
                                <xsl:variable name="end-day" select="substring($end-dt, 9, 2)"/>
164
                                <xsl:if test="$start-day &lt;= 31 and $end-day &lt;= 31">
165
                                    <xsl:variable name="month-lengths"
166
                                        select="document('')/*/datetime:month-lengths/datetime:month"/>
167
                                    <xsl:variable name="start-y-1" select="$start-year - 1"/>
168
                                    <xsl:variable name="start-leaps"
169
                                        select="floor($start-y-1 div 4) - floor($start-y-1 div 100) + floor($start-y-1 div 400)"/>
170
                                    <xsl:variable name="start-leap"
171
                                        select="(not($start-year mod 4) and $start-year mod 100) or not($start-year mod 400)"/>
172
                                    <xsl:variable name="start-month-days"
173
                                        select="sum($month-lengths[position() &lt; $start-month])"/>
174
                                    <xsl:variable name="start-days">
175
                                        <xsl:variable name="days"
176
                                            select="($start-year * 365) + $start-leaps + $start-month-days + $start-day"/>
177
                                        <xsl:choose>
178
                                            <xsl:when test="$start-leap and $start-month > 2">
179
                                                <xsl:value-of select="$days + 1"/>
180
                                            </xsl:when>
181
                                            <xsl:otherwise>
182
                                                <xsl:value-of select="$days"/>
183
                                            </xsl:otherwise>
184
                                        </xsl:choose>
185
                                    </xsl:variable>
186
                                    <xsl:variable name="end-y-1" select="$end-year - 1"/>
187
                                    <xsl:variable name="end-leaps"
188
                                        select="floor($end-y-1 div 4) - floor($end-y-1 div 100) + floor($end-y-1 div 400)"/>
189
                                    <xsl:variable name="end-leap"
190
                                        select="(not($end-year mod 4) and $end-year mod 100) or not($end-year mod 400)"/>
191
                                    <xsl:variable name="end-month-days"
192
                                        select="sum($month-lengths[position() &lt; $end-month])"/>
193
                                    <xsl:variable name="end-days">
194
                                        <xsl:variable name="days"
195
                                            select="($end-year * 365) + $end-leaps + $end-month-days + $end-day"/>
196
                                        <xsl:choose>
197
                                            <xsl:when test="$end-leap and $end-month > 2">
198
                                                <xsl:value-of select="$days + 1"/>
199
                                            </xsl:when>
200
                                            <xsl:otherwise>
201
                                                <xsl:value-of select="$days"/>
202
                                            </xsl:otherwise>
203
                                        </xsl:choose>
204
                                    </xsl:variable>
205
                                    <xsl:variable name="diff-days" select="$end-days - $start-days"/>
206
                                    <xsl:choose>
207
                                        <xsl:when
208
                                            test="$start-dt-length = 10 or $end-dt-length = 10">
209
                                            <xsl:choose>
210
                                                <xsl:when test="$diff-days &lt; 0">-P <xsl:value-of
211
                                                  select="$diff-days * -1"/> D</xsl:when>
212
                                                <xsl:otherwise>P <xsl:value-of select="$diff-days"/>
213
                                                  D</xsl:otherwise>
214
                                            </xsl:choose>
215
                                        </xsl:when>
216
                                        <xsl:when
217
                                            test="substring($start-dt, 11, 1) = 'T' and substring($end-dt, 11, 1) = 'T' and substring($start-dt, 14, 1) = ':' and substring($start-dt, 17, 1) = ':' and substring($end-dt, 14, 1) = ':' and substring($end-dt, 17, 1) = ':'">
218
                                            <xsl:variable name="start-hour"
219
                                                select="substring($start-dt, 12, 2)"/>
220
                                            <xsl:variable name="start-min"
221
                                                select="substring($start-dt, 15, 2)"/>
222
                                            <xsl:variable name="start-sec"
223
                                                select="substring($start-dt, 18)"/>
224
                                            <xsl:variable name="end-hour"
225
                                                select="substring($end-dt, 12, 2)"/>
226
                                            <xsl:variable name="end-min"
227
                                                select="substring($end-dt, 15, 2)"/>
228
                                            <xsl:variable name="end-sec"
229
                                                select="substring($end-dt, 18)"/>
230
                                            <xsl:if
231
                                                test="$start-hour &lt;= 23 and $end-hour &lt;= 23 and $start-min &lt;= 59 and $end-min &lt;= 59 and $start-sec &lt;= 60 and $end-sec &lt;= 60">
232
                                                <xsl:variable name="min-s" select="60"/>
233
                                                <xsl:variable name="hour-s" select="60 * 60"/>
234
                                                <xsl:variable name="day-s" select="60 * 60 * 24"/>
235
                                                <xsl:variable name="start-tz-adj">
236
                                                  <xsl:variable name="tz"
237
                                                  select="(substring($start-timezone, 2, 2) * $hour-s) + (substring($start-timezone, 5, 2) * $min-s)"/>
238
                                                  <xsl:choose>
239
                                                  <xsl:when test="starts-with($start-timezone, '-')">
240
                                                  <xsl:value-of select="$tz"/>
241
                                                  </xsl:when>
242
                                                  <xsl:when test="starts-with($start-timezone, '+')">
243
                                                  <xsl:value-of select="$tz * -1"/>
244
                                                  </xsl:when>
245
                                                  <xsl:otherwise>0</xsl:otherwise>
246
                                                  </xsl:choose>
247
                                                </xsl:variable>
248
                                                <xsl:variable name="end-tz-adj">
249
                                                  <xsl:variable name="tz"
250
                                                  select="(substring($end-timezone, 2, 2) * $hour-s) + (substring($end-timezone, 5, 2) * $min-s)"/>
251
                                                  <xsl:choose>
252
                                                  <xsl:when test="starts-with($end-timezone, '-')">
253
                                                  <xsl:value-of select="$tz"/>
254
                                                  </xsl:when>
255
                                                  <xsl:when test="starts-with($end-timezone, '+')">
256
                                                  <xsl:value-of select="$tz * -1"/>
257
                                                  </xsl:when>
258
                                                  <xsl:otherwise>0</xsl:otherwise>
259
                                                  </xsl:choose>
260
                                                </xsl:variable>
261
                                                <xsl:variable name="start-secs"
262
                                                  select="$start-sec + ($start-min * $min-s) + ($start-hour * $hour-s) + ($start-days * $day-s) + $start-tz-adj"/>
263
                                                <xsl:variable name="end-secs"
264
                                                  select="$end-sec + ($end-min * $min-s) + ($end-hour * $hour-s) + ($end-days * $day-s) + $end-tz-adj"/>
265
                                                <xsl:variable name="diff-secs"
266
                                                  select="$end-secs - $start-secs"/>
267
                                                <xsl:variable name="s"
268
                                                  select="$diff-secs * ((($diff-secs &lt; 0) * -2) + 1)"/>
269
                                                <xsl:variable name="days"
270
                                                  select="floor($s div $day-s)"/>
271
                                                <xsl:variable name="hours"
272
                                                  select="floor(($s - ($days * $day-s)) div $hour-s)"/>
273
                                                <xsl:variable name="mins"
274
                                                  select="floor(($s - ($days * $day-s) - ($hours * $hour-s)) div $min-s)"/>
275
                                                <xsl:variable name="secs"
276
                                                  select="$s - ($days * $day-s) - ($hours * $hour-s) - ($mins * $min-s)"/>
277
                                                <xsl:if test="$diff-secs &lt; 0">-</xsl:if>
278
                                                <xsl:text>P</xsl:text>
279
                                                <xsl:if test="$days">
280
                                                  <xsl:value-of select="$days"/>
281
                                                  <xsl:text>D</xsl:text>
282
                                                </xsl:if>
283
                                                <xsl:if test="$hours or $mins or $secs">T</xsl:if>
284
                                                <xsl:if test="$hours">
285
                                                  <xsl:value-of select="$hours"/>
286
                                                  <xsl:text>H</xsl:text>
287
                                                </xsl:if>
288
                                                <xsl:if test="$mins">
289
                                                  <xsl:value-of select="$mins"/>
290
                                                  <xsl:text>M</xsl:text>
291
                                                </xsl:if>
292
                                                <xsl:if test="$secs">
293
                                                  <xsl:value-of select="$secs"/>
294
                                                  <xsl:text>S</xsl:text>
295
                                                </xsl:if>
296
                                            </xsl:if>
297
                                        </xsl:when>
298
                                    </xsl:choose>
299
                                </xsl:if>
300
                            </xsl:when>
301
                        </xsl:choose>
302
                    </xsl:when>
303
                </xsl:choose>
304
            </xsl:if>
305
        </xsl:variable>
306
        <xsl:value-of select="$difference"/>
307
    </xsl:template>
308
	<xsl:template name="checkURL">
309
		<xsl:param name="url"/>
310
		<xsl:param name="localize"/>
311
		<xsl:choose>
312
			<xsl:when test="$localize">
313
				<xsl:choose>
314
					<xsl:when test="starts-with($url, 'http://hdl.handle.net/')">
315
						<xsl:value-of select="concat('/handle/', substring($url, 23))"/>
316
					</xsl:when>
317
					<xsl:when test="starts-with($url, 'http://datadryad.org/handle/')">
318
						<xsl:value-of select="concat('/handle/', substring($url, 29))"/>
319
					</xsl:when>
320
					<!--
321
						FIXME: this only works until our numbers reach five spaces;
322
						One solution: have a local webservice that resolves all DOIs
323
					-->
324
					<xsl:when test="starts-with($url, 'http://dx.doi.org/10.5061/')">
325
						<xsl:value-of select="concat('/doi?redirect=doi:', substring($url, 19))"/>
326
					</xsl:when>
327
					<xsl:otherwise>
328
						<xsl:value-of select="$url"/>
329
					</xsl:otherwise>
330
				</xsl:choose>
331
			</xsl:when>
332
			<xsl:otherwise>
333
				<xsl:value-of select="$url"/>
334
			</xsl:otherwise>
335
		</xsl:choose>
336
	</xsl:template>
337
	<!--
338
		*********************************************
339
		OpenURL COinS Rendering Template
340
		*********************************************
341
342
		COinS Example:
343
344
		<span class="Z3988"
345
		title="ctx_ver=Z39.88-2004&amp;
346
		rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Adc&amp;
347
		rfr_id=info%3Asid%2Focoins.info%3Agenerator&amp;
348
		rft.title=Making+WordPress+Content+Available+to+Zotero&amp;
349
		rft.aulast=Kraus&amp;
350
		rft.aufirst=Kari&amp;
351
		rft.subject=News&amp;
352
		rft.source=Zotero%3A+The+Next-Generation+Research+Tool&amp;
353
		rft.date=2007-02-08&amp;
354
		rft.type=blogPost&amp;
355
		rft.format=text&amp;
356
		rft.identifier=http://www.zotero.org/blog/making-wordpress-content-available-to-zotero/&amp;
357
		rft.language=English"></span>
358
359
		This Code does not parse authors names, instead relying on dc.contributor to populate the
360
		coins
361
	-->
362
363
	<xsl:template name="renderCOinS">
364
		<xsl:text>ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Adc&amp;</xsl:text>
365
		<xsl:for-each select=".//dim:field[@element = 'identifier']">
366
			<xsl:text>rft_id=</xsl:text>
367
			<xsl:value-of select="encoder:encode(string(.))"/>
368
			<xsl:text>&amp;</xsl:text>
369
		</xsl:for-each>
370
		<xsl:text>rfr_id=info%3Asid%2Fdatadryad.org%3Arepo&amp;</xsl:text>
371
		<xsl:for-each select=".//dim:field">
372
			<xsl:value-of select="concat('rft.', @element,'=',encoder:encode(string(.))) "/>
373
			<xsl:if test="position()!=last()">
374
				<xsl:text>&amp;</xsl:text>
375
			</xsl:if>
376
		</xsl:for-each>
377
	</xsl:template>
378
379
</xsl:stylesheet>