W3C home > Mailing lists > Public > www-style@w3.org > July 1996

RE: CSS1 Lookup

From: Chris Wilson (PSD) <cwilso@microsoft.com>
Date: Fri, 5 Jul 1996 13:00:08 -0700
Message-Id: <c=US%a=_%p=msft%l=RED-76-MSG-960705200008Z-25164@abash1.microsoft.com>
To: "'Hakon Lie'" <howcome@w3.org>, "'Douglas Rand'" <drand@sgi.com>
Cc: "'www-style@w3.org'" <www-style@w3.org>
>Douglas Rand <drand@sgi.com> wrote:
>>If you had sample code for a context lookup,  I think alot of browsers
>>could indeed support CSS1 within a few weeks.  I'd like to at least see
>>a published algorithm,  not necessarily optimal,  for the lookup code.  

As I discussed in my presentation at WWW5, I found the difficult part of
implementing CSS (in Internet Explorer) to be maintaining a document
tree structure (any valid SGML document should be able to be treated as
a tree structure) while maintaining compatibility with all the legacy
code out there that has been authored using popular browsers as a
validation engine.  (This is not a veiled slam on Netscape; as I also
said in my talk, I can hold myself to blame, for originally implementing
the ability to handle improperly nested <B> and <I> tags in NCSA Mosaic
for Windows.)  The context-matching, on the other hand, I thought was
reasonably trivial (took me an afternoon).  If this will speed the
acceptance of CSS, though, then by all means you're welcome to the
algorithm.

Assume the document structure is stored as a tree, with each node
maintaining its CLASS, ID and tag name.  To test if a selector matches a
given document structure node, do the following:

While there are items left in the CSS selector,
    and we haven't walked off the top of the document structure tree
{
    if ( ( the tagname is given in the selector,
           and the tagname of the node doesn't match ) OR
         ( the CLASS is given in the selector,
           and the CLASS of the node doesn't match ) OR
         ( the ID is given in the selector,
           and the ID of the node doesn't match )
    {
        if this is the first item in the selector,
        {
            // The match failed. (the first selector item has to match
            // the current node in the document tree.)
            return FAILURE
        }
        else
        {
            skip to the next node in the document structure
            go to the top of this WHILE loop
            // (to try to match this selector item again with the next
            // node in the document structure tree.)
        }
    }
    else
    {
        // This node matched this part of the selector
        Skip to the next item in the document structure tree.
        Skip to the next item in the selector.
    }
}
return SUCCESS;

>	-Chris
>Chris Wilson
>cwilso@microsoft.com
>-[-
>
>
Received on Friday, 5 July 1996 15:59:50 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 27 April 2009 13:53:44 GMT