Feed history in asp.net 2.0

With the xml obtained in the previous post we can databind it to the asp.net treeview to obtain the blog's history similar to the one shown in blogger UI. My site uses CSS friendly adapters so I needed some css to tweak the visual appearance.

I had to slightly change the xslt to get descending date order, to add subtotals of post per year/month/day and the month name instead of the month number.

 1: <span>Blog history</span>
 2: <asp:TreeView ID="TreeView1" runat="server" DataSourceID="XmlDataSource1" OnSelectedNodeChanged="TreeView1_SelectedNodeChanged"
 3: ImageSet="Arrows" AutoGenerateDataBindings="False" LineImagesFolder="~/TreeLineImages"
 4: ShowLines="True" Width="361px" EnableTheming="False" EnableViewState="False">
 5: <DataBindings>
 6: <asp:TreeNodeBinding DataMember="year" TextField="name" />
 7: <asp:TreeNodeBinding DataMember="month" TextField="name" />
 8: <asp:TreeNodeBinding DataMember="day" TextField="name" />
 9: <asp:TreeNodeBinding DataMember="a" NavigateUrlField="href" TextField="#InnerText" />
 10: </DataBindings>
 11: <ParentNodeStyle Font-Bold="False" />
 12: <HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
 13: <SelectedNodeStyle Font-Underline="True" HorizontalPadding="0px" VerticalPadding="0px" ForeColor="#5555DD" />
 14: <NodeStyle Font-Names="Tahoma" Font-Size="10pt" ForeColor="Black" HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" />
 15: </asp:TreeView>
 16: &nbsp;
 17: <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/feed.xml" XPath="/FeedHierarchy/year"
 18: OnTransforming="XmlDataSource1_Transforming" TransformFile="/IlViale/Tests/Atom2tree.xslt">
 19: </asp:XmlDataSource>

The final xslt is

 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)" />&lt;span>(<xsl:value-of select="count(key('year', substring(atom:published, 0, 5)))"/>)&lt;/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: &lt;span>
 34: (<xsl:value-of select="count(key('month', substring(atom:published, 0, 8)))"/>)
 35: &lt;/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: &lt;span>
 43: (<xsl:value-of select="count(key('day', substring(atom:published, 0, 11)))"/>)
 44: &lt;/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>

I also added a simple css to create a border with a title on it (saying "blog history") and styling the tree appareance.

BlogHistory

You can get here a 'live' version. 

Technorati Tags: , , , , ,

posted @ lunedì 29 ottobre 2007 02:11

Print
Comments have been closed on this topic.
«novembre»
domlunmarmergiovensab
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567