xsl递归问题

思源6DZ CSDN会员 思源6DZ 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
现有这样一个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 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>
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
思源6DZ CSDN会员
XML/XSL 8,906 成员 22,677 内容