Re: XPath & CSS, again

* Bert Bos wrote:
>I think XPath has different goals, viz., selecting not just elements, 
>but also individual attributes, comments, etc. And it is meant to be 
>used by a different group of people. That is why it has a different 
>syntax. Note that not only does it lack special syntax for CLASS 
>attributes, it *can't* select on CLASS attributes at all. (With XSLT, 
>my estimate is that you need about 50 lines to select an element with a 
>certain CLASS. With the new regular expressions in XPath 2.0 it is 
>tricky, but possible within XPath.) Clearly that is not what XPath was 
>designed for.

Selecting class attributes is tricky as it requires to know which
attributes have classes and how to get from the string value of the
attribute to a set of classes. Assuming that the type of the class
attribute is NMTOKENS (as in more recent document types) and on all
elements the "class" attribute is a class attribute, then you can
select those with

  *[@class="name"]

in XPath 2.0. There is no general solution though as you cannot
"type" an attribute value as associating classes with an element
with W3C Technology, implementations of the .class selector have
built-in knowledge for it. That's a problem aswell, if a document
type does not have a rule like

  Attributes with a local name of "class" in no namespace on any
  element in the http://example.org/ namespace must be considered
  [class attributes].

new elements in the http://example.org/ namespace could not be
considered to have associated classes until this is hard-coded in
the implementation. If there is such knowledge, it can easily be
used in XPath using extension functions, for example,

  *[css:class('name')]

could easily be defined to be equivalent to the *.name selector.
This could easily be defined in a general purpose way, you just
need an extension to data typing to more semantic typing (like
class typing here, maybe link typing, etc.) Without such typing
it is indeed a bit out of scope of XPath to address this problem.
-- 
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/ 

Received on Monday, 11 April 2005 23:32:18 UTC