<?xml version="1.0"?>
<!--
    vsbabu_at_vsbabu_dot_org: Silly XSL to make a static HTML from a Leo outline.

    I *really* like Leo as an outliner and would like to use it for
    things like making HTML documents, business requirements etc., rather
    than just for coding.

    This is a first step. Prints structured HTML. Later I'd like to
    extend this so that it prints valid DocBook format.

    Releasing this so that other XSL newbies like me can get a start.

    Thanks to: http://www.jserv.com/jk_orr/xml/leo.htm

    Comments are most welcome.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
                xmlns="http://www.w3.org/TR/REC-html40">
<xsl:output method="html" indent="yes" encoding="iso-8859-1" />
<xsl:strip-space elements="*"/>

<!-- Main Template -->
<xsl:template match="/">
  <html>
    <head>
        <title>LEO Document</title>
    </head>
    <body>
        <xsl:apply-templates select="/leo_file/vnodes/v/vh"> 
            <xsl:with-param name="pos">1</xsl:with-param>
        </xsl:apply-templates>
    </body>
 </html>
</xsl:template>

<xsl:template match="vh">
    <xsl:param name="pos" select="1"/>
    <!-- dynamically printing h$pos will be better. Can XSL do that? -->
    <xsl:choose>
        <xsl:when test="$pos=1">
            <h1><xsl:value-of select="."/></h1>
        </xsl:when>
        <xsl:when test="$pos=2">
            <h2><xsl:value-of select="."/></h2>
        </xsl:when>
        <xsl:when test="$pos=3">
            <h3><xsl:value-of select="."/></h3>
        </xsl:when>
        <xsl:when test="$pos=4">
            <h4><xsl:value-of select="."/></h4>
        </xsl:when>
        <xsl:when test="$pos=5">
            <h5><xsl:value-of select="."/></h5>
        </xsl:when>
        <xsl:when test="$pos=6">
            <h6><xsl:value-of select="."/></h6>
        </xsl:when>
        <xsl:when test="$pos=7">
            <h7><xsl:value-of select="."/></h7>
        </xsl:when>
    </xsl:choose>
    <xsl:variable name="textID" select="../@t"/>
    <xsl:apply-templates select="//t[@tx=$textID]"/>
    <xsl:apply-templates select="../v/vh"> 
        <xsl:with-param name="pos" select="$pos+1"/>
    </xsl:apply-templates>
</xsl:template>

<xsl:template match="t">
    <p class='leoText'>
        <!-- replace LF with '~' and replace spaces with #A0 (which will be output as &nbsp;, bc this is html output)-->
        <xsl:value-of select="translate(., '&#10;&#32;', '~&#xA0;')"/>
    </p>
</xsl:template>
</xsl:stylesheet>
