devdoc

Wednesday, October 19, 2005

RSS and XSLT

If you have a feed and want to display only a few elements and add an alternate backgournd color maybe this stylesheet can give you some ideas :)


<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


<xsl:template match="/">

<div id="bbcNews">
<h2 class="bbc">World News</h2>
<xsl:apply-templates/>
</div>
</xsl:template>



<xsl:template match="rss">
<xsl:apply-templates/>
</xsl:template>



<xsl:template match="item">
<xsl:variable name="numItem"><xsl:number count="item" level="multiple" format="1"></xsl:variable>
<xsl:if test="$numItem &lt; 10">
<xsl:if test="$numItem mod 2 = 0">
<p class="bbcNotShaded"><xsl:value-of select="title"> <a href="{link}"> ...more</a></p>
</xsl:if>
<xsl:if test="$numItem mod 2 = 1">
<p class="bbcShaded"><xsl:value-of select="title"> <a href="{link}"> ...more</a></p>
</xsl:if>
</xsl:if>

</xsl:template>




<xsl:template match="text()">


</xsl:stylesheet>

0 Comments:

Post a Comment

<< Home