GetTemplateRoot(getter_AddRefs(tmpl)); if (! tmpl) return NS_OK;
nsXULTemplateBuilder::CompileRules(){    NS_PRECONDITION(mRoot != nsnull, "not initialized");    if (! mRoot)        return NS_ERROR_NOT_INITIALIZED;    mRulesCompiled = PR_FALSE;    // Initialize the rule network    InitializeRuleNetwork();    nsCOMPtr<nsIContent> tmpl;    GetTemplateRoot(getter_AddRefs(tmpl));    if (! tmpl)        return NS_OK;    // Used for simple rules, if there are any.    InnerNode* childnode = nsnull;    // Set the "container" and "member" variables, if the user has    // specified them.    mContainerSymbol.Truncate();    tmpl->GetAttr(kNameSpaceID_None, nsXULAtoms::container, mContainerSymbol);    if (!mContainerSymbol.IsEmpty())        mRules.PutSymbol(mContainerSymbol.get(), mContainerVar);    mMemberSymbol.Truncate();    tmpl->GetAttr(kNameSpaceID_None, nsXULAtoms::member, mMemberSymbol);    if (!mMemberSymbol.IsEmpty())        mRules.PutSymbol(mMemberSymbol.get(), mMemberVar);    // Compile the rules beneath the <template>    PRInt32 count = 0;    tmpl->ChildCount(count);    PRInt32 nrules = 0;    for (PRInt32 i = 0; i < count; i++) {        nsCOMPtr<nsIContent> rule;        tmpl->ChildAt(i, getter_AddRefs(rule));        if (! rule)            break;        PRInt32 nameSpaceID = kNameSpaceID_Unknown;        rule->GetNameSpaceID(&nameSpaceID);        if (nameSpaceID != kNameSpaceID_XUL)            continue;        nsCOMPtr<nsIAtom> tag;        rule->GetTag(getter_AddRefs(tag));        if (tag.get() == nsXULAtoms::rule) {            ++nrules;            // If the <rule> has a <conditions> element, then            // compile it using the extended syntax.            nsCOMPtr<nsIContent> conditions;            nsXULContentUtils::FindChildByTag(rule,                                              kNameSpaceID_XUL,                                              nsXULAtoms::conditions,                                              getter_AddRefs(conditions));            if (conditions)                CompileExtendedRule(rule, nrules, mRules.GetRoot());            else {                if (! childnode)                    InitializeRuleNetworkForSimpleRules(&childnode);                CompileSimpleRule(rule, nrules, childnode);            }        }    }    if (nrules == 0) {        // if no rules are specified in the template, then the        // contents of the <template> tag are the one-and-only        // template.        InitializeRuleNetworkForSimpleRules(&childnode);        CompileSimpleRule(tmpl, 1, childnode);    }    // XXXwaterson post-process the rule network to optimize    mRulesCompiled = PR_TRUE;    return NS_OK;}