<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:simple="http://my.netscape.com/rdf/simple/0.9/" xmlns:rss="http://purl.org/rss/1.0/"
    xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/"
    xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:syn="http://purl.org/rss/1.0/modules/syndication/" xmlns:atom="http://purl.org/atom/ns#"
    xmlns:atom1="http://www.w3.org/2005/Atom" xmlns:foaf="http://xmlns.com/foaf/0.1/"
    xmlns:admin="http://webns.net/mvcb/" xmlns:icbm="http://postneo.com/icbm"
    xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
    xmlns:enc="http://purl.oclc.org/net/rss_2.0/enc#"
    xmlns:wfw="http://wellformedweb.org/CommentAPI/"
    exclude-result-prefixes="rdf simple rss dc dcterms content syn atom atom1 foaf admin icbm geo enc wfw">
    <xsl:output method="html"/>
    
    <xsl:param name="ListSize" select="5"/>
    
    <xsl:template match="/">
        <xsl:apply-templates select="/rdf:RDF[rss:channel or simple:channel]"/>
        <xsl:apply-templates select="/rss[@version]/channel"/>
        <xsl:apply-templates select="/redirect/newLocation"/>
        <xsl:apply-templates select="/atom:feed[@version='0.3']"/>
        <xsl:apply-templates select="/atom1:feed"/>
    </xsl:template>
    
    <xsl:template match="rss/channel">
        <xsl:call-template name="listTitle"/>
        <p class="displayNone">Source:<br/><a href="{link}">
            <xsl:value-of select="title" disable-output-escaping="yes"/>
        </a></p>
    </xsl:template>
    
    <xsl:template match="/atom:feed|/atom1:feed">
        <xsl:call-template name="listAtomTitle"/>
        <p class="displayNone">Source:<br/>
            <xsl:element name="a">
                <xsl:attribute name="href">
                    <xsl:apply-templates select="atom:link|atom1:link"/>
                </xsl:attribute>
                <xsl:apply-templates select="atom:title|atom1:title"/>
            </xsl:element>
        </p>
    </xsl:template>
    
    <xsl:template match="atom:link|atom1:link">
        <xsl:if test="@rel = 'alternate'">
            <xsl:value-of select="@href"/>
        </xsl:if>
    </xsl:template>
    
    <xsl:template match="atom:title|atom1:title">
        <xsl:value-of select="." disable-output-escaping="yes"/>
    </xsl:template>
    
    <xsl:template match="/rdf:RDF">
        <xsl:call-template name="listRdfTitle"/>
        <p class="displayNone">Source:<br/><a href="{rss:channel/rss:link}">
            <xsl:value-of select="rss:channel/rss:title"
                disable-output-escaping="yes"/>
        </a></p>
    </xsl:template>
    
    <!--#####################      FUNCTION 	#####################-->
    <xsl:template name="listTitle">
        <xsl:for-each select="item">
            <xsl:choose>
                <xsl:when test="$ListSize >= position()">
                    <p class="rssTitle">
                        <a href="{link}">
                            <xsl:value-of select="title" disable-output-escaping="yes"/>
                        </a>
                        <xsl:choose>
                            <xsl:when test="dc:date">
                                <!-- Show date if available -->
                                <span>
                                    <xsl:call-template name="listDcDate"/>
                                </span>
                            </xsl:when>
                            <xsl:when test="pubDate">
                                <!-- Show date if available -->
                                <span>
                                    <xsl:call-template name="listPubDate"/>
                                </span>
                            </xsl:when>
                            <xsl:otherwise/>
                        </xsl:choose>
                    </p>
                </xsl:when>
                <xsl:otherwise/>
            </xsl:choose>
        </xsl:for-each>
    </xsl:template>
    
    <!--#####################      FUNCTION 	#####################-->
    <xsl:template name="listAtomTitle">
        <xsl:for-each select="atom:entry|atom1:entry">
            <xsl:choose>
                <xsl:when test="$ListSize >= position()">
                    <p class="rssTitle">
                        <xsl:element name="a">
                            <xsl:attribute name="href">
                                <xsl:apply-templates select="atom:link|atom1:link"/>
                            </xsl:attribute>
                            <xsl:apply-templates select="atom:title|atom1:title"/>
                        </xsl:element>
                        <xsl:choose>
                            <xsl:when test="atom:modified">
                                <!-- Show date if available -->
                                <span>
                                    <xsl:call-template name="listAtomDate"/>
                                </span>
                            </xsl:when>
                            <xsl:otherwise/>
                        </xsl:choose>
                    </p>
                </xsl:when>
                <xsl:otherwise/>
            </xsl:choose>
        </xsl:for-each>
    </xsl:template>
    
    <!--#####################      FUNCTION 	#####################-->
    <xsl:template name="listRdfTitle">
        <xsl:for-each select="rss:item">
            <xsl:choose>
                <xsl:when test="$ListSize >= position()">
                    <p class="rssTitle">
                        <xsl:element name="a">
                            <xsl:attribute name="href">
                                <xsl:value-of select="rss:link"/>
                            </xsl:attribute>
                            <xsl:value-of select="rss:title" disable-output-escaping="yes"/>
                        </xsl:element>
                        <xsl:choose>
                            <xsl:when test="dc:date">
                                <!-- Show date if available -->
                                <span>
                                    <xsl:call-template name="listDcDate"/>
                                </span>
                            </xsl:when>
                            <xsl:otherwise/>
                        </xsl:choose>
                    </p>
                </xsl:when>
                <xsl:otherwise/>
            </xsl:choose>
        </xsl:for-each>
    </xsl:template>
    
    <!--#####################      FUNCTION 	#####################-->
    <!--## <pubDate>Fri, 29 Sep 2006 14:16:42 +0200</pubDate> #####-->
    <!--## <pubDate>19 Nov 2008 09:20:00 +0100</pubDate> #####-->
    <xsl:template name="listPubDate">
        <xsl:variable name="after1">
            <xsl:choose>
                <xsl:when test="contains(pubDate, ',')">
                    <xsl:value-of select="substring-after(pubDate, ', ')"/>
                </xsl:when>	 
                <xsl:otherwise>
                    <xsl:value-of select="pubDate"/>
                </xsl:otherwise>	 
            </xsl:choose>
        </xsl:variable>
        <xsl:variable name="day" select="substring-before($after1, ' ')"/>
        <xsl:variable name="after2" select="substring-after($after1, ' ')"/>
        <xsl:variable name="month1" select="substring-before($after2, ' ')"/>
        <xsl:variable name="after3" select="substring-after($after2, ' ')"/>
        <xsl:variable name="year" select="substring-before($after3, ' ')"/>
        <xsl:variable name="month">
            <xsl:choose>
                <xsl:when test="$month1= 'Jan'">01</xsl:when> 
                <xsl:when test="$month1= 'Feb'">02</xsl:when> 
                <xsl:when test="$month1= 'Mar'">03</xsl:when> 
                <xsl:when test="$month1= 'Apr'">04</xsl:when> 
                <xsl:when test="$month1= 'May'">05</xsl:when> 
                <xsl:when test="$month1= 'Jun'">06</xsl:when> 
                <xsl:when test="$month1= 'Jul'">07</xsl:when> 
                <xsl:when test="$month1= 'Aug'">08</xsl:when> 
                <xsl:when test="$month1= 'Sep'">09</xsl:when> 
                <xsl:when test="$month1= 'Oct'">10</xsl:when> 
                <xsl:when test="$month1= 'Nov'">11</xsl:when> 
                <xsl:when test="$month1= 'Dec'">12</xsl:when> 
                <xsl:otherwise><xsl:value-of select="$month1" /></xsl:otherwise>
            </xsl:choose>	 
        </xsl:variable>
        (<xsl:value-of select="$day" /><xsl:text>/</xsl:text><xsl:value-of select="$month" />&#160;<xsl:value-of select="$year" />)
    </xsl:template>
    
    <!--#####################      FUNCTION 	#####################-->
    <!--## <pubDate>Fri, 29 Sep 2006 14:16:42 +0200</pubDate> #####-->
    <xsl:template name="listDcDate">
        <xsl:variable name="year" select="substring-before(dc:date, '-')"/>
        <xsl:variable name="after1" select="substring-after(dc:date, '-')"/>
        <xsl:variable name="month" select="substring-before($after1, '-')"/>
        <xsl:variable name="after2" select="substring-after($after1, '-')"/>
        <xsl:variable name="day" select="substring($after2, 1, 2)"/> (<xsl:value-of select="$day"
        /><xsl:text>/</xsl:text><xsl:value-of select="$month"/>&#160;<xsl:value-of
            select="$year"/>) </xsl:template>
    
    <!--#####################      FUNCTION 	#####################-->
    <!--## <modified>2006-10-04T17:06:42Z</modified>          #####-->
    <xsl:template name="listAtomDate">
        <xsl:variable name="year" select="substring-before(atom:modified, '-')"/>
        <xsl:variable name="after1" select="substring-after(atom:modified, '-')"/>
        <xsl:variable name="month" select="substring-before($after1, '-')"/>
        <xsl:variable name="after2" select="substring-after($after1, '-')"/>
        <xsl:variable name="day" select="substring($after2, 1, 2)"/> (<xsl:value-of select="$day"
        /><xsl:text>/</xsl:text><xsl:value-of select="$month"/>&#160;<xsl:value-of
            select="$year"/>) </xsl:template>
</xsl:stylesheet>

