-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdates.xsl
115 lines (103 loc) · 3.87 KB
/
dates.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
<?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:include href="languages.xsl" />
<!--
* Kit: Dates
*
* This template formats dates to one of the following formats:
*
* - long
* The full date with day, long month and long year
* - short
* The full date with day, shortened month and long year
* - numeric
* The full date in localized tabular format
*
* # Example usage
*
* <xsl:apply-templates select="date" mode="kit:dates" />
*
* # Parameters
*
* - format
* The output format, either long, short or numeric, defaults to numeric
* - zero
* Whether to include a leading zero or not, defaults to false
*
* # Requirements
*
* The template requires the `datetime` and date type nodes from Kirby XSLT,
* https://github.com/hananils/kirby-xslt
-->
<xsl:template match="*" mode="kit:dates">
<xsl:param name="format" select="numeric" />
<xsl:param name="zero" select="false()" />
<xsl:variable name="month" select="/data/datetime/language[@id = $kit:language-code]/months/month[@id = current()/@month]" />
<xsl:variable name="number-format">
<xsl:choose>
<xsl:when test="$zero = true()">00</xsl:when>
<xsl:otherwise>#0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="$kit:language-code = 'de'">
<xsl:apply-templates select="." mode="kit:dates-formatter-german">
<xsl:with-param name="format" select="$format" />
<xsl:with-param name="month" select="$month" />
<xsl:with-param name="number-format" select="$number-format" />
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="." mode="kit:dates-formatter-english">
<xsl:with-param name="format" select="$format" />
<xsl:with-param name="month" select="$month" />
<xsl:with-param name="number-format" select="$number-format" />
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--
German
-->
<xsl:template match="*" mode="kit:dates-formatter-german">
<xsl:param name="format" select="numeric" />
<xsl:param name="month" />
<xsl:param name="number-format" />
<xsl:choose>
<xsl:when test="$format = 'long' and $month != ''">
<xsl:value-of select="concat(format-number(@day, $number-format), '. ', $month, ' ', @year)" />
</xsl:when>
<xsl:when test="$format = 'short' and $month != ''">
<xsl:value-of select="concat(format-number(@day, $number-format), '. ', $month/@abbr, '. ', @year)" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat(format-number(@day, $number-format), '.', format-number(@month, $number-format), '.', @year)" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!--
English
-->
<xsl:template match="*" mode="kit:dates-formatter-english">
<xsl:param name="format" select="numeric" />
<xsl:param name="month" />
<xsl:param name="number-format" />
<xsl:choose>
<xsl:when test="$format = 'long' and $month != ''">
<xsl:value-of select="concat($month, ' ', format-number(@day, $number-format), ', ', @year)" />
</xsl:when>
<xsl:when test="$format = 'short' and $month != ''">
<xsl:value-of select="concat($month/@abbr, '. ', format-number(@day, $number-format), ', ', @year)" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat(format-number(@day, $number-format), '/', format-number(@month, $number-format), '/', @year)" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>