节点计数问题 [英] Node Counting Problems

查看:83
本文介绍了节点计数问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了相当多的时间(比我想要的方式更多)今天看了

来回答我认为简单的问题。我只需要
需要获得一些节点内的项目数到目前的节点

(之前或之前的兄弟相关)。例如,以下是我必须使用的一些

样本XML:


< ITEM>

< CHILD>

< ITEM>

< CHILD />

< CHILD />

< / ITEM>

< ITEM>

< CHILD />

< CHILD />

< CHILD />

< / ITEM>

< ITEM>

< CHILD /> << - 当前节点

< / ITEM>

< ITEM>

< CHILD />

< / ITEM>

< / CHILD>

< / ITEM>


让'比如说当前节点如上所述。如何获得先前CHILD节点的数量
?在这种情况下,我正在寻找的数字是5.

任何帮助将不胜感激!

解决方案



count(previous-sibling :: CHILD)+ count(../ preceding-sibling :: ITEM / CHILD)


David


count(前面:: CHILD)


嘿,


非常感谢快速回复。出于某种原因

" count(../ preceding-sibling :: ITEM / CHILD)"每次模板执行时,返回0并且我的计数开始

。此外,这个例子只有当前节点是第三个节点才会工作

,或者它会随时在

集合中工作吗?


I''ve spent quite a bit of time (way more than I''d like) today looking
for an answer to what I thought would be a simple question. I simply
need to get the count of items within some nodes up to the current node
(previous or previous-sibling related). For example, here is some
sample XML I have to work with:

<ITEM>
<CHILD>
<ITEM>
<CHILD />
<CHILD />
</ITEM>
<ITEM>
<CHILD />
<CHILD />
<CHILD />
</ITEM>
<ITEM>
<CHILD /> <<-- current node
</ITEM>
<ITEM>
<CHILD />
</ITEM>
</CHILD>
</ITEM>

Let''s say the current node is as noted above. How do I get the count of
the previous CHILD nodes? In this case the number I''m looking for is 5.
Any help would be greatly appreciated!

解决方案


count(preceding-sibling::CHILD) + count(../preceding-sibling::ITEM/CHILD)

David


count(preceding::CHILD)


Hey,

Serious thanks for the fast reply. For some reason
"count(../preceding-sibling::ITEM/CHILD)" returns 0 and my count starts
over every time the template executes. Also, will this example work
only if the current node was the 3rd node or will it work at anytime in
the set?


这篇关于节点计数问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆