I wish CSS was smarter…

There’s a wonderful technology for XML called XPath. XML as you may know is a structured markup language that represents a document as a tree. XPath allows you to find parts of that tree (called nodes, actually there are several names for the parts…) with wonderful little recipes.

With CSS, given a XHTML document, I can find an anchor that is the child of a list item in the following manner: li a XPath is similar: li/a (of course there are other ways in both).

One thing that I can do in XPath that CSS cannot do is go backwards. In XHTML I can give an anchor a class or id to make it more CSS findable (among other things). a.external could represent an anchor that links to the outside world. In XPath I can do the same (//a[@class = 'external']) albeit not as succinctly. XPath lets me do the following //a[@class = 'external']/.. to match the parent of an anchor that links to something external. CSS cannot do the same.

Boy do I wish it could.

This entry was posted in web, work, xml. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Spam Protection by WP-SpamFree