1: <?xml version="1.0" encoding="ISO-8859-1"?>
2: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3: xmlns:msxsl="urn:schemas-microsoft-com:xslt"
4: xmlns:cs="urn:cs"
5: xmlns:js="urn:custom-javascript"
6: exclude-result-prefixes="msxsl js"
7: >
8:
9: <msxsl:script language="c#" implements-prefix="cs">
10: <![CDATA[
11: public static string UXDate( string pubDate )
12: { 13: DateTime d = DateTime.Parse( pubDate );
14: DateTime now = DateTime.Now;
15: TimeSpan timeSince = now - d;
16:
17: double inSeconds = timeSince.TotalSeconds;
18: double inMinutes = timeSince.TotalMinutes;
19: double inHours = timeSince.TotalHours;
20: double inDays = timeSince.TotalDays;
21: double inMonths = inDays / 30;
22: double inYears = inDays / 365;
23:
24: if(Math.Round(inSeconds) == 1){ 25: return "1 second ago";
26: }
27: else if(inMinutes < 1.0){ 28: return Math.Floor(inSeconds) + " seconds ago";
29: }
30: else if(Math.Floor(inMinutes) == 1){ 31: return "1 minute ago";
32: }
33: else if(inHours < 1.0){ 34: return Math.Floor(inMinutes) + " minutes ago";
35: }
36: else if(Math.Floor(inHours) == 1){ 37: return "about an hour ago";
38: }
39: else if(inDays < 1.0){ 40: return Math.Floor(inHours) + " hours ago";
41: }
42: else if(Math.Floor(inDays) == 1){ 43: return "1 day ago";
44: }
45: else if(inMonths < 3 ){ 46: return Math.Floor(inDays) + " days ago";
47: }
48: else if(inMonths <= 12 ){ 49: return Math.Floor(inMonths) + " months ago ";
50: }
51: else if(Math.Floor(inYears) <= 1){ 52: return "1 year ago";
53: }
54: else
55: { 56: return Math.Floor(inYears) + " years ago";
57: }
58: }
59: ]]>
60: </msxsl:script>
61:
62: <xsl:template match="rss/channel">
63: <style>
64: #tweets a { 65: text-decoration: none;
66: color: #444;
67: }
68:
69: #tweets span { 70: font-family: Verdana, Helvetica, sans-serif;
71: font-size: 9px;
72: color: #888;
73: font-style: italic;
74: }
75: </style>
76:
77: <div id="tweets" style="padding-left:5px;font-family: Verdana, Helvetica, sans-serif; font-size: 10px; width: 500px;">
78: <xsl:for-each select="item[position() <= 5]">
79: <p>
80: <a href="{link}"> 81: <xsl:value-of select="substring-after(title,': ')" />
82: </a>
83: <br/><span><xsl:value-of select="cs:UXDate(pubDate)" /></span>
84: </p>
85: </xsl:for-each>
86: </div>
87: </xsl:template>
88: </xsl:stylesheet>