Using XSLT

The transformation of RSS into another form of XML, using XSLT, isn’t very common at the moment, but it may soon have its time in the sun. This is because RSS—especially RSS 1.0, with its complicated relationships and masses of metadata—can be reproduced in many useful ways.

While the examples in this book are text-based and mostly XHTML, there is no reason you can’t render RSS into an SVG graphic, a PDF (via the Apache FOP tool), an MMS-SMIL message for new-generation mobile phones, or any of the hundreds of other XML-based systems. XSLT and the arcane art of writing XSLT stylesheets to take care of all of this is a subject too large for this book to cover in detail—for that, check out O’Reilly’s XSLT.

Nevertheless, I will show you some nifty stuff. Example 8-8 is an XSLT stylesheet that transforms an RSS 1.0 feed into the XHTML produced in Example 8-7.

Example 8-8. Transforming RSS 1.0 into XHTML fragments
<?xml version="1.0"?> <xsl:stylesheet version = '1.0' 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/" exclude-result-prefixes="rss rdf" > <xsl:output method="html"/> <xsl:template match="/"> <div class="channellink"> <a href="{rdf:RDF/rss:channel/rss:link}"> <xsl:value-of select="rdf:RDF/rss:channel/rss:title"/> </a> </div> <div class="linkentries"> <ul> <xsl:apply-templates select="rdf:RDF/*"/> </ul> </div> </xsl:template> <xsl:template match="rss:channel|rss:item"> <li> <a ...

Get Developing Feeds with RSS and Atom now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.