-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdates.range.xsl
103 lines (84 loc) · 3.27 KB
/
dates.range.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
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:kit="https://hananils.de/xslt/kit">
<!--
* hana+nils · Büro für Gestaltung
* https://hananils.de · [email protected]
-->
<xsl:import href="dates.xsl" />
<xsl:import href="dates.time.xsl" />
<!--
* Kit: Date Ranges
*
* This template creates readable date and time ranges.
*
* # Example usage
*
* <xsl:apply-templates select="dates" mode="kit:dates-range" />
*
* # Parameters
*
* - show-date
* Whether to display the date or not, defaults to true
* - show-time
* Whether to display the time or not, defaults to true
* - separator-datetime
* A string used to separate date and time values, defaults to comma and space
* - separator-times
* A string used to separate times, defaults to a n-dash
-->
<xsl:template match="*" mode="kit:dates-range">
<xsl:param name="show-date" select="true()" />
<xsl:param name="show-time" select="true()" />
<xsl:param name="separator-datetime" select="', '" />
<xsl:param name="separator-times" select="'–'" />
<!-- Timerange -->
<xsl:choose>
<!-- Same day -->
<xsl:when test="start = end or not(end)">
<xsl:if test="$show-date = true()">
<xsl:apply-templates match="start" mode="kit:dates">
<xsl:with-param name="format" select="'long'" />
</xsl:apply-templates>
</xsl:if>
<xsl:if test="$show-date = true() and $show-time = true()">
<xsl:value-of select="$separator-datetime" />
</xsl:if>
<xsl:if test="$show-time = true()">
<xsl:apply-templates select="start" mode="kit:dates-time" />
<xsl:if test="start/@time and end/time">
<xsl:value-of select="$separator-times" />
</xsl:if>
<xsl:apply-templates select="end" mode="kit:dates-time" />
</xsl:if>
</xsl:when>
<!-- Different day -->
<xsl:otherwise>
<xsl:if test="$show-date = true()">
<xsl:apply-templates match="start" mode="kit:dates">
<xsl:with-param name="format" select="'long'" />
</xsl:apply-templates>
</xsl:if>
<xsl:if test="$show-date = true() and $show-time = true()">
<xsl:value-of select="$separator-datetime" />
</xsl:if>
<xsl:if test="$show-time = true()">
<xsl:apply-templates select="start" mode="kit:dates-time" />
</xsl:if>
<xsl:value-of select="concat(' ', $separator-times, ' ')" />
<xsl:if test="$show-date = true()">
<xsl:apply-templates match="end" mode="kit:dates">
<xsl:with-param name="format" select="'long'" />
</xsl:apply-templates>
</xsl:if>
<xsl:if test="$show-date = true() and $show-time = true()">
<xsl:value-of select="$separator-datetime" />
</xsl:if>
<xsl:if test="$show-time = true()">
<xsl:apply-templates select="end" mode="kit:dates-time" />
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>