XSLT is a language for transforming XML documents into other XML documents. RSS documents (feed, web feed, or channel) and XHTML documents (web pages) are just XML documents, so we can use XSLT to transform an RSS document into a styled XHTML web page, and display it in a browser.
There are two approaches to applying XSLT to your XML content. You can perform these XSLT transformations server‑side on your web server, and serve up the resulting XHTML web page to a browser. The other is to use XSLT is to send a source XML document and an XSLT stylesheet to a browser, and ask the browser to apply the XSLT transformation for you.
Given the inconsistencies between [X]HTML support in the different browsers, it should come as no surprise that they offer varying support for XSLT as well. In this article I"ll describe how to use PHP to perform a server‑side transformation of your RSS document into XHTML.
Note: The content:encoded element can be used in conjunction with the description element to provide an item's full content along with a shorter summary. While either the description or the content:encoded elements may contain the full content of an item, the description element is more widely supported than the content:encoded element in the context of an RSS 2.0 feed.
The XHTML Page
The XSL Stylesheets
The feed's content:encoded element must be suitable for presentation as [X]HTML, so no markup is applied in the stylesheet.
Generate an [X]HTML list—including hyperlinks—to display the feed's title elements.
Generate an [X]HTML list—including hyperlinks and item count—to display the feed's category elements.
Grouping and Sorting: the Muench Method
For this stylesheet, we'll look at using <xsl:key> to group items in an XML document. Commonly referred to as the Muench method—after Steve Muench—this approach has three steps:
Define a key for the property we want to use for grouping.
Select all of the category nodes, sorted alphabetically.
Do some magic with the generate‑id() and key() functions to find unique values. Output is generated only if we are processing the first node returned by the key that matches the value of the current node.