从列表中算起 [英] count from the list
问题描述
// div [contains(@class,'cat 53453463')] / a
并且页面包含许多具有不同Xes的元素
// div [contains(@class,'cat xxxxxx')] / a
xpath是否有任何功能来计算它在列表中有多远?例如,如果在下面的列表中,我的比赛是第7排。 xpath是否有任何东西可以获取,或者我应该手动编写代码?
// div [contains(@class,' (@class,'cat xxxxxx')] / a
// div [contains(@class,'cat xxxxxx')] / $
// div [contains(@class,'cat xxxxxx')] / a
// div [contains(@class,'cat xxxxxx')] / a
// div [contains (@class,'cat xxxxxx')] / a
// div [contains(@class,'cat 53453463')] / a
// div [contains(@class,'cat xxxxxx' )] / a
这是一个真实世界的例子
转到此页
http://newyork.backpage.com/homes-for-sale/
然后我们运行下面的xpath
// div [contains(@class,'cat 93893742')] / a
在发布时,比赛是第7个上市。有没有办法让xpath返回7,因为它是第7个列表?
在XPath 2.0中,您可以获得节点$ N在节点列表$ L中使用表达式
for $ i in 1 to count($ L)return $我[$ L [$ i]是$ N]
我认为这不可行在XPath 1.0中(但之前我错了...)
Say I have a xpath like below
//div[contains(@class, 'cat 53453463')]/a
and the page contains many of these with different Xes
//div[contains(@class, 'cat xxxxxx')]/a
Does xpath have any feature to count how far down the list it is? for example if in the list below my match is the 7th row. Does xpath have anything for getting that or is this something I should code manually?
//div[contains(@class, 'cat xxxxxx')]/a
//div[contains(@class, 'cat xxxxxx')]/a
//div[contains(@class, 'cat xxxxxx')]/a
//div[contains(@class, 'cat xxxxxx')]/a
//div[contains(@class, 'cat xxxxxx')]/a
//div[contains(@class, 'cat xxxxxx')]/a
//div[contains(@class, 'cat 53453463')]/a
//div[contains(@class, 'cat xxxxxx')]/a
Here is a real world example
Take this page
http://newyork.backpage.com/homes-for-sale/
and we run the following xpath on it
//div[contains(@class, 'cat 93893742')]/a
At the time of posting this, the match is the 7th listing. Is there anyway to get the xpath return 7 since it's the 7th listing?
In XPath 2.0 you can get the position of a node $N within a node-list $L using the expression
for $i in 1 to count($L) return $i[$L[$i] is $N]
I don't think it can be done in XPath 1.0 (but I've been wrong before...)
这篇关于从列表中算起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!