TreeNode 模板
TreeNode模板是XSLT模板文檔的主要部分,其代碼為
<!-- ******************* 輸出一個樹狀列表節點 *************************** -->
<xsl:template name="TreeNode">
<!-- 定義一個 Level 參數,表示節點層次,默認 0 -->
<xsl:param name="Level">0</xsl:param>
<!-- 定義一個NodeID變量,表示當前節點的編號 -->
<xsl:variable name="NodeID">
<xsl:choose>
<xsl:when test="string-length(ID) > 0">
<xsl:value-of select="ID" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="generate-id( . ) " />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- 定義一個showChildNodes變量,表示當前節點是否默認顯示子節點 -->
<xsl:variable name="ShowChildNode">
<xsl:if test="$Level < 1 ">1</xsl:if>
</xsl:variable>
<!-- 獲得所有子節點的個數 -->
<xsl:variable name="ChildCount">
<xsl:value-of select="count(Nodes/Node) " />
</xsl:variable>
<!-- 判斷是否存在子節點 -->
<xsl:variable name="HasChild">
<xsl:if test="$ChildCount > 0 or string-length( XMLSource ) > 0 ">1</xsl:if>
</xsl:variable>
<tr>
<td valign="top" align="left" width="16" height="16">
<!-- 顯示前面的樹狀結構線 -->
<xsl:choose>
<xsl:when test=" $HasChild = '1' ">
<xsl:if test="position()!=last()">
<xsl:attribute name="background">SkyTreeVIEwControl_line.gif</xsl:attribute>
</xsl:if>
<img>
<xsl:attribute name="id">
<xsl:value-of select="concat($NodeID,'_expend')" />
</xsl:attribute>
<xsl:choose>
<xsl:when test="$ShowChildNode != '1' and position() != last()">
<xsl:attribute name="src">SkyTreeVIEwControl_collapse.gif</xsl:attribute>
<xsl:attribute name="SrcBack">SkyTreeVIEwControl_expend.gif</xsl:attribute>
</xsl:when>
<xsl:when test="$ShowChildNode = '1' and position() != last()">
<xsl:attribute name="src">SkyTreeVIEwControl_expend.gif</xsl:attribute>
<xsl:attribute name="SrcBack">SkyTreeVIEwControl_collapse.gif</xsl:attribute>
</xsl:when>
<xsl:when test="$ShowChildNode != '1' and position() = last()">
<xsl:attribute name="src">SkyTreeVIEwControl_lastcollapse.gif</xsl:attribute>
<xsl:attribute name="SrcBack">SkyTreeVIEwControl_lastexpend.gif</xsl:attribute>
</xsl:when>
<xsl:when test="$ShowChildNode = '1' and position() = last()">
<xsl:attribute name="src">SkyTreeVIEwControl_lastexpend.gif</xsl:attribute>
<xsl:attribute name="SrcBack">SkyTreeVIEwControl_lastcollapse.gif</xsl:attribute>
</xsl:when>
</xsl:choose>
<xsl:attribute name="onclick">
<xsl:text>SkyTreeVIEwContrlExpendNodeByID('</xsl:text>
<xsl:value-of select="$NodeID" />
<xsl:text>' , false );</xsl:text>
</xsl:attribute>
</img>
</xsl:when>
<xsl:otherwise>
<xsl:if test="position()!=last()">
<img src="SkyTreeVIEwControl_child.gif" />
</xsl:if>
<xsl:if test="position()=last()">
<img src="SkyTreeVIEwControl_lastchild.gif" />
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</td>
<td valign="top" nowrap="1">
<!-- 用於生成節點圖標Html代碼 -->
<img align="absmiddle" width="16" height="16">
<xsl:attribute name="onclick">
<xsl:text>SkyTreeVIEwContrlExpendNodeByID('</xsl:text>
<xsl:value-of select="$NodeID" />
<xsl:text>' , true );</xsl:text>
</xsl:attribute>
<xsl:attribute name="id">
<xsl:value-of select="concat($NodeID,'_icon')" />
</xsl:attribute>
<xsl:choose>
<xsl:when test="string-length( Icon ) != 0">
<xsl:attribute name="SrcBack">
<xsl:value-of select="Icon" />
</xsl:attribute>
<xsl:attribute name="src">
<xsl:value-of select="Icon" />
</xsl:attribute>
</xsl:when>
<xsl:when test="$HasChild = '1' and $ShowChildNode = '1'">
<xsl:attribute name="SrcBack">SkyTreeVIEwControl_close.bmp</xsl:attribute>
<xsl:attribute name="src">SkyTreeVIEwControl_open.bmp</xsl:attribute>
</xsl:when>
<xsl:when test="$HasChild = '1' and $ShowChildNode != '1'">
<xsl:attribute name="SrcBack">SkyTreeVIEwControl_open.bmp</xsl:attribute>
<xsl:attribute name="src">SkyTreeVIEwControl_close.bmp</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="src">SkyTreeVIEwControl_default.bmp</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
</img>
<!-- 生成節點的文本 -->
<a class="SkyTreeVIEwControl_TreeNode" valign="top">
<xsl:attribute name="id">
<xsl:value-of select="concat( $NodeID, '_text')" />
</xsl:attribute>
<xsl:attribute name="onclick">
<xsl:text>SkyTreeVIEwContrlExpendNodeByID('</xsl:text>
<xsl:value-of select="$NodeID" />
<xsl:text>' , true );</xsl:text>
<xsl:if test="OnClick !=''">
<xsl:value-of select="OnClick" />
</xsl:if>
</xsl:attribute>
<xsl:if test="Link != ''">
<xsl:attribute name="href">
<xsl:value-of select="Link" />
</xsl:attribute>
</xsl:if>
<xsl:if test="string-length(XMLSource) > 0 ">
<xsl:attribute name="XMLSource">
<xsl:value-of disable-output-escaping="yes" select="XMLSource" />
</xsl:attribute>
</xsl:if>
<xsl:value-of select="concat( ' ' ,Text)" />
</a>
<xsl:if test="$ChildCount > 0 ">
<!-- 若有子節點則顯示子節點 -->
<table border="0" cellspacing="0" cellpadding="0">
<xsl:attribute name="id">
<xsl:value-of select="concat( $NodeID , '_table' ) " />
</xsl:attribute>
<xsl:if test="$ShowChildNode != '1'">
<xsl:attribute name="style">display:none</xsl:attribute>
</xsl:if>
<xsl:for-each select="Nodes/Node">
<!-- 遞歸調用TreeNode模板本身來生成下一級的節點的Html代碼 -->
<xsl:call-template name="TreeNode">
<xsl:with-param name="Level"> <!-- 傳遞節點層次參數 -->
<xsl:value-of select="$Level + 1" />
</xsl:with-param>
</xsl:call-template>
</xsl:for-each>
</table>
</xsl:if>
<xsl:if test="string-length(XMLSource) > 0 ">
<!-- 若節點的XMLSource存在則預先生成好“正在加載”字樣,但隱藏起來 -->
<span style='display:none' class='SkyTreeVIEwControl_TreeNode'>
<xsl:attribute name="id">
<xsl:value-of select="concat( $NodeID , '_Loading' ) " />
</xsl:attribute>
<br />
<xsl:text>正在加載</xsl:text>
</span>
</xsl:if>
</td>
</tr>
< /xsl:template>