1: <?xml version="1.0" encoding="utf-8"?>
2: <!--http://www.jenitennison.com/xslt/grouping/muenchian.html -->
3: <xsl:stylesheet version="1.0"
4: xmlns:atom="http://www.w3.org/2005/Atom"
5: xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
6: xmlns:dc="http://purl.org/dc/elements/1.1/">
7: <xsl:output method="xml"/>
8: <xsl:template match="/">
9: <xsl:apply-templates select="/atom:feed"/>
10: </xsl:template>
11: <xsl:key name="year" match="atom:entry" use="substring(atom:published, 0, 5)" />
12: <xsl:key name="month" match="atom:entry" use="substring(atom:published, 0, 8)" />
13: <xsl:key name="day" match="atom:entry" use="substring(atom:published, 0, 11)" />
14: <xsl:template match="/atom:feed">
15: <FeedHierarchy>
16: <xsl:for-each select="atom:entry[count(. | key('year', substring(atom:published, 0, 5))[1]) = 1]">
17: <xsl:sort select="substring(atom:published, 6, 2)" order="descending"/>
18: <year>
19: <xsl:attribute name="name">
20: <xsl:value-of select="substring(atom:published, 0, 5)" /><span>(<xsl:value-of select="count(key('year', substring(atom:published, 0, 5)))"/>)</span>
21: </xsl:attribute>
22:
23: <xsl:for-each select="key('year', substring(atom:published, 0, 5))[count(. | key('month', substring(atom:published, 0, 8))[1]) = 1]">
24: <xsl:sort select="substring(atom:published, 6, 2)" order="descending"/>
25: <month>
26: <xsl:attribute name="name">
27: <xsl:call-template name="decode">
28: <xsl:with-param name="id">
29: <xsl:value-of select="substring(atom:published, 6, 2)" />
30: </xsl:with-param>
31: <xsl:with-param name="locale">us</xsl:with-param>
32: </xsl:call-template>
33: <span>
34: (<xsl:value-of select="count(key('month', substring(atom:published, 0, 8)))"/>)
35: </span>
36: </xsl:attribute>
37: <xsl:for-each select="key('month', substring(atom:published, 0, 8))[count(. | key('day', substring(atom:published, 0, 11))[1]) = 1]">
38: <xsl:sort select="substring(atom:published, 0, 11)" order="descending"/>
39: <day>
40: <xsl:attribute name="name">
41: <xsl:value-of select="substring(atom:published, 9, 2)" />
42: <span>
43: (<xsl:value-of select="count(key('day', substring(atom:published, 0, 11)))"/>)
44: </span>
45: </xsl:attribute>
46: <!--<xsl:value-of select="atom:published" />,<br />-->
47: <xsl:for-each select="key('day', substring(atom:published, 0, 11))">
48:
49: <xsl:sort select="substring(atom:published, 9, 2)" />
50:
51: <a>
52: <xsl:attribute name="href">
53: ?PostId=<xsl:value-of select="atom:id" />
54: </xsl:attribute>
55: <xsl:value-of select="atom:title" />
56: </a>
57:
58: </xsl:for-each>
59: </day>
60: </xsl:for-each>
61: </month>
62:
63: </xsl:for-each>
64: </year>
65: </xsl:for-each>
66: </FeedHierarchy>
67: </xsl:template>
68: <xsl:template name="decode">
69: <xsl:param name="id"/>
70: <xsl:param name="locale"/>
71: <xsl:choose>
72: <xsl:when test="$id = 01">
73: january
74: </xsl:when>
75: <xsl:when test="$id = 02">
76: february
77: </xsl:when>
78: <xsl:when test="$id = 03">
79: march
80: </xsl:when>
81: <xsl:when test="$id = 04">
82: april
83: </xsl:when>
84: <xsl:when test="$id = 05">
85: may
86: </xsl:when>
87: <xsl:when test="$id = 06">
88: june
89: </xsl:when>
90: <xsl:when test="$id = 07">
91: july
92: </xsl:when>
93: <xsl:when test="$id = 08">
94: august
95: </xsl:when>
96: <xsl:when test="$id = 09">
97: september
98: </xsl:when>
99: <xsl:when test="$id = 10">
100: october
101: </xsl:when>
102: <xsl:when test="$id = 11">
103: november
104: </xsl:when>
105: <xsl:when test="$id = 12">
106: december
107: </xsl:when>
108: <xsl:otherwise>
109: wrong month id
110: </xsl:otherwise>
111: </xsl:choose>
112:
113: </xsl:template>
114: </xsl:stylesheet>