Skip to content

Commit 25097d5

Browse files
committed
Tools: add a XSL to create the Windows/Olson mappings
Since Windows uses its own names for timezones, the Unicode corsotium provides the canonical mapping for the timezones. Use the Unicode CLDR to generate the mapping plist requires transformation, which this XSLT provides. These XSLs allow the creation of both the Olson -> Windows mapping and the Windows -> Olson mapping. Since the latter only preserves the primary name and not the secondary ones, we split the inverted database.
1 parent d433b20 commit 25097d5

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
This XSL transforms the Windows Timezone list from the Unicode CLDR to a plist
4+
which is consumable by CoreFoundation. You need to fetch the lastest mapping
5+
from the Unicode consortium from:
6+
https://unicode.org/repos/cldr/trunk/common/supplemental/windowsZones.xml
7+
The XSL can be applied to this data via the `xsltproc` command.
8+
Running
9+
`xsltproc &dash;&dash;novalid OlsonWindowsDatabase.xsl windowsZones.xml`
10+
will generate the mapping plist.
11+
-->
12+
<xsl:stylesheet version="1.0"
13+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
14+
xmlns:ext="http://exslt.org/common"
15+
exclude-result-prefixes="ext">
16+
<xsl:output encoding="utf-8" indent="yes" />
17+
18+
<xsl:template name="tokenize">
19+
<xsl:param name="string" />
20+
<xsl:param name="delimiter" />
21+
22+
<xsl:choose>
23+
<xsl:when test="not($string)"><items><item/></items></xsl:when>
24+
<xsl:when test="not(contains($string, $delimiter))" ><items><item><xsl:value-of select="$string" /></item></items></xsl:when>
25+
<xsl:otherwise><items><item><xsl:value-of select="normalize-space(substring-before($string, $delimiter))" /></item><xsl:call-template name="tokenize">
26+
<xsl:with-param name="string" select="substring-after($string, $delimiter)" />
27+
<xsl:with-param name="delimiter" select="$delimiter" />
28+
</xsl:call-template></items>
29+
</xsl:otherwise>
30+
</xsl:choose>
31+
</xsl:template>
32+
33+
<xsl:template match="/">
34+
<xsl:text disable-output-escaping="yes">&lt;!DOCTYPE plist SYSTEM "file:///localhost/System/Library/DTDs/PropertyList.dtd"&gt;
35+
</xsl:text>
36+
<plist version="1.0">
37+
<dict>
38+
<xsl:for-each select="supplementalData/windowsZones/mapTimezones/mapZone[not(@territory='001')]">
39+
<xsl:variable name="names">
40+
<xsl:call-template name="tokenize">
41+
<xsl:with-param name="string" select="@type" />
42+
<xsl:with-param name="delimiter" select="' '" />
43+
</xsl:call-template>
44+
</xsl:variable>
45+
<key><xsl:value-of select="ext:node-set($names)/items/*" /></key>
46+
<string><xsl:value-of select="@other" /></string>
47+
</xsl:for-each>
48+
</dict>
49+
</plist>
50+
</xsl:template>
51+
</xsl:stylesheet>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
This XSL transforms the Windows Timezone list from the Unicode CLDR to a plist
4+
which is consumable by CoreFoundation. You need to fetch the lastest mapping
5+
from the Unicode consortium from:
6+
https://unicode.org/repos/cldr/trunk/common/supplemental/windowsZones.xml
7+
The XSL can be applied to this data via the `xsltproc` command.
8+
Running
9+
`xsltproc &dash;&dash;novalid WindowsOlsonDatabase.xsl windowsZones.xml`
10+
will generate the mapping plist.
11+
-->
12+
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
13+
<xsl:output encoding="utf-8" indent="yes" />
14+
15+
<xsl:template match="/">
16+
<xsl:text disable-output-escaping="yes">&lt;!DOCTYPE plist SYSTEM "file:///localhost/System/Library/DTDs/PropertyList.dtd"&gt;
17+
</xsl:text>
18+
<plist version="1.0">
19+
<dict>
20+
<xsl:for-each select="supplementalData/windowsZones/mapTimezones/mapZone[@territory='001']">
21+
<key><xsl:value-of select="@other" /></key>
22+
<string><xsl:value-of select="@type" /></string>
23+
</xsl:for-each>
24+
</dict>
25+
</plist>
26+
</xsl:template>
27+
</xsl:stylesheet>

0 commit comments

Comments
 (0)