← Back to Archives

A Simple Transform for NetNewsWire OPML

blogging

I've got the blogroll back (see the right panel).

Most of the solutions out there -- like these -- for transforming from OPML to HTML assume that I have a "flat" OPML file or that I want a bunch of bells and whistles (my blogroll needs no javascript).

If you use a reader like NetNewsWire (or Bloglines or Google Reader...) that supports outputting OPML in Groups, these solutions aren't very satisfying. I like the fact that I have a number of "groups" or "containers" in which I read my feeds and I'd like to be able to preserve that when exporting to OPML and also when transforming the OPML to HTML for inclusion on this here blog's blogroll.

Anyway, to make a long story short, I had to write my own. The following XSLT will take an OPML file with groups (i.e., not a "flat" OPML file) and render it with heading tags for group labels and list elements for each feed.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" indent="yes" standalone="no" omit-xml-declaration="yes" /> <xsl:template match="/"> <xsl:apply-templates select="//body" /> </xsl:template> <xsl:template match="outline"> xsl:choose <xsl:when test="parent::outline">

  • <xsl:value-of select="@title" />
  • </xsl:when> xsl:otherwise

    <xsl:value-of select="@title" />

      <xsl:apply-templates select="outline" > <xsl:sort select="@text"/> </xsl:apply-templates>
    </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>

    It's actually just barely clever. It's slightly recursive in that it calls itself again if it is on an "outline" node that doesn't have "outline" as it's parent. This only works for single nested groupings.

    For b2evo, you can use this and plop the output into the "Free HTML" sidebar widget. Some CSS tweaks and you have something looking quite nice.