EXAMPLE 1:
<body>
<div>
<h1>category1</h1><a>sibling1</a><a>sibling2</a><h1>category2</h1><a>sibling3</a><a>sibling4</a>
</div>
</body>
so they don’t have a common ancestor other than that they are under the single div. How would you be able to produce (that can be expressed by an xpath) the following resulting string data format?
category1,sibling1,sibling2;
category2,sibling3,sibling4;
if EXAMPLE 1 was something like this:
<body>
<div>
<span>
<h1>category1</h1><a>sibling1</a><a>sibling2</a>
</span>
<span>
<h1>category2</h1><a>sibling3</a><a>sibling4</a>
</span>
</div>
</body>
here in this case, it’s quite easy, all that is required is to capture all <SPAN> tags via //span xpath expression and look insde each <span> tags for it’s <h1> & <a> inside it.
You can select all
h1using//h1, then select two siblings of h1, i.e.:following-sibling::*[position() < 3]