<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <html>
            <head>
                <link rel="stylesheet" href="http://www.supermemo.com/beta/xml/ss/tree.css" type="text/css" />
                <script src="http://www.supermemo.com/beta/xml/js/tree.js" type="text/javascript"></script>
            </head>
            <body>
                <xsl:apply-templates />
            </body>
        </html>
    </xsl:template>
    <xsl:template match="SuperMemoElement">
        <xsl:variable name="ID">
            <xsl:value-of select="ID" />
        </xsl:variable>
        <xsl:variable name="Type">
            <xsl:value-of select="Type" />
        </xsl:variable>
        <div id="{$ID}" onclick="window.event.cancelBubble = true; clickElement(this, '{$ID}', '{$Type}');">
            <xsl:attribute name="open">false</xsl:attribute>
            <xsl:attribute name="class">
                <xsl:choose>
                    <xsl:when test="count(ancestor-or-self::SuperMemoElement) > 1">
                        smTreeHide
                    </xsl:when>
                    <xsl:otherwise>
                        smTreeShow
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:attribute>
            <xsl:choose>
                <xsl:when test="Type = 'Topic'">
                    <xsl:choose>
                        <xsl:when test="SuperMemoTree">
                            <span><img alt="Expand" height="16" id="Pic{$ID}" src="http://www.supermemo.com/beta/xml/img/expand.gif" width="16" /></span>
                        </xsl:when>
                        <xsl:otherwise>
                            <span><img height="16" src="http://www.supermemo.com/beta/xml/img/nil.gif" width="16" /></span>
                        </xsl:otherwise>
                    </xsl:choose>
                    <span><img alt="Topic" height="16" src="http://www.supermemo.com/beta/xml/img/topic.gif" width="16" /></span>
                    <span class="smTopic"><xsl:value-of select="Content/Title" /></span>
                </xsl:when>
                <xsl:otherwise>
                    <span><img alt="Item" height="16" src="http://www.supermemo.com/beta/xml/img/item.gif" width="16" /></span>
                    <span class="smItem" onclick="viewItem('{$ID}')"><xsl:value-of select="Content/Title" /></span>
                </xsl:otherwise>
            </xsl:choose>
            <xsl:apply-templates select="SuperMemoTree/SuperMemoElement" />
        </div>
    </xsl:template>
</xsl:stylesheet>