XSL for Formatting OPML

I just wrote a simple XSL file that formats OPML files which contain lists of feeds/websites, like the ones you get when exporting feed listings from a feed reader. In particular, I wanted to be able to convert the OPML files created by FeedDemon to XHTML, and put them on this site.

Here it is, in case you want to have it:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns="http://www.w3.org/1999/xhtml">
 <xsl:output method="xml" encoding="UTF-8"
  omit-xml-declaration="yes" indent="yes"
  doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
  doctype-system=
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" />

 <xsl:template match="/opml">
  <html>
   <head>
    <title>
     <xsl:apply-templates select="head/title" /> (OPML)
    </title>
    <meta http-equiv="Content-Type"
     content="text/html; charset=UTF-8" />
   </head>
   <body>
    <h1><xsl:apply-templates select="head/title" /></h1>
    <ul class="opml">
     <xsl:apply-templates select="body/outline" />
    </ul>
   </body>
  </html>
 </xsl:template>

 <xsl:template match="outline">
  <li>
   <a href="{@htmlUrl}"><xsl:value-of select="@text" /></a>
  </li>
 </xsl:template>

</xsl:stylesheet>

It’s not much, but it’s a start, and it does what I want it to. Feel free to use and modify it.

Leave a Reply

Entries (RSS)