Austin Cheney wrote:
> Scott Sauyet wrote:

>> how often do we really need to target something that can't be
>> expressed with CSS?
>
> All the time.  How can I target the following with CSS?
>
> * parent

Can't do this, by design.  This would be the primary advantage to
XPath

> * last child

p span:last-child

> * prior sibling

Can't do this, by design.

> * next sibling

p + *

> * first n named child of parent j

p > span:first-child

> * third n named child of parent j

p > span:nth-child(42)

> * first descendant of any name with attribute n and attribute value j

I don't know how to do this exactly, but this will get all such
descendents, in document order, so you can easily then select the
first one: p *[n='j']

> * first element where name contains "abc"

Can't be done, probably not by design, but because it's a very strange
request.  But you can do this with attribute values.>

> Name, in the above examples, refers to element name and not HTML name
> Attribute.

> As far as I know you can't do any of these with CSS, and the first is
> absolutely essential.  I am pretty sure all these are immediately
> achievable in XPath.  I need most of those pretty frequently and have to
> write conditional code in JavaScript loops to achieve some of these that
> XPath performs in a single simple expression that is faster to execute.

The only one of your list that I miss is parent.  And that only
rarely.


> I bet you need most of those too and probably just don't consider it as
> a selector when you are forced to write some amount of nested logic to
> accomplish similar objectives where such logic looks nothing like a
> selector.

On the other hand, can you find any better way to mimic `p.foo` than
the following?:

    //p[contains(concat(' ',normalize-space(@class),' '),' foo ')]

:-)

  -- Scott

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/jsmentors@jsmentors.com/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/jsmentors@googlegroups.com/

To unsubscribe from this group, send email to
jsmentors+unsubscr...@googlegroups.com

Reply via email to