XPath:如何选择以下兄弟姐妹直到某个兄弟姐妹 [英] XPath: how to select following siblings until a certain sibling
问题描述
对于下面的示例HTML,返回具有class ='B'的class ='A'的a元素的同胞的XPath查询可以写为: 有关如何将当前XPath查询限制为仅适用于这些兄弟的任何想法都将非常感谢:) 要选择所有 选择 n 获取第二个 说: 给我所有 类似地,更一般地,我们可以应用Kayessian方法来找到两个交点节点集。在给出的例子中,我们需要1)在第二个 For the example HTML below, an XPath query that returns the siblings of the "a" elements with class='A' that have class='B' can be written as: However, I would only like the Example HTML: Any ideas on how to limit my current XPath query to just those siblings would be much appreciated :) To select all This selects everything between the nth To get the two elements between the second In English, this says: Give me all of the Similarly, and more generally, we can apply the Kayessian method for finding the intersection of two node sets. In the example given, we want the intersection of all the
这篇关于XPath:如何选择以下兄弟姐妹直到某个兄弟姐妹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! // a [ @类= 'A'] /以下同胞::一个[@类= 'B']
。这个查询输出4 < a class =B/>
元素。 然而,我只会喜欢< a class =B/>
元素。当前< a class =A/>
元素,并且没有其他人遵循其他< a class =B/>
元素/节点。换句话说,我只需要下面的< a class =B/>
兄弟元素,直到下一个< a class = B $ / b $ / b
$ p> < a class ='A'/>
< a class ='B'/>
< a class ='A'/>
< a class ='B'/>
< a class ='B'/>
< a class ='B'/>
a 在
等于 a
与类之间的
A
,接下来会出现这样的情况:
<$ c $ b $ class ='A'] [$ n] / following-sibling :: a [
@ class ='B'and count(preceding-sibling :: a [@ class = 'A'])= $ n]
a [@ class ='A']
和下一个这样的元素。对于一个具体的例子,请考虑以下输入:
< r>
< a class =A/>
< a class =B/>
< a class =A/>
< a class =B/>
< a class =B/>
< a class =A/>
< a class =B/>
< a class =B/>
< a class =B/>
< / r>
< a class =A />
和第三个< a class =A/>
:
/ * / a [@ class ='A'] [2] / following-sibling :: a [
@ class ='B'and count( -sibling :: a [@ class ='A'])= 2]
a
元素,它们有一个<$ c $在第二个 a
之后的c> class 属性的值等于 B
一个类属性等于 A
,并且只有两个具有 class
属性等于 A
<>之后的同胞集合中的所有
和2)第三个 @ class ='B'
a class =A/> < a class =A/>
。这两个集合的交集正好是这两个分隔元素之间的节点,可以这样表示:
/ * / a [@ class ='A'] [2] / following-sibling :: a [@ class ='B'] [
count(。| / * / a [@ class ='A'] [ 3] / preceding-sibling :: a [@ class ='B'])= $ b $ count(/ * / a [@ class ='A'] [3] / preceding-sibling :: a [@class ='B'])]
//a[@class='A']/following-sibling::a[@class='B']
. This query outputs 4 <a class="B"/>
elements. <a class="B"/>
elements that follow the current <a class="A"/>
element, and no others that follow other <a class="B"/>
elements/nodes. In other words, I only want the following <a class="B"/>
sibling elements until the next <a class="B"/>
element shows up.<a class='A' />
<a class='B' />
<a class='A' />
<a class='B' />
<a class='B' />
<a class='B' />
a
elements having a class
attribute of B
between some specific a
with a class
equal to A
and the next such occurrence:/*/a[@class='A'][$n]/following-sibling::a[
@class='B' and count(preceding-sibling::a[@class='A'])=$n]
a[@class='A']
and the next such element. For a specific example, consider the following input:<r>
<a class="A"/>
<a class="B"/>
<a class="A"/>
<a class="B"/>
<a class="B"/>
<a class="A"/>
<a class="B"/>
<a class="B"/>
<a class="B"/>
</r>
<a class="A"/>
and the third <a class="A"/>
:/*/a[@class='A'][2]/following-sibling::a[
@class='B' and count(preceding-sibling::a[@class='A'])=2]
a
elements having a class
attribute whose value is equal to B
that come after the second a
having a class attribute equal to A
and that have only two preceding siblings having a class
attribute equal to A
@class='B'
elements in 1) the set of siblings after the second <a class="A"/>
and 2) the set of siblings before the third <a class="A"/>
. The intersection of these two sets is precisely the nodes that come between those two divider elements and can be expressed like this:/*/a[@class='A'][2]/following-sibling::a[@class='B'][
count(.|/*/a[@class='A'][3]/preceding-sibling::a[@class='B'])=
count(/*/a[@class='A'][3]/preceding-sibling::a[@class='B'])]