O'Reilly logo

How to Build an RSS 2.0 Feed by Mark Woodman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Browser-Friendly Feeds

If you have a link to your RSS feed on a web page, feed-savvy people know how to cut and paste the link into their RSS reader. For the rest of your web site visitors who click on the link, however, it would be nice to protect them from seeing the raw XML of your feed, as shown in Figure 5.

A raw RSS feed in a web browser

Figure 6. A raw RSS feed in a web browser

Using XSLT

A technology called XML Stylesheet Transformations (XSLT) provides a mechanism which can transform the XML of your feed into nicely formatted HTML. This can be used to either inform your visitors that they're looking at a feed and give them more information, or could even be used to mimic the layout of your web sites's normal HTML pages.

XSLT is not a trivial thing to learn, however. The good news is that there are various free XSLT scripts you can download from the web, modifying them as needed. (A simple Google search for "RSS to HTML with XSL" will turn up quite a few variations.)

Here is an example XSLT that provides a very simple transformation of RSS 2.0 feeds:

<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html"/> <xsl:template match="/"> <xsl:apply-templates select="/rss/channel"/> </xsl:template> <xsl:template match="/rss/channel"> <div> <h1><xsl:value-of select="title"/></h1> <em><xsl:value-of select="description"/></em> <ul><xsl:apply-templates ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required