<?xml version="1.0"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
                xmlns:rss="http://purl.org/rss/1.0/"
                xmlns:simple09="http://my.netscape.com/rdf/simple/0.9/"
                exclude-result-prefixes="rdf rss simple09"
                version="1.0">
    
    <xsl:output indent="yes"
                method="html"
                omit-xml-declaration="yes"/>

    <!-- Limite de items -->
    <xsl:param name="limit" select="6"/>
    
    <!-- Fecha -->
    <xsl:param name="datetime"/>
                
    <!--
      - Templates comunes
      -->
    <xsl:template name="box_header">
        <xsl:param name="channel_title"/>
        <xsl:param name="channel_link"/>
        <h1>
            <a>
                <xsl:attribute name="href">
                    <xsl:value-of select="$channel_link"/>
                </xsl:attribute>
                <xsl:value-of select="$channel_title"/>
            </a>
        </h1>
        <h2>
            <h2>(<xsl:value-of select="$datetime"/>)</h2>
        </h2>
    </xsl:template>
    
    <xsl:template name="box_item">
        <xsl:param name="item_title"/>
        <xsl:param name="item_link"/>
        <li>
            <a>
                <xsl:attribute name="href">
                    <xsl:value-of select="$item_link"/>
                </xsl:attribute>
                <xsl:value-of select="$item_title"/>
            </a>
        </li>
    </xsl:template>
    
    <!--
      - Templates para RDF 0.9 and RSS 1.0
      -->
    <xsl:template match="/rdf:RDF">
        <div class="caja">
            <xsl:apply-templates select="rss:channel"/>
            <xsl:apply-templates select="simple09:channel"/>
            <ul>
                <xsl:for-each select="rss:item[position() &lt;= $limit]">
                    <xsl:call-template name="box_item">
                        <xsl:with-param name="item_title">
                            <xsl:value-of select="rss:title"/>
                        </xsl:with-param>
                        <xsl:with-param name="item_link">
                            <xsl:value-of select="rss:link"/>
                        </xsl:with-param>
                    </xsl:call-template>
                </xsl:for-each>
                <xsl:for-each select="simple09:item[position() &lt;= $limit]">
                    <xsl:call-template name="box_item">
                        <xsl:with-param name="item_title">
                            <xsl:value-of select="simple09:title"/>
                        </xsl:with-param>
                        <xsl:with-param name="item_link">
                            <xsl:value-of select="simple09:link"/>
                        </xsl:with-param>
                    </xsl:call-template>
                </xsl:for-each>
            </ul>
        </div>
    </xsl:template>
    
    <xsl:template match="rss:channel">
        <xsl:call-template name="box_header">
            <xsl:with-param name="channel_title">
                <xsl:value-of select="rss:title"/>
            </xsl:with-param>
            <xsl:with-param name="channel_link">
                <xsl:value-of select="rss:link"/>
            </xsl:with-param>
        </xsl:call-template>
    </xsl:template>
    
    <xsl:template match="simple09:channel">
        <xsl:call-template name="box_header">
            <xsl:with-param name="channel_title">
                <xsl:value-of select="simple09:title"/>
            </xsl:with-param>
            <xsl:with-param name="channel_link">
                <xsl:value-of select="simple09:link"/>
            </xsl:with-param>
        </xsl:call-template>
    </xsl:template>
    
    <!--
      - Templates para RSS 2.0
      -->
    <xsl:template match="/rss/channel">
        <div class="caja">
            <xsl:call-template name="box_header">
                <xsl:with-param name="channel_title">
                    <xsl:value-of select="title"/>
                </xsl:with-param>
                <xsl:with-param name="channel_link">
                    <xsl:value-of select="link"/>
                </xsl:with-param>
            </xsl:call-template>
            <ul>
                <xsl:for-each select="item[position() &lt;= $limit]">
                    <xsl:call-template name="box_item">
                        <xsl:with-param name="item_title">
                            <xsl:value-of select="title"/>
                        </xsl:with-param>
                        <xsl:with-param name="item_link">
                            <xsl:value-of select="link"/>
                        </xsl:with-param>
                    </xsl:call-template>
                </xsl:for-each>
            </ul>
        </div>
    </xsl:template>
     
</xsl:stylesheet>