<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!--
	outline.xsl - recursively transform OPML document into HTML
	(c) 2000, Bill Humphries <bill@whump.com>	

	Modified by Phil Windley, Dec 2004.
-->

<xsl:output method="html" indent="yes"/>

<xsl:template match="outlineDocument|opml">
	<xsl:apply-templates select="body"/>
</xsl:template>

<xsl:template match="body">

	<xsl:for-each select="outline">
		<h1><xsl:value-of select="@text"/></h1>
		<xsl:apply-templates select="outline"/>
	</xsl:for-each>
	
</xsl:template>

<!--
	At any level in the outline, first test to see if there are any
	children. If there are, write out a header element using the
	current level, and call this template on the children. If
	not, display the node's text in blockquotes.
-->
<xsl:template match="outline">
	<ul>
	<xsl:param name="LEVEL" select="1"/>
	<xsl:choose>
		<xsl:when test="count(outline) &gt; 0">
		<xsl:element name="{concat('h',$LEVEL + 1)}">
			<xsl:call-template name="display"/>
		</xsl:element>
		</xsl:when>
		<xsl:otherwise>
	           <li>
	           <xsl:call-template name="display"/></li>
		</xsl:otherwise>
	</xsl:choose>
	<xsl:apply-templates select="outline">
		<xsl:with-param name="LEVEL" select="$LEVEL + 1"/>
	</xsl:apply-templates>
	</ul>
</xsl:template>

<!--
	Test to see if the node is a link, if so, render the 
	link. If not, render the plain text.
-->
<xsl:template name="display">
	<xsl:choose>
		<xsl:when test="@type='link'">
			<a href="{@url}"><xsl:value-of select="@text"/></a>
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="@text"/>
		</xsl:otherwise>	
	</xsl:choose>
</xsl:template>

</xsl:stylesheet>

