如何取得当前节点的上一级节点的名字及其position值?

OnlyVB 2006-08-11 10:06:16
如题
...全文
302 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
cds27 2006-08-15
  • 打赏
  • 举报
回复
<xsl: when test="上一级节点的position值=last()">
等价于
<xsl: when test="count(../following-sibling::*[name()=$Name])=0">
OnlyVB 2006-08-14
  • 打赏
  • 举报
回复
如何取得当前节点的上一级节点的position值?
OnlyVB 2006-08-14
  • 打赏
  • 举报
回复
我要写成:
<xls: when test="上一级节点的position值=last()">的格式
OnlyVB 2006-08-14
  • 打赏
  • 举报
回复
怎么试呀,我就要一行代码
那行是呀
<xsl:variable name="Position" select="count(../preceding-sibling::*[name()=$Name])+1"/>
cds27 2006-08-14
  • 打赏
  • 举报
回复
上面的例子就是了,你没试吗
cds27 2006-08-13
  • 打赏
  • 举报
回复
XML例子:
<?xml version="1.0" encoding="gb2312"?>
<?xml-stylesheet type="text/xsl" href="xsl.xsl"?>
<root>
<item>a
<itemc/>
</item>
<item>b
<itemc/>
</item>
<item>c
<itemc/>
</item>
<item>d
<itemc/>
</item>
<item>e
<itemc/>
</item>
</root>

XSL.XSL :
<?xml version="1.0" encoding="gb2312"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY nbsp " ">
<!ENTITY copy "©">
<!ENTITY reg "®">
<!ENTITY trade "™">
<!ENTITY mdash "—">
<!ENTITY ldquo "“">
<!ENTITY rdquo "”">
<!ENTITY pound "£">
<!ENTITY yen "¥">
<!ENTITY euro "€">
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="gb2312"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="root">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="item">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="itemc">
<xsl:call-template name="getPosition"/>
<br />
</xsl:template>

<xsl:template name="getPosition">
<xsl:variable name="Name" select="name(..)"/>
<xsl:variable name="Position" select="count(../preceding-sibling::*[name()=$Name])+1"/>
<xsl:value-of select="$Position"/>
</xsl:template>
</xsl:stylesheet>

OnlyVB 2006-08-12
  • 打赏
  • 举报
回复
to cds27(http://blog.csdn.net/cds27/)
那如何取得当前节点的上一级节点的position值?
cds27 2006-08-12
  • 打赏
  • 举报
回复
./parent::*/position()怎么出错呀

--------------

因为position()是函数,而不是nodetest。当然会出错。
cds27 2006-08-12
  • 打赏
  • 举报
回复
你犯了几个错误。

1,你思路不对,不应该从当前节点倒推回去,而是应该从根节点往下传递层级变量。
毕竟XSL的解析顺序是从根开始。

2,name()返回的是字符串,root是节点,显然它们不会相等。如果相等也是偶然。参考语句:name(..)='root'

3,位置也应该是从父节点传递。

也许你可以参考这篇:http://blog.csdn.net/cds27/archive/2005/10/24/514457.aspx
OnlyVB 2006-08-11
  • 打赏
  • 举报
回复
<xsl:when test="name(parent::*)=root/TreeNode">
<xsl:value-of select="$BranchImgSrc" />
</xsl:when>
<xsl:when test="name(parent::*)=TreeNode">
<xsl:value-of select="$BranchImgSrc" />
</xsl:when>
<xsl:when test="name(parent::*)=root">
<xsl:value-of select="$BranchImgSrc" />
</xsl:when>

怎么都是true,明明有时等于root,有时等于TreeNode?
实际我的问题就是判断当前节点是第几级节点
OnlyVB 2006-08-11
  • 打赏
  • 举报
回复
./parent::*/position()怎么出错呀
tornado_cn 2006-08-11
  • 打赏
  • 举报
回复
name(parent::*)
./parent::*/position()
conghui 2006-08-11
  • 打赏
  • 举报
回复
节点的名字:当前节点.ParentNode.Name

8,906

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧