<?xml version="1.0"?>
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xhtml="http://www.w3.org/1999/xhtml"
    xmlns="http://www.w3.org/1999/xhtml"
    exclude-result-prefixes="xhtml">
    
    <xsl:output indent="yes" method="xml" />

    <xsl:variable name="OPML_TO_XOXO" 
        select="'http://decafbad.com/2005/10/gopher-ng/xsltproc/xslAddr=http://decafbad.com/2005/10/gopher-ng/opml-to-xoxo.xsl&amp;docAddr='" />

    <xsl:template match="/opml">
        <html>
            <head>
                <title><xsl:value-of select="head/title" /></title>
            </head>
            <body>
                <ul>
                    <xsl:for-each select="body">
                        <xsl:apply-templates mode="outline" />
                    </xsl:for-each>
                </ul>
            </body>
        </html>
    </xsl:template>

    <xsl:template match="outline" mode="outline">
        <xsl:variable name="url" select="@url | @htmlUrl" />
        <xsl:variable name="xmlUrl" select="@xmlUrl" />
        <li>
            <xsl:choose>
                <xsl:when test="@type='link' and contains($url, '.opml')">
                    <!-- Auto-munge links to OPML files into XOXO-conversion calls -->
                    <a href="{concat($OPML_TO_XOXO,$url)}"><xsl:value-of select="@text" disable-output-escaping="yes" /></a>

                    <!-- Alternately, you could define these as subsections, but this could
                         potentially recurse to slurp down the whole outline web.  Could be bad. -->
                    <!-- <a href="{$url}" rel="subsection"><xsl:value-of select="@text" /></a> -->
                </xsl:when>
                <xsl:when test="@type='link'">
                    <a href="{$url}"><xsl:value-of select="@text" disable-output-escaping="yes" /></a>
                </xsl:when>
                <xsl:when test="@type='rss'">
                    <a href="{$url}"><xsl:value-of select="@text" disable-output-escaping="yes" /></a>
                    <xsl:text> </xsl:text>
                    <a href="{$xmlUrl}" class="feed" rel="alternate" type="application/rss+xml">RSS</a>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="@text" disable-output-escaping="yes" />
                </xsl:otherwise>
            </xsl:choose>
            <xsl:if test="./outline">
                <ul>
                    <xsl:apply-templates mode="outline" />
                </ul>
            </xsl:if>
        </li>
    </xsl:template>
    
</xsl:stylesheet>

