C#发现之旅 - 高性能ASP.NET树状列表控件(下)
2010-09-30 21:03:02 来源:WEB开发网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="http://tech.ddvip.com/2009-09/SkyTreeViewControl_child.gif" />
</xsl:if>
<xsl:if test="position()=last()">
<img src="http://tech.ddvip.com/2009-09/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>
更多精彩
赞助商链接