RE: CSS1 Lookup

>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 UTC