Xpath:: Get Following Sibling

XPath:: Get following Sibling

You should be looking for the second tr that has the td that equals ' Color Digest ', then you need to look at either the following sibling of the first td in the tr, or the second td.

Try the following:

//tr[td='Color Digest'][2]/td/following-sibling::td[1]

or

//tr[td='Color Digest'][2]/td[2]

http://www.xpathtester.com/saved/76bb0bca-1896-43b7-8312-54f924a98a89

XPath: Get following-sibling based on text() only

You almost got it right, here you go, you just needed to show where exactly you want to look for. I hope this helps:

//td[text()="Looking for"]/following-sibling::td[text()="This!"]

How to select following sibling/XML tag using XPath

How would I accomplish the nextsibling
and is there an easier way of doing
this?

You may use:

tr/td[@class='name']/following-sibling::td

but I'd rather use directly:

tr[td[@class='name'] ='Brand']/td[@class='desc']

This assumes that:

  1. The context node, against which the XPath expression is evaluated is the parent of all tr elements -- not shown in your question.

  2. Each tr element has only one td with class attribute valued 'name' and only one td with class attribute valued 'desc'.

XPath to match only directly following siblings

Is there some reason you can't take the simple approach of picking all of the divs that don't have id attributes?

div[not(@id)]

Or, perhaps, divs with a style attribute?

div[@style]

If, for some reason, that's not acceptable, you can go with something more like what you were thinking:

div[@style][following-sibling::div[@id='foo1']]

Which gets all of the divs with style attributes which come before divs matching a particular id. Is that what you're asking for?

I imagine your actual input HTML is less trivial than the example you've provided, but all of these XPath expressions I've listed work with your example. If you could provide more specific detail about what your expected output is and what issues you've been facing then I can give you more help.

XPath - All following siblings except first specific elements

Use:

 /table[@id='target']/following-sibling::*[not(self::table) and not(self::ol)] 
|
/table[@id='target']/following-sibling::table[position() > 1]
|
/table[@id='target']/following-sibling::ol[position() > 1]

This selects all the following siblings of the table that are not table and are not ol and all the following table siblings with position 2 or greater and all the following ol siblings with position 2 or greater.

Which is exactly what you want: all following siblings with the exception of the first table following sibling and the first ol following siblings.

This is pure XPath 1.0 and not using any XSLT functions.

xpath with following-sibling

You can try following instead of following-sibling as mentioned h3 and table nodes are not siblings:

//div[@id="topTenSellers"]//h3[@class="box-title" and .="OODR Items for next 20 Days"]/following::table[@class="table table-hover"]


Related Topics



Leave a reply



Submit