On Tuesday, 22 November 2011 11:50 AM, "Robin Berjon" <[email protected]> wrote:
> 
> So let's start again and do it right this time. Martin: what are your use
> cases for XPath that aren't addressed with the current support for CSS
> Selectors?
> 
> -- 
> Robin Berjon - http://berjon.com/ - @robinberjon
> 

Thank you for support.
In my opinion, there are two use cases for XPath:
1) It's much harder to write the CSS selector
e.g.:
CSS: "article > div:nth-child(2) input[type=text], article > div:nth-child(2) 
input:not([type]), article > div:nth-child(2) input[type=color]";
XPath: "//article/div[2]//input[@type='text' | @type='color'| not(@type)]";

2) It's impossible to write the CSS selector (or really really hard/long)
a - "*[@data-price>30]";
b - "*[position()<30]";
c - "div[@*]";
d - "//div[parent::*//a]";
e - ...

Anyway, mostly when I use XPath instead of CSS selectors it's because of XPath 
axis - the ability to go not just deeper but also higher in the element tree. 
XPath can also work with any node, not just elements.

There are definitely lots of cases when CSS selectors are much more powerful 
than XPath. Mainly when there are many of class names and ids involved. And 
that is why I think that XPath and CSS selectors are not rivals - they are 
exactly the opposite, they complement each other.

Cheers,
Martin

Reply via email to