Sent by Bjoern Hoehrmann on 15 August 2004 19:07
* Julian Rickards wrote:
>The situation is like this:
>
><p>This paragraph does not have a link.</p>
><p>This paragraph does have a <a href="#">link</a>.</p>
>
>Without using classes or ids, is there a way to create style rules
>that: (1) if the paragraph has a link in it, color the paragraph text
>red, (2) if the paragraph does not have a link in it, color the
>paragraph text green.
No, the reason beeing that implementers want to calculate the applicable
rules in the moment they have read the start-tag of the element, which
only allows selections based on previous siblings and ancestor elements.
There is an exception in css3-selectors for e.g. :only-of-type which
needs to know about following-siblings but then implementers argued that
they do not want to make things worse...
W3C offers an alternate selection mechanism called XPath which is used
in XSLT, XForms, XML Schema, EMMA, XPointer, XQuery, etc. which can do
essentially everything structural CSS Selectors can do and much more,
the above would be e.g. p[a] which selects all p children of the context
node that have at least one a child. You could write a pre-processor
based on XPath that adds classes to the document based on a XPath
expression or use scripting to do that in the browser (a number of
browsers ship with XPath implementations, including Mozilla and Internet
Explorer for Windows). XHTML2 will require XPath support as it requires
support for XForms which requires XPath support, solutions based on
XPath make thus a lot of sense, e.g. as an extension to CSS Selectors...
______________________________________________________________________
css-discuss [EMAIL-REMOVED]]
http://www.css-discuss.org/mailman/listinfo/css-d
List wiki/FAQ -- http://css-discuss.incutio.com/
Supported by evolt.org -- http://www.evolt.org/help_support_evolt/