xsl 实现递归树的问题,急急急!!!!
时间:2004-07-10
来源:互联网
现有这样一个xml文件
<Tree>
<Leave id="10020001">
<Desc>银行存款</Desc>
<Values>16483103.69</Values>
<Parent>10020001</Parent>
</Leave>
<Leave id="10020002">
<Desc>活期存款</Desc>
<Values>16483103.69</Values>
<Parent>10020001</Parent>
</Leave>
<Leave id="10020003">
<Desc>人民银行存款</Desc>
<Values></Values>
<Parent>10020002</Parent>
</Leave>
<Leave id="10020004">
<Desc>中资银行</Desc>
<Values></Values>
<Parent>10020002</Parent>
</Leave>
这个xml的结构是这样的
每个Leave都有 id 属性 唯一表示该 节点
同时也有Parent 属性,该属性记载该节点父节点的 id 属性值
如果 Parent 的值 跟 id 属性的值相同则代表 该节点没有父节点
我要实现在xsl样式表中能够自动通过<Parent>标签 将一个<Leave>挂到另一个<Leave>标签(这个Leave 的 id 值等于前一个Leave的 Parent 值)下面,从而生成一棵树
我是这样写的,但总是实现不了,而且也有错,还请各位高手指教:
<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl" language="JavaScript">
<xsl:template match="Tree">
<!--首先显示所有根节点即 @id=parent-->
<xsl:for-each match=".[Leave/@id=Leave/Parent]">
<xsl:apply-templates select="Leave"/>
</xsl:for-each>
</xsl:template>
<xsl:template match="Leave">
<div onclick="window.event.cancelBubble = true;clickOnEntity(this);" onselectstart="return false" ondragstart="return false">
<xsl:attribute name="image">images/book.gif</xsl:attribute>
<xsl:attribute name="imageOpen">images/bookOpen.gif</xsl:attribute>
<xsl:attribute name="open">false</xsl:attribute>
<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
<xsl:attribute name="open">false</xsl:attribute>
<xsl:attribute name="STYLE">
padding-left: 20px;
cursor: hand;
<!--果不是根节点就隐藏-->
<xsl:if match=".[Parent!=@id]">
display: none;
</xsl:if>
</xsl:attribute>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="middle">
<img border="0" id="image">
<xsl:attribute name="SRC">images/bookOpen.gif</xsl:attribute>
</img>
</td>
<td valign="middle" nowrap="true">
<xsl:attribute name="STYLE">
padding-left: 7px;
font-family: Verdana;
font-size: 9pt;
font-color: black;
</xsl:attribute>
<xsl:value-of select="Desc"/><xsl:value-of select="Values"/></td>
</tr>
</table>
<!--查找当前 Leave 的子 Leave
即查找 Parent = 当前Leave的 @id 的 Leave-->
<xsl:for-each select="Leave">
<!--如果当前@id!=Parent 且当前 Parent=上一个@id-->
<xsl:if match=".[Parent!=@id and Parent=../@id]">
<xsl:apply-templates select="Leave"/>
</xsl:if>
</xsl:for-each>
</div>
</xsl:template>
</xsl:stylesheet>
[ 本帖由 sc_80817 于 2004-7-10 14:38 最后编辑 ]
<Tree>
<Leave id="10020001">
<Desc>银行存款</Desc>
<Values>16483103.69</Values>
<Parent>10020001</Parent>
</Leave>
<Leave id="10020002">
<Desc>活期存款</Desc>
<Values>16483103.69</Values>
<Parent>10020001</Parent>
</Leave>
<Leave id="10020003">
<Desc>人民银行存款</Desc>
<Values></Values>
<Parent>10020002</Parent>
</Leave>
<Leave id="10020004">
<Desc>中资银行</Desc>
<Values></Values>
<Parent>10020002</Parent>
</Leave>
这个xml的结构是这样的
每个Leave都有 id 属性 唯一表示该 节点
同时也有Parent 属性,该属性记载该节点父节点的 id 属性值
如果 Parent 的值 跟 id 属性的值相同则代表 该节点没有父节点
我要实现在xsl样式表中能够自动通过<Parent>标签 将一个<Leave>挂到另一个<Leave>标签(这个Leave 的 id 值等于前一个Leave的 Parent 值)下面,从而生成一棵树
我是这样写的,但总是实现不了,而且也有错,还请各位高手指教:
<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl" language="JavaScript">
<xsl:template match="Tree">
<!--首先显示所有根节点即 @id=parent-->
<xsl:for-each match=".[Leave/@id=Leave/Parent]">
<xsl:apply-templates select="Leave"/>
</xsl:for-each>
</xsl:template>
<xsl:template match="Leave">
<div onclick="window.event.cancelBubble = true;clickOnEntity(this);" onselectstart="return false" ondragstart="return false">
<xsl:attribute name="image">images/book.gif</xsl:attribute>
<xsl:attribute name="imageOpen">images/bookOpen.gif</xsl:attribute>
<xsl:attribute name="open">false</xsl:attribute>
<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
<xsl:attribute name="open">false</xsl:attribute>
<xsl:attribute name="STYLE">
padding-left: 20px;
cursor: hand;
<!--果不是根节点就隐藏-->
<xsl:if match=".[Parent!=@id]">
display: none;
</xsl:if>
</xsl:attribute>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="middle">
<img border="0" id="image">
<xsl:attribute name="SRC">images/bookOpen.gif</xsl:attribute>
</img>
</td>
<td valign="middle" nowrap="true">
<xsl:attribute name="STYLE">
padding-left: 7px;
font-family: Verdana;
font-size: 9pt;
font-color: black;
</xsl:attribute>
<xsl:value-of select="Desc"/><xsl:value-of select="Values"/></td>
</tr>
</table>
<!--查找当前 Leave 的子 Leave
即查找 Parent = 当前Leave的 @id 的 Leave-->
<xsl:for-each select="Leave">
<!--如果当前@id!=Parent 且当前 Parent=上一个@id-->
<xsl:if match=".[Parent!=@id and Parent=../@id]">
<xsl:apply-templates select="Leave"/>
</xsl:if>
</xsl:for-each>
</div>
</xsl:template>
</xsl:stylesheet>
[ 本帖由 sc_80817 于 2004-7-10 14:38 最后编辑 ]
作者: sc_80817 发布时间: 2004-07-10
我也想了解这个
作者: sendidmax 发布时间: 2005-09-20
<?xml version="1.0" encoding="gb2312"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/Tree"> <!--首先显示所有根节点即 @id=parent--> <body onclick="alert(this.innerHTML);"> <xsl:apply-templates select="Leave"/> </body> </xsl:template> <xsl:template match="Leave"> <div onclick="window.event.cancelBubble = true;clickOnEntity(this);" onselectstart="return false" ondragstart="return false"> <xsl:attribute name="image">images/book.gif</xsl:attribute> <xsl:attribute name="imageOpen">images/bookOpen.gif</xsl:attribute> <xsl:attribute name="open">false</xsl:attribute> <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute> <xsl:attribute name="open">false</xsl:attribute> <xsl:attribute name="STYLE"> padding-left: 20px; cursor: hand; <!--果不是根节点就隐藏--> <xsl:if test="Parent!=@id"> display: none; </xsl:if> </xsl:attribute> <table border="0" cellspacing="0" cellpadding="0"> <tr> <td valign="middle"> <img border="0" id="image"> <xsl:attribute name="SRC">images/bookOpen.gif</xsl:attribute> </img> </td> <td valign="middle" nowrap="true"> <xsl:attribute name="STYLE"> padding-left: 7px; font-family: Verdana; font-size: 9pt; font-color: black; </xsl:attribute> <xsl:value-of select="Desc"/><xsl:value-of select="Values"/></td> </tr> </table> <!--查找当前 Leave 的子 Leave 即查找 Parent = 当前Leave的 @id 的 Leave--> <xsl:apply-templates select="Leave"/> </div> </xsl:template> </xsl:stylesheet>
提示:您可以先修改部分代码再运行
作者: sendidmax 发布时间: 2005-09-20
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28