I have an XML structure similar to this:
<Header>
<ElementA>
<ElementB>
<ElementC/>
<ElementC/>
</ElementB>
<ElementB/>
</ElementA>
</Header>
where the <ElementB> may have a sequence of <ElementC>, or may have none.
I can select <ElementA> nodes which have two <ElementB> by /Header/ElementA/ElementB/following-sibling::ElementB. I can select <ElementA> nodes which contain an <ElementB> node which contains an <ElementC> using /Header/ElementA/ElementB[ElementC].
But how do I select <ElementA> nodes which contain an <ElementB> which contains an <ElementC> followed by another <ElementB> containing another <ElementC>. Something like this:
<Header>
<ElementA>
<ElementB>
<ElementC/>
<ElementC/>
</ElementB>
<ElementB>
<ElementC/>
<ElementC/>
</ElementB>
</ElementA>
</Header>
Note that you don’t have to explicitly search the following-sibling axis. These two patterns will return the same result:
and
So your pattern can be as simple as:
which will find
ElementAelements that have two or moreElementBchildren, each of which has anElementCchild.