-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathamc-trips-to-ical.xsl
491 lines (446 loc) · 20.5 KB
/
amc-trips-to-ical.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
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:date="http://exslt.org/dates-and-times"
extension-element-prefixes="date">
<xsl:import href="amc-trips-to-html-inc.xsl" />
<!--xsl:import href="functions/date/date.add.template.xsl"/-->
<xsl:import href="functions/date/date.add.function.xsl"/>
<xsl:output encoding="UTF-8" indent="yes" method="text"/>
<xsl:param name="groupTitle">AMC</xsl:param>
<xsl:template name="obfuscatedEmailLink">
<xsl:param name="address"/>
<xsl:value-of select="$address"/>
</xsl:template>
<xsl:template match="trips">
<xsl:call-template name="emit_text">
<xsl:with-param name="line">
<xsl:text>BEGIN:VCALENDAR</xsl:text>
</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="emit_text">
<xsl:with-param name="line">
<xsl:text>VERSION:2.0</xsl:text>
</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="emit_text">
<xsl:with-param name="line">
<xsl:text>X-WR-CALNAME:</xsl:text>
<xsl:value-of select="$groupTitle"/>
<xsl:text> Trip Listings</xsl:text>
</xsl:with-param>
</xsl:call-template>
<!-- PRODID:-//Apple Computer\, Inc//iCal 1.5//EN
X-WR-RELCALID:472DCB8C-5E99-11D9-AC8C-000393B3AC06 -->
<xsl:call-template name="emit_text">
<xsl:with-param name="line">
<xsl:text>X-WR-TIMEZONE:US/Eastern</xsl:text>
</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="emit_text">
<xsl:with-param name="line">
<xsl:text>CALSCALE:GREGORIAN</xsl:text>
</xsl:with-param>
</xsl:call-template>
<xsl:for-each select="*">
<xsl:call-template name="amc-trip-to-ical"/>
</xsl:for-each>
<xsl:call-template name="emit_text">
<xsl:with-param name="line">
<xsl:text>END:VCALENDAR</xsl:text>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name="amc-trip-to-ical">
<!--div class="sponsor"><xsl:value-of select="committee"/></div-->
<!--span class="date">
<xsl:call-template name="date-range">
<xsl:with-param name="start_date"><xsl:value-of select="trip_start_date"/></xsl:with-param>
<xsl:with-param name="end_date"><xsl:value-of select="trip_end_date"/></xsl:with-param>
</xsl:call-template>
</span-->
<!--xsl:if test="rating">
<xsl:text> </xsl:text>
<xsl:apply-templates select="rating" />
</xsl:if-->
<xsl:call-template name="emit_text">
<xsl:with-param name="line">
<xsl:text>BEGIN:VEVENT</xsl:text>
</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="emit_text">
<xsl:with-param name="line">
<xsl:text>UID:</xsl:text>
<xsl:value-of select="trip_id"/>
</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="emit_text">
<xsl:with-param name="line">
<xsl:text>DTSTAMP:</xsl:text>
<xsl:call-template name="USToW3CDateTime">
<xsl:with-param name="date" select="last_updated"/><!-- +++ must convert to UTC -->
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="emit_text">
<xsl:with-param name="line">
<xsl:text>LAST-MODIFIED:TZID=US/Eastern:</xsl:text>
<xsl:call-template name="USToW3CDateTime">
<xsl:with-param name="date" select="last_updated"/>
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="emit_text">
<xsl:with-param name="line">
<xsl:text>DTSTART;TZID=US/Eastern:</xsl:text>
<xsl:call-template name="USToW3CDate">
<xsl:with-param name="date" select="trip_start_date"/>
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="emit_text">
<xsl:with-param name="line">
<xsl:text>DTEND;TZID=US/Eastern:</xsl:text>
<xsl:choose>
<xsl:when test="function-available('date:add')">
<xsl:call-template name="USToW3CDate">
<xsl:with-param name="date" select="date:add(substring(trip_end_date, 0, 11),'P1D')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="USToW3CDate">
<xsl:with-param name="date">
<xsl:call-template name="date:add">
<xsl:with-param name="date-time" select="substring(trip_end_date, 0, 11)"/>
<xsl:with-param name="duration" select="'P1D'"/>
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="emit_text">
<xsl:with-param name="line">
<xsl:text>SUMMARY:</xsl:text>
<xsl:call-template name="quote-some">
<xsl:with-param name="text"><xsl:value-of select="trip_title"/>
<xsl:if test="@new"><xsl:text> </xsl:text><span class="tagNew">New</span></xsl:if>
<xsl:if test="@full or status = 'Full'"><xsl:text> </xsl:text><span class="tagFull">Full</span></xsl:if>
<xsl:if test="@wait or status = 'Waitlist'"><xsl:text> </xsl:text><span class="tagWaitlist">Waitlist</span></xsl:if>
<xsl:if test="@cancel or status = 'Cancelled' or status = 'Canceled'"><xsl:text> </xsl:text><span class="tagCancel">Cancelled</span></xsl:if>
</xsl:with-param>
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="emit_text">
<xsl:with-param name="line">
<xsl:text>DESCRIPTION:</xsl:text>
<xsl:call-template name="quote-some">
<xsl:with-param name="text">
<xsl:value-of select="web_desc"/>
<xsl:text> </xsl:text>
<xsl:call-template name="regAndLeaderInfo"/>
</xsl:with-param>
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
<xsl:if test="normalize-space(external_link)">
<xsl:call-template name="emit_text">
<xsl:with-param name="line">
<xsl:text>URL;VALUE=URI:</xsl:text>
<xsl:call-template name="quote-some">
<xsl:with-param name="text">
<xsl:value-of select="external_link"/>
</xsl:with-param>
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
</xsl:if>
<xsl:if test="normalize-space(leader1_email)">
<xsl:call-template name="emit_text">
<xsl:with-param name="line">
<xsl:text>ORGANIZER;CN="</xsl:text>
<xsl:call-template name="quote-some">
<xsl:with-param name="text">
<xsl:value-of select="leader1"/>
</xsl:with-param>
</xsl:call-template>
<xsl:text>"</xsl:text>
<xsl:if test="normalize-space(leader1_email)">
<xsl:text>:MAILTO:</xsl:text>
<xsl:call-template name="quote-some">
<xsl:with-param name="text">
<xsl:value-of select="leader1_email"/>
</xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:with-param>
</xsl:call-template>
</xsl:if>
<xsl:call-template name="emit_text">
<xsl:with-param name="line">
<xsl:text>END:VEVENT</xsl:text>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name="regAndLeaderInfo">
<xsl:if test="registration_required = 'Yes' and not(normalize-space(registrar)) and not(normalize-space(external_link))">Reg. req’d. </xsl:if>
<xsl:if test="normalize-space(external_link)">
<xsl:choose>
<xsl:when test="registration_required = 'Yes' and not(normalize-space(registrar))"> Reg. at </xsl:when>
<xsl:otherwise> See </xsl:otherwise>
</xsl:choose>
<a href="{external_link}"><xsl:value-of select="external_link"/></a>.<xsl:text> </xsl:text>
</xsl:if>
<xsl:variable name="regOverridesCL1" select="normalize-space(registrar) and registrar = coleader1 and (not(normalize-space(coleader1_phone)) or registrar_phone = coleader1_phone) and (not(normalize-space(coleader1_email)) or registrar_email = coleader1_email)"/>
<xsl:variable name="regOverridesL1" select="not($regOverridesCL1) and normalize-space(registrar) and registrar = leader1 and (not(normalize-space(leader1_phone)) or registrar_phone = leader1_phone) and (not(normalize-space(leader1_email)) or registrar_email = leader1_email)"/>
<xsl:if test="normalize-space(registrar)">
<xsl:text> Reg. with </xsl:text>
<xsl:if test="$regOverridesCL1"> CL </xsl:if>
<xsl:if test="$regOverridesL1"> L </xsl:if>
<xsl:call-template name="joyst-leader">
<xsl:with-param name="isFirst" select="1"/>
<xsl:with-param name="nodeName">registrar</xsl:with-param>
</xsl:call-template>
<xsl:text>. </xsl:text>
</xsl:if>
<xsl:if test="(normalize-space(leader1) and not($regOverridesL1)) or normalize-space(concat(leader2,leader3,leader4))">
<span class="leaders">
<xsl:text>L </xsl:text>
<xsl:if test="not($regOverridesL1)">
<xsl:call-template name="joyst-leader">
<xsl:with-param name="isFirst" select="1"/>
<xsl:with-param name="nodeName">leader1</xsl:with-param>
</xsl:call-template>
</xsl:if>
<xsl:call-template name="joyst-leader">
<xsl:with-param name="isFirst" select="$regOverridesL1"/>
<xsl:with-param name="nodeName">leader2</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="joyst-leader">
<xsl:with-param name="nodeName">leader3</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="joyst-leader">
<xsl:with-param name="nodeName">leader4</xsl:with-param>
</xsl:call-template>. </span>
</xsl:if>
<xsl:if test="(normalize-space(coleader1) and not($regOverridesCL1)) or normalize-space(concat(coleader2,coleader3,coleader4))">
<span class="leaders">
<xsl:text>CL </xsl:text>
<xsl:if test="not($regOverridesCL1)">
<xsl:call-template name="joyst-leader">
<xsl:with-param name="isFirst" select="1"/>
<xsl:with-param name="nodeName">coleader1</xsl:with-param>
</xsl:call-template>
</xsl:if>
<xsl:call-template name="joyst-leader">
<xsl:with-param name="isFirst" select="$regOverridesCL1"/>
<xsl:with-param name="nodeName">coleader2</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="joyst-leader">
<xsl:with-param name="nodeName">coleader3</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="joyst-leader">
<xsl:with-param name="nodeName">coleader4</xsl:with-param>
</xsl:call-template>.</span>
</xsl:if>
</xsl:template>
<!-- xCalendar to iCalendar utility functions, based on
http://ietfreport.isoc.org/idref/draft-hare-xcalendar/ -->
<!-- Emit text, 75 character max per line, recursively -->
<!-- bug fix: don't call normalize_space on the argument, because
it was being called inconsistently, which sometimes led to doubled-up chars
when splitting lines (first line used normalize_space, second line started at
the offset where the first ended but didn't).
Also, each line was progressively one char shorter. -->
<xsl:template name="emit_text">
<xsl:param name="limit" select="number(75)"/> <!-- default limit is 75 " -->
<xsl:param name="line"/>
<xsl:value-of select="substring($line,1,$limit)"/>
<!-- Output the newline string -->
<xsl:text> </xsl:text>
<xsl:if test="string-length($line) > $limit">
<xsl:call-template name="emit_text">
<xsl:with-param name="limit" select="$limit"/>
<!-- +++ bug fix: iCal ignores leading whitespace on subsequent lines,
leading to words running together from opposite sides of a line break. -->
<xsl:with-param name="line" select="concat(' ',substring($line,($limit + 1)))"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<!-- ACK: ASPN replace-string function used to model this
http://aspn.activestate.com/ASPN/Cookbook/XSLT/Recipe/65426
via Dan Connolly, W3C
all characters to be quoted are in this template rather than doing multiple calls to the template
in the hopes that this will improve performance.
-->
<xsl:template name="quote-some">
<!-- rfc2445#sec4.3.11 says to quote DQUOTE, newline, semicolon, colon,
reverse solidus, comma -->
<!-- bugs in original:
* $after var is named $before; conflicts with real $before var
* $after var is referenced by invalid entity &after (no trailing semi), not dollar sign
* replacement text isn't quoted in value-of select attribute value
* order of testing for special chars means that each special char
will hide all other special chars that happen to occur nearer
the beginning of the string but are tested for subsequently
(e.g. if the string contains a double quote, no other special
chars will be escaped up to that point)
-->
<xsl:variable name="text2">
<xsl:call-template name="my-replace-string">
<xsl:with-param name="text" select="$text"/>
<xsl:with-param name="from" select="'\'"/>
<xsl:with-param name="to" select="'\\'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="text3">
<xsl:call-template name="my-replace-string">
<xsl:with-param name="text" select="$text2"/>
<xsl:with-param name="from" select="'"'"/>
<xsl:with-param name="to" select="'\"'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="text4">
<xsl:call-template name="my-replace-string">
<xsl:with-param name="text" select="$text3"/>
<xsl:with-param name="from" select="' '"/>
<xsl:with-param name="to" select="'\n'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="text5">
<xsl:call-template name="my-replace-string">
<xsl:with-param name="text" select="$text4"/>
<xsl:with-param name="from" select="';'"/>
<xsl:with-param name="to" select="'\;'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="text6">
<xsl:call-template name="my-replace-string">
<xsl:with-param name="text" select="$text5"/>
<xsl:with-param name="from" select="':'"/>
<xsl:with-param name="to" select="':'"/> <!-- disabled -->
</xsl:call-template>
</xsl:variable>
<xsl:variable name="text7">
<xsl:call-template name="my-replace-string">
<xsl:with-param name="text" select="$text6"/>
<xsl:with-param name="from" select="','"/>
<xsl:with-param name="to" select="'\,'"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$text7"/>
</xsl:template>
<xsl:template name="my-replace-string">
<xsl:param name="from"/>
<xsl:param name="to"/>
<xsl:param name="text"/>
<xsl:choose>
<xsl:when test="contains($text,$from)">
<xsl:value-of select="substring-before($text,$from)"/>
<xsl:value-of select="$to"/>
<xsl:call-template name="my-replace-string">
<xsl:with-param name="text" select="substring-after($text,$from)"/>
<xsl:with-param name="from" select="$from"/>
<xsl:with-param name="to" select="$to"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="USToW3CDate">
<xsl:param name="date"/>
<xsl:value-of select="substring($date,1,4)"/>
<xsl:value-of select="substring($date,6,2)"/>
<xsl:value-of select="substring($date,9,2)"/>
</xsl:template>
<xsl:template name="USToW3CDateTime">
<xsl:param name="date"/>
<xsl:value-of select="substring($date,1,4)"/>
<xsl:value-of select="substring($date,6,2)"/>
<xsl:value-of select="substring($date,9,2)"/>
<xsl:text>T</xsl:text>
<xsl:value-of select="substring($date,12,2)"/>
<xsl:value-of select="substring($date,15,2)"/>
<xsl:value-of select="substring($date,18,2)"/>
</xsl:template>
<!--xsl:choose>
<xsl:when test="contains($text,$from)">
<xsl:variable name="before" select="substring-before($text,$from)"/>
<xsl:variable name="after" select="substring-after($text,$from)"/>
<xsl:call-template name="quote-some">
<xsl:with-param name="text" select="$before"/>
</xsl:call-template>
<xsl:value-of select="'\\"'" />
<xsl:call-template name="quote-some">
<xsl:with-param name="text" select="$after" />
</xsl:call-template>
</xsl:when>
<xsl:when test="contains($text,' ')">
<xsl:variable name="before" select="substring-before($text,' ')"/>
<xsl:variable name="after" select="substring-after($text,' ')"/>
<xsl:call-template name="quote-some">
<xsl:with-param name="text" select="$before"/>
</xsl:call-template>
<xsl:value-of select="'\n'" />
<xsl:call-template name="quote-some">
<xsl:with-param name="text" select="$after" />
</xsl:call-template>
</xsl:when>
<xsl:when test="contains($text,';')">
<xsl:variable name="before" select="substring-before($text,';')"/>
<xsl:variable name="after" select="substring-after($text,';')"/>
<xsl:call-template name="quote-some">
<xsl:with-param name="text" select="$before"/>
</xsl:call-template>
<xsl:value-of select="'\;'" />
<xsl:call-template name="quote-some">
<xsl:with-param name="text" select="$after" />
</xsl:call-template>
</xsl:when>
<xsl:when test="contains($text,':')">
<xsl:variable name="before" select="substring-before($text,':')"/>
<xsl:variable name="after" select="substring-after($text,':')"/>
<xsl:call-template name="quote-some">
<xsl:with-param name="text" select="$before"/>
</xsl:call-template>
<xsl:value-of select="'\:'" />
<xsl:call-template name="quote-some">
<xsl:with-param name="text" select="$after" />
</xsl:call-template>
</xsl:when>
<xsl:when test="contains($text,'\\')">
<xsl:variable name="before" select="substring-before($text,'\\')"/>
<xsl:variable name="after" select="substring-after($text,'\\')"/>
<xsl:call-template name="quote-some">
<xsl:with-param name="text" select="$before"/>
</xsl:call-template>
<xsl:value-of select="'\\'" />
<xsl:call-template name="quote-some">
<xsl:with-param name="text" select="$after" />
</xsl:call-template>
</xsl:when>
<xsl:when test="contains($text,',')">
<xsl:variable name="before" select="substring-before($text,',')"/>
<xsl:variable name="after" select="substring-after($text,',')"/>
<xsl:call-template name="quote-some">
<xsl:with-param name="text" select="$before"/>
</xsl:call-template>
<xsl:value-of select="'\,'" />
<xsl:call-template name="quote-some">
<xsl:with-param name="text" select="$after" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template-->
</xsl:stylesheet>
<!--
Local Variables:
coding: utf-8;
End:
-->