<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:date="http://exslt.org/dates-and-times" extension-element-prefixes="date">
    <xsl:template match="item">
       <xsl:choose>
          <xsl:when test="position() &lt; 6">
             <li style="background-position:0 -1732px; list-style-type:none; margin: 0 0 0.1em 0.6em; padding-left:8px; list-style-position:outside;" class="elements-img"><em><a class="med-small" href="{ link }"><xsl:value-of select="title"/> </a></em><q class="alt-text-color" style="font-size:70%;font-family:Verdana;white-space:nowrap;"> - <xsl:variable name="time"><xsl:call-template name="convertDate"><xsl:with-param name="date"> <xsl:value-of select="pubDate" /> </xsl:with-param> </xsl:call-template> </xsl:variable><xsl:call-template name="reltime"><xsl:with-param name="time" select="$time" /></xsl:call-template></q></li>
          </xsl:when>
       </xsl:choose>
    </xsl:template>
    <xsl:template name="convertDate">
	<xsl:param name="date" />
        <xsl:choose>
            <xsl:when test="string-length($date) &lt; 28">
                <xsl:variable name="year">
                     <xsl:value-of select="substring-after($date,', ') "/>
                </xsl:variable>
                <xsl:value-of select="concat($year,'-')"/>
                <xsl:variable name="month">
                    <xsl:value-of select="substring-before($date,' ')"/>
                </xsl:variable>
                <xsl:call-template name="mToNumber">
                    <xsl:with-param name="month" select="substring($month,0,4)" />
                </xsl:call-template>
                <xsl:variable name="day">
                     <xsl:value-of select="substring-before(substring-after($date,concat($month,' ')),',')"/>
                </xsl:variable>
                <xsl:variable name="nday">
                    <xsl:if test="string-length($day) &lt;=1">
                        <xsl:value-of select="concat('0',$day)"/>
                    </xsl:if>
                    <xsl:if test="string-length($day) &gt; 1">
                        <xsl:value-of select="$day"/>
                    </xsl:if>
                </xsl:variable>
                <xsl:value-of select="concat('-',$nday,'T00:00:00Z')"/>
            </xsl:when>
            <xsl:otherwise>
		<xsl:value-of  select="concat(substring($date,13,4),'-')" />
                <xsl:variable name="month">
                    <xsl:value-of  select="substring($date,9,3)"/>
                </xsl:variable>
                <xsl:call-template name="mToNumber">
                    <xsl:with-param name="month" select="$month" />
                </xsl:call-template>
                <xsl:value-of select="concat('-',substring($date,6,2),'T')" />
                <xsl:value-of select="concat(substring($date,18,2),':',substring($date,21,2),':',substring($date,24,2),'Z')" />
            </xsl:otherwise>
      </xsl:choose>
     </xsl:template>
      <xsl:template name="mToNumber">
        <xsl:param name="month" />
       <xsl:choose>
          <xsl:when test="$month='Jan'">01</xsl:when>
          <xsl:when test="$month='Feb'">02</xsl:when>
          <xsl:when test="$month='Mar'">03</xsl:when>
          <xsl:when test="$month='Apr'">04</xsl:when>
          <xsl:when test="$month='May'">05</xsl:when>
          <xsl:when test="$month='Jun'">06</xsl:when>
          <xsl:when test="$month='Jul'">07</xsl:when>
          <xsl:when test="$month='Aug'">08</xsl:when>
          <xsl:when test="$month='Sep'">09</xsl:when>
          <xsl:when test="$month='Oct'">10</xsl:when>
          <xsl:when test="$month='Nov'">11</xsl:when>
          <xsl:when test="$month='Dec'">12</xsl:when>
       </xsl:choose>
     </xsl:template>
     <xsl:template name="reltime">
       <xsl:param name="time" />
       <xsl:variable name="diff" select="date:seconds(date:difference($time,date:date-time()))" />
       <xsl:variable name="seconds"><xsl:call-template name="absolute"><xsl:with-param name="diff" select="$diff" /></xsl:call-template></xsl:variable>
       <xsl:choose>
       <xsl:when test="$seconds &lt;= (60*60)">
           <xsl:variable name="minutes" select="floor($seconds div 60)"/>
           <xsl:if test="$minutes &lt;= 1">
              <xsl:value-of select="$minutes"/> minute ago
           </xsl:if>
           <xsl:if test="$minutes &gt; 1">
               <xsl:value-of select="$minutes"/> minutes ago
           </xsl:if>
       </xsl:when>
       <xsl:when test="$seconds &lt;= (60 * 60 * 24)">
           <xsl:variable name="hours" select="floor($seconds div 3600)"/>
           <xsl:if test="$hours &lt;= 1">
               <xsl:value-of select="$hours"/> hour ago
           </xsl:if>
           <xsl:if test="$hours &gt; 1">
               <xsl:value-of select="$hours"/> hours ago
           </xsl:if>
       </xsl:when>
       <xsl:when test="$seconds &lt;= (60 * 60 * 24 * 7)">
           <xsl:variable name="days" select="floor($seconds div 86400)"/>
           <xsl:if test="$days &lt;= 1">
               <xsl:value-of select="$days"/> day ago
           </xsl:if>
           <xsl:if test="$days &gt; 1">
               <xsl:value-of select="$days"/> days ago
           </xsl:if>
       </xsl:when>
       <xsl:when test="$seconds &lt;= (60 * 60 * 24 * 30)">
           <xsl:variable name="weeks" select="floor($seconds div 604800)"/>
           <xsl:if test="$weeks &lt;= 1">
               <xsl:value-of select="$weeks"/> week ago
           </xsl:if>
           <xsl:if test="$weeks &gt; 1">
               <xsl:value-of select="$weeks"/> weeks ago
           </xsl:if>
       </xsl:when>
       <xsl:when test="$seconds &lt;= (60 * 60 * 24 * 365)">
           <xsl:variable name="months" select="floor($seconds div 2592000)"/>
           <xsl:if test="$months &lt;= 1">
               <xsl:value-of select="$months"/> month ago
           </xsl:if>
           <xsl:if test="$months &gt; 1">
               <xsl:value-of select="$months"/> months ago
           </xsl:if>
       </xsl:when>
       <xsl:otherwise>
          1 year ago
       </xsl:otherwise>
    </xsl:choose>
    </xsl:template>
     <xsl:template name="absolute">
       <xsl:param name="diff"/>
        <xsl:choose>
           <xsl:when test="$diff &lt; 0">
               <xsl:value-of select="$diff * -1"/>
           </xsl:when>
           <xsl:otherwise>
               <xsl:value-of select="$diff"/>
           </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template match="channel">
	<xsl:variable name="cName">
          <xsl:choose>
            <xsl:when test="image">border-bottom:2px solid black;</xsl:when>
            <xsl:otherwise></xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
        <table  style="width:98%;margin:5px 5px 0px 5px;{$cName}">
        <tbody>
        <tr>
	<xsl:choose>
            <xsl:when test="image">
        	<td style="padding:3px;">
	        <a href="{ image/link }"><img src="{ image/url }" title="{ image/title }" /></a>
	        </td>
	    </xsl:when>
	    <xsl:otherwise></xsl:otherwise>
        </xsl:choose>
	<xsl:choose>
	    <xsl:when test="lastBuildDate">
	        <td style="vertical-align:top;text-align:right;padding:3px;font-size:70%;font-family:Verdana;"><xsl:if test="lastBuildDate"><q class="alt-text-color"><xsl:value-of select="concat(substring(lastBuildDate,9,3),' ',substring(lastBuildDate,6,3),',',substring(lastBuildDate,13,4))"/></q></xsl:if></td>
	    </xsl:when>
            <xsl:otherwise></xsl:otherwise>
       	</xsl:choose>
        </tr>
        </tbody>
        </table>
        <ul style="padding:0.8em 0">
        <xsl:apply-templates select="item"/>
        </ul>
    </xsl:template>
    <xsl:template match="/">
        <html>
        <body>
        <xsl:apply-templates/>
        </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

