Is it possible to combine XPath and CSS selectors

cssxmlxpath

Just came through XPath.

I got curious about this. Why is there a different way to select tags in XPath and CSS(selectors).

Why cant there be a common way in both XPath and CSS?

Best Answer

CSS is not designed to be used as a selector. It's purpose is to mark similar items in markup, so that they can be styled in the same way across the document. Because jQuery (et al) is also related to styling, and functionality is often attached to similar items in markup, CSS selectors have become commonplace in that arena.

If this doesn't explain it then imagine what an XPath Stylesheet sould look like. Perhaps something like this:

/html/body/div/table/tr/td[3]/div {
    background-color: #800;
}

Now, if you add a column to the table, or add a div into the structure, or maybe redefine the first div using HTML5's <article> tag, you're going to have to go and redefine your style's path.

Or, in reverse, imagine having to put a CSS tag on everything, just so that you can find it. What a PITA that would be.

Related Topic