xsl递归问题
时间:2010-09-10
来源:互联网
XML代码如下:
XML code
XSL代码如下:
XML code
按我的理解出来的结果应该是这样的:
(a)
----(b) Value: test1
(b)
----(a)
--------(a) Value: test2
但实际出来的结果却是这样:
(a)
----(b) Value: test1
----------Value: test1
(b)
----(a)
--------(a) Value: test2
--------------Value: test2
我觉得应该是 "<ul><xsl:apply-templates select="*"/></ul>" 这一句中的select="*"调用了match="z"模板了,但是select="*"不是只选择a或者b或者c节点下的所有第一级子节点吗,为什么会选到了z子节点去了呢?
有人能帮忙解析一下吗?
我暂时的解决办法是改写为 "<ul><xsl:apply-templates select="a|b|c"/></ul>"
XML code
<?xml version="1.0" ?> <?xml-stylesheet type="text/xsl" href="test.xsl"?> <root> <a> <b> <x> <y> <z> <item value="test1"/> </z> </y> </x> </b> </a> <b> <a> <a> <x> <y> <z> <item value="test2"/> </z> </y> </x> </a> </a> </b> </root>
XSL代码如下:
XML code
<?xml version="1.0" encoding="utf-8"?> <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr"> <head> <title>Test</title> </head> <body> <ul><xsl:apply-templates select="/root/*"/></ul> </body> </html> </xsl:template> <xsl:template match="a|b|c"> <li> <i>(<xsl:value-of select="name()"/>)</i> <xsl:choose> <xsl:when test="count(x/y/z)>0"> <xsl:apply-templates select="x/y/z"/> </xsl:when> </xsl:choose> <ul><xsl:apply-templates select="*"/></ul> </li> </xsl:template> <xsl:template match="z"> Value: <xsl:value-of select="item/@value"/> </xsl:template> </xsl:transform>
按我的理解出来的结果应该是这样的:
(a)
----(b) Value: test1
(b)
----(a)
--------(a) Value: test2
但实际出来的结果却是这样:
(a)
----(b) Value: test1
----------Value: test1
(b)
----(a)
--------(a) Value: test2
--------------Value: test2
我觉得应该是 "<ul><xsl:apply-templates select="*"/></ul>" 这一句中的select="*"调用了match="z"模板了,但是select="*"不是只选择a或者b或者c节点下的所有第一级子节点吗,为什么会选到了z子节点去了呢?
有人能帮忙解析一下吗?
我暂时的解决办法是改写为 "<ul><xsl:apply-templates select="a|b|c"/></ul>"
作者: nwleo 发布时间: 2010-09-10
XSLT有默认实现以下这段
<xsl:template match="×">
<xsl:apply-templates select="*"/>
</xsl:template>
<xsl:template match="×">
<xsl:apply-templates select="*"/>
</xsl:template>
作者: cds27 发布时间: 2010-09-15
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28