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

<xsl:template match="/">
	<html>
		<head>
			<title>Cool BBS</title>
		</head>
		<body>
			<h1>Here is some cool BBS type stuff:</h1>
			<xsl:apply-templates select="threads"/>
		</body>
	</html>
</xsl:template>

<xsl:template match="threads">
	<ul>
	<xsl:for-each select="thread[@parent = '']">
		<li>This is a top level</li>
		<xsl:call-template name="thread">
			<xsl:with-param name="parentid"><xsl:value-of select="@id"/></xsl:with-param>
		</xsl:call-template>
	</xsl:for-each>
	</ul>
</xsl:template>

<xsl:template name="thread">
	<xsl:param name="parentid"/>
	<ul>
	<xsl:for-each select="/threads/thread[@parent=$parentid]">
		<li><xsl:value-of select="title"/></li>
		<xsl:call-template name="thread">
			<xsl:with-param name="parentid"><xsl:value-of select="@id"/></xsl:with-param>
		</xsl:call-template>
	</xsl:for-each>
	</ul>
</xsl:template>

</xsl:stylesheet>