function scan_styles($root, &$pipeline)
{
    switch ($root->node_type()) {
        case XML_ELEMENT_NODE:
            if ($root->tagname() === 'style') {
                // Parse <style ...> ... </style> nodes
                //
                parse_style_node($root, $pipeline);
            } elseif ($root->tagname() === 'link') {
                // Parse <link rel="stylesheet" ...> nodes
                //
                $rel = strtolower($root->get_attribute("rel"));
                $type = strtolower($root->get_attribute("type"));
                if ($root->has_attribute("media")) {
                    $media = explode(",", $root->get_attribute("media"));
                } else {
                    $media = array();
                }
                if ($rel == "stylesheet" && ($type == "text/css" || $type == "") && (count($media) == 0 || is_allowed_media($media))) {
                    $src = $root->get_attribute("href");
                    if ($src) {
                        css_import($src, $pipeline);
                    }
                }
            }
            // Note that we continue processing here!
        // Note that we continue processing here!
        case XML_DOCUMENT_NODE:
            // Scan all child nodes
            $child = $root->first_child();
            while ($child) {
                scan_styles($child, $pipeline);
                $child = $child->next_sibling();
            }
            break;
    }
}
function parse_css_property($property, &$pipeline)
{
    /**
     * Check for !important declaration; if it is present, remove the "!important"
     * substring from declaration text.
     *
     * @todo: store flag indicating that this property is important in returned data 
     */
    if (preg_match("/^(.*)!important/", $property, $matches)) {
        $property = $matches[1];
    }
    if (preg_match("/^(.*?)\\s*:\\s*(.*)/", $property, $matches)) {
        return array(strtolower(trim($matches[1])) => trim($matches[2]));
    } elseif (preg_match("/@import\\s+\"(.*)\";/", $property, $matches)) {
        // @import "<url>"
        css_import(trim($matches[1]), $pipeline);
    } elseif (preg_match("/@import\\s+url\\((.*)\\);/", $property, $matches)) {
        // @import url()
        css_import(trim($matches[1]), $pipeline);
    } elseif (preg_match("/@import\\s+(.*);/", $property, $matches)) {
        // @import <url>
        css_import(trim($matches[1]), $pipeline);
    } else {
        return array();
    }
}