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

<xslt:param name="id" select="/.."/>     

<xslt:output method="html"
 standalone="yes"
 encoding="utf-8"
 indent="yes"/>

<xslt:template match="/tree">
  <xslt:choose>
   <xslt:when test="string($id) = ''">
	<ul class="lwAjaxTree" id="lwAjaxTree_root">
          <xslt:apply-templates select="/tree/node/label"/>
	</ul>
   </xslt:when>
   <xslt:otherwise>
  	<ul class="lwAjaxTree" id="lwAjaxTree_subtree_{$id}">
	  <xslt:apply-templates select="//label[@id=$id]/parent::node/tree/node/label"/>
	</ul>
   </xslt:otherwise>
  </xslt:choose>
</xslt:template>

<xslt:template match="/labels">
  <ul class="lwAjaxTree">
    <xslt:attribute name="id">    
      <xslt:choose>
         <xslt:when test="string($id) = ''">lwAjaxTree_root</xslt:when>
         <xslt:otherwise>
            <xslt:text>lwAjaxTree_subtree_</xslt:text>
            <xslt:value-of select="$id"/>
         </xslt:otherwise>
      </xslt:choose>
    </xslt:attribute>
    <xslt:apply-templates select="label"/>
  </ul>
</xslt:template>

<xslt:template match="label">
  <li class="lwAjaxTree_li">
	<xslt:if test="@id">
	  <xslt:attribute name="id">
		<xslt:text>lwAjaxTree_node_</xslt:text>
		<xslt:value-of select="@id"/>
	  </xslt:attribute> 
	</xslt:if>
	<div class="lwAjaxTreeLabel">
	  <xslt:choose>
           <xslt:when test="@id">
		<a class="lwAjaxTree_control" href="javascript:void(lw_aufklappen('{@id}'))" id="lwAjaxTree_plus_{@id}">+</a>
                <a class="lwAjaxTree_control" href="javascript:void(lw_zuklappen('{@id}'))" id="lwAjaxTree_minus_{@id}" style="display: none;">-</a>
           </xslt:when>
	   <xslt:otherwise>
		<span class="lwAjaxTree_spacer">&#160;</span>
           </xslt:otherwise>
	  </xslt:choose>
	  <xslt:apply-templates/>
	</div>
  </li>
</xslt:template>

<xslt:template match="node()|@*">
  <xslt:copy>
	<xslt:apply-templates select="node()|@*"/>
  </xslt:copy>
</xslt:template>

</xslt:stylesheet>