﻿<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
	xmlns:msxsl="urn:schemas-microsoft-com:xslt">

  <xsl:template match="/">
    <xsl:for-each select="./root">
      <xsl:apply-templates select="."/>
    </xsl:for-each>
  </xsl:template>

  <xsl:template match="item">
    <xsl:variable name="vpos" select = "position()"/>
    <xsl:variable name="vancest" select = "count(ancestor::*)"/>
    <xsl:variable name="chkbx" select="./@chkbx"/>

    <xsl:variable name="vsiblings">
      <xsl:value-of select = "count(../*)"/>
    </xsl:variable>

    <xsl:variable name="vstyle2">
      <xsl:choose>
        <xsl:when test="count(ancestor::*)=1">
          display:block
        </xsl:when>
        <xsl:otherwise>
          display:none
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="defColFolderIcon">../images/icons/Set1/ClosedFolder.gif</xsl:variable>
    <xsl:variable name="defExpFolderIcon">../images/icons/Set1/OpenFolder.gif</xsl:variable>
    <xsl:variable name="plus_icon">../images/common/exp.gif</xsl:variable>
    <xsl:variable name="minus_icon">../images/common/col.gif</xsl:variable>
    <xsl:variable name="icon_dir">../images/common/</xsl:variable>
    <xsl:variable name="defItemIcon">../images/common/nochild.gif</xsl:variable>
    <div style="overflow:hidden; width:100%">
      <table border="0" id="tbl_left_treeview" class="clsTreeHide" width="100%" style="{$vstyle2}" pos="{$vpos}" ancest="{$vancest}" cellspacing="0" cellpadding="0">
        <thead>
          <!-- CONNECTORS -->
          <xsl:if test="count(ancestor::*)>1">
            <th >
            <xsl:attribute name="style">
              <xsl:if test="@hide='1'">display:none;</xsl:if>
            </xsl:attribute>  

              <!-- fork connector -->
              <span valign="top" >
                <table width="15px" cellspacing="0" cellpadding="0"  height="100%" >
                  <tr>
                    <td width="50%">
                    </td>
                    <td height="50%"  width="50%">
                      <!-- upper part: for all elements -->
                      <table style="HEIGHT: 100%;BORDER-LEFT:gray solid 1px; BORDER-BOTTOM:gray solid 1px"  >
                        <tr>
                          <td>
                          </td>
                        </tr>
                      </table>
                    </td>
                  </tr>
                  <tr>
                    <td width="50%">
                    </td>
                    <td height="50%" width="50%">
                      <!-- lower part: not for the last element -->
                      <xsl:choose>
                        <xsl:when test="$vsiblings!=$vpos">
                          <table style="HEIGHT: 100%;BORDER-LEFT:gray solid 1px ;"  >
                            <tr>
                              <td>
                              </td>
                            </tr>
                          </table>
                        </xsl:when>
                        <xsl:otherwise>
                          <table>
                            <tr>
                              <td>
                              </td>
                            </tr>
                          </table>
                        </xsl:otherwise>
                      </xsl:choose>
                    </td>
                  </tr>
                </table>
              </span>
            </th>
          </xsl:if>

          <th align="left">
            <xsl:attribute name="style">
              HEIGHT:100%;WIDTH:100%;white-space:nowrap;
              <xsl:if test="@hide='1'">display:none;</xsl:if>
            </xsl:attribute>  
            <!-- NODE -->
            <xsl:choose>
              <xsl:when test="(count(item) &gt; 0) or (@folder='Y')">
                <span title="Expand folder" expand="0" folder="true" style="cursor:pointer; width:16; height:16; display:inline-block;" onclick="onNode(this)">
                  <img id="sign">
                    <xsl:attribute name="icon_dir">
                      <xsl:copy-of select="$icon_dir" />
                    </xsl:attribute>
                    <xsl:attribute name="src">
                      <xsl:copy-of select="$plus_icon" />
                    </xsl:attribute>
                  </img>
                  <img id="icon">
                    <xsl:choose>
                      <xsl:when test="@col_icon and @col_icon != ''">
                        <xsl:attribute name="src">
                          <xsl:value-of select="@col_icon" />
                        </xsl:attribute>
                        <xsl:attribute name="col_icon">
                          <xsl:value-of select="@col_icon" />
                        </xsl:attribute>
                      </xsl:when>
                      <xsl:otherwise>
                        <xsl:attribute name="src">
                          <xsl:copy-of select="$defColFolderIcon" />
                        </xsl:attribute>
                        <xsl:attribute name="col_icon">
                          <xsl:copy-of select="$defColFolderIcon" />
                        </xsl:attribute>
                      </xsl:otherwise>
                    </xsl:choose>
                    <xsl:attribute name="exp_icon">
                      <xsl:choose>
                        <xsl:when test="@exp_icon and @exp_icon != ''">
                          <xsl:value-of select="@exp_icon" />
                        </xsl:when>
                        <xsl:otherwise>
                          <xsl:copy-of select="$defExpFolderIcon" />
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:attribute>
                  </img>
                </span>
                <span style="WIDTH:2px;"></span>
                <!-- CHECK BOXES -->
                <xsl:choose>
                  <!-- ATTRIBUTE CHKBX -->
                  <xsl:when test="@chkbx = 'Y'">
                    <input type="checkbox" checked="true" id="chkFolder" onclick="ChkFolderClick2(this)" ></input>
                  </xsl:when>
                </xsl:choose>
                <span unselectable="off" id="spanLeftTreeNode" onkeydown="KeyDownPNP(this)" onkeyup="KeyUpPNP(this)" class="TableTextBold" ancest="{$vancest}" type="1">
                  <xsl:attribute name="uid">
                    <xsl:value-of select="@id" />
                  </xsl:attribute>
                  <xsl:attribute name="onclick">HighLightTreeNode(this);onNode(this);if(gElem)gElem.focused=false;<xsl:value-of select="@onclick"/>
                  </xsl:attribute>
                  <xsl:attribute name="typeId">
                    <xsl:value-of select="@typeId"/>
                  </xsl:attribute>
                  <xsl:attribute name="oncontextmenu"><xsl:value-of select="@onCM"/>; return false;</xsl:attribute>
                  <xsl:if test="@drag='1'">
                    <xsl:attribute name="onmousedown">TreeNodeSelect(this)</xsl:attribute>
                    <xsl:attribute name="ondragstart">HandleDragStart(this)</xsl:attribute>
                  </xsl:if>
                  <xsl:attribute name="style">
                    font-size:11;cursor:pointer;height:'70%';valign: middle; cursor:pointer;
                    background-color: <xsl:value-of select="@bgColor"/>; color: <xsl:value-of select="@color" />;
                    <xsl:choose>
                      <xsl:when test="@hide='1'">display:none;</xsl:when>
                      <xsl:when test="@hide='2'">text-decoration:line-through;</xsl:when>
                      <xsl:otherwise></xsl:otherwise>
                    </xsl:choose>
                  </xsl:attribute>
                  <xsl:attribute name="title">
                    <xsl:value-of select = "@text"/>
                  </xsl:attribute>
                  <xsl:attribute name="page">
                    <xsl:value-of select = "@page"/>
                  </xsl:attribute>
                  <xsl:value-of select = "@text"/>
                </span>
              </xsl:when>

              <xsl:otherwise>
                <!-- LEAF -->
                <!-- LEAF: DIFFERENT IMAGES -->
                <span>
                  <img>
                    <xsl:attribute name="src">
                      <xsl:choose>
                        <xsl:when test="@icon and @icon !=''">
                          <xsl:value-of select="@icon" />
                        </xsl:when>
                        <xsl:otherwise>
                          <xsl:copy-of select="$defItemIcon" />
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:attribute>
                  </img>
                  <!-- CHECK BOXES -->
                  <xsl:choose>
                    <!-- ATTRIBUTE CHKBX -->
                    <xsl:when test="@chkbx = 'Y'">
                      <input type="checkbox" id="chkSelect" onclick="ChkClick(this)" checked="true">
                        <xsl:attribute name="uid">
                          <xsl:value-of select="@id" />
                        </xsl:attribute>
                        <xsl:attribute name="level">
                          <xsl:value-of select="position()"/>
                        </xsl:attribute>
                      </input>
                    </xsl:when>
                  </xsl:choose>
                </span>
                <span id="spanLeftTreeNode" onkeydown="KeyDownPNP(this)" onkeyup="KeyUpPNP(this)" class="TableText" ancest="{$vancest}" type="2">
                  <xsl:attribute name="uid">
                    <xsl:value-of select="@id" />
                  </xsl:attribute>
                  <xsl:attribute name="onclick">HighLightTreeNode(this);onLeaf(this);if(gElem)gElem.focused=false;<xsl:value-of select="@onclick"/></xsl:attribute>
                  <xsl:attribute name="typeId">
                    <xsl:value-of select="@typeId"/>
                  </xsl:attribute>
                  <xsl:attribute name="oncontextmenu"><xsl:value-of select="@onCM"/>; return false;</xsl:attribute>
                  <xsl:if test="@drag='1'">
                    <xsl:attribute name="onmousedown">TreeNodeSelect(this)</xsl:attribute>
                    <xsl:attribute name="ondragstart">HandleDragStart(this)</xsl:attribute>
                  </xsl:if>
                  <xsl:attribute name="page">
                    <xsl:value-of select = "@page"/>
                  </xsl:attribute>
                  <xsl:attribute name="target">
                    <xsl:value-of select="@target"/>
                  </xsl:attribute>
                  <xsl:attribute name="style">
                    cursor:pointer;color:blue;font-size:10px;height:90%; position: relative; top:0;
                    background-color: <xsl:value-of select = "@bgColor"/>;color: <xsl:value-of select="@color" />;
                    <xsl:choose>
                      <xsl:when test="@hide='1'">display:none;</xsl:when>
                      <xsl:when test="@hide='2'">text-decoration:line-through;</xsl:when>
                      <xsl:otherwise></xsl:otherwise>
                    </xsl:choose>
                  </xsl:attribute>
                  <xsl:attribute name="title">
                    <xsl:value-of select = "@text"/>
                  </xsl:attribute>&#160;<xsl:value-of select = "@text"/>
                </span>
              </xsl:otherwise>
            </xsl:choose>
          </th>
        </thead>

        <thead>
          <xsl:if test="count(ancestor::*)>1">
            <th width="15px" height="100%" >
              <!-- vertical connector:  
							1. not for the last element 
							2. invisible until right part is open
							3. change the height up to the height of the right side
						-->
              <table style="display: block" height="100%"  cellspacing="0" cellpadding="0">
                <tr>
                  <td width="50%">
                  </td>
                  <td height="100%" width="50%">
                    <xsl:choose>
                      <xsl:when test="$vsiblings!=$vpos">
                        <table height="100%" style="BORDER-LEFT:gray solid 1px; "  >
                          <tr>
                            <td>
                            </td>
                          </tr>
                        </table>
                      </xsl:when>
                      <xsl:otherwise>
                        <table height="100%">
                          <tr>
                            <td>
                            </td>
                          </tr>
                        </table>
                      </xsl:otherwise>
                    </xsl:choose>
                  </td>
                </tr>
              </table>
            </th>
          </xsl:if>
          <th align="left">
            <xsl:apply-templates select="item"/>
          </th>
        </thead>
      </table>
    </div>
  </xsl:template>
</xsl:stylesheet>
