logo

MMBase tips

Displaying a RSS-feed in your page

tip #2 / Mon 2 Nov 2009 / André / 0 comments

The mmbase taglib has a formatter tag to be used with xsl to parse XML-files, like for example a RSS-feed.

This short example contains the www.mmbase.org feed. It imports, or rather 'cites', the url with the <mm:include /> tag. The imported content is formatted with the <mm:formatter /> and <mm:xslt /> tags.

<mm:formatter escape="none">
<mm:include page="http://www.mmbase.org/rss/" cite="true" />
<mm:xslt>
<xsl:template match="channel"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<ol>
<xsl:for-each select="item">
<li>
<a href="{link}"><xsl:value-of select="title" /></a>
</li>
</xsl:for-each>
</ol>
</xsl:template>
</mm:xslt>
</mm:formatter>

When you run a recent version of mmbase you'll find the output of this example at http://127.0.0.1:8080/mmbase/about/core/mmbase_news

Publication dates

It's a pity that RSS-feeds have a rather ugly way of displaying dates. You can select and print an item's publication date with:

<xsl:variable name="datum" select="pubDate" />

That prints for example 'Mon, 26 Oct 2009 12:00:00 +0100'.  Convertion of these dates to something more readable has to be done in Java code.

0 comments

RSS feed

Tweet this article

Most mentioned links:

MMBase documentation
MMBase API
MMBase SVN
Bugtracker
MMBase Taglib reference
The reference for all tags mm