<?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>	
-->

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

<xsl:template match="outlineDocument|opml">
	<html>
		<head>
			<title><xsl:value-of select="head/title"/></title>
			<link rel="stylesheet" type="text/css" href="http://www.whump.com/stylesheets/whump.css"/>	
		</head>
		<body>
			<xsl:apply-templates select="body"/>
		</body>
	</html>
</xsl:template>

<xsl:template match="body">

	<h1>Outline</h1>
	<ol>
	<xsl:for-each select="outline">
		<li><xsl:value-of select="@text"/></li>
	</xsl:for-each>
	</ol>
	
	<hr />
	
	<xsl:for-each select="outline">
		<h1><xsl:value-of select="@text"/></h1>
		<xsl:apply-templates select="outline"/>
		<hr />
	</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">
	<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>
			<blockquote><xsl:call-template name="display"/></blockquote>
		</xsl:otherwise>
	</xsl:choose>
	<xsl:apply-templates select="outline">
		<xsl:with-param name="LEVEL" select="$LEVEL + 1"/>
	</xsl:apply-templates>
</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>