nsCOMPtr<nsIContent> tmpl; bestmatch->mRule->GetContent(getter_AddRefs(tmpl));
nsXULTemplateBuilder::FireNewlyMatchedRules(const ClusterKeySet& aNewKeys){    // Iterate through newly added keys to determine which rules fired.    //    // XXXwaterson Unfortunately, this could also lead to retractions;    // e.g., (contaner ?a ^empty false) could become "unmatched". How    // to track those?    ClusterKeySet::ConstIterator last = aNewKeys.Last();    for (ClusterKeySet::ConstIterator key = aNewKeys.First(); key != last; ++key) {        MatchSet* matches;        mConflictSet.GetMatchesForClusterKey(*key, &matches);        NS_ASSERTION(matches != nsnull, "no matched rules for new key");        if (! matches)            continue;        Match* bestmatch =            matches->FindMatchWithHighestPriority();        NS_ASSERTION(bestmatch != nsnull, "no matches in match set");        if (! bestmatch)            continue;        // XXXwaterson fix me!        const Match* lastmatch = matches->GetLastMatch();        if (bestmatch != lastmatch) {            Value value;            nsIContent* content;            PRBool hasassignment;            if (lastmatch) {                // See if we need to yank anything out of the content                // model to handle the newly matched rule. If the                // instantiation has a assignment for the content                // variable, there's content that's been built that we                // need to pull.                hasassignment = lastmatch->mAssignments.GetAssignmentFor(mContentVar, &value);                NS_ASSERTION(hasassignment, "no content assignment");                if (! hasassignment)                    return NS_ERROR_UNEXPECTED;                nsIContent* parent = VALUE_TO_ICONTENT(value);                PRInt32 membervar = lastmatch->mRule->GetMemberVariable();                hasassignment = lastmatch->mAssignments.GetAssignmentFor(membervar, &value);                NS_ASSERTION(hasassignment, "no member assignment");                if (! hasassignment)                    return NS_ERROR_UNEXPECTED;                nsIRDFResource* member = VALUE_TO_IRDFRESOURCE(value);                RemoveMember(parent, member, PR_TRUE);            }            // Get the content node to which we were bound            hasassignment = bestmatch->mAssignments.GetAssignmentFor(mContentVar, &value);            NS_ASSERTION(hasassignment, "no content assignment");            if (! hasassignment)                continue;            content = VALUE_TO_ICONTENT(value);            nsCOMPtr<nsIContent> tmpl;            bestmatch->mRule->GetContent(getter_AddRefs(tmpl));            PRBool contentsGenerated = PR_TRUE;            nsCOMPtr<nsIXULContent> xulcontent = do_QueryInterface(content);            if (xulcontent)                xulcontent->GetLazyState(nsIXULContent::eContainerContentsBuilt, contentsGenerated);            if (contentsGenerated) {                BuildContentFromTemplate(tmpl, content, content, PR_TRUE,                                         VALUE_TO_IRDFRESOURCE(key->mMemberValue),                                         PR_TRUE, bestmatch, nsnull, nsnull);                // Remember the best match as the new "last" match                matches->SetLastMatch(bestmatch);            }            else {                // If we don't build the content, then pretend we                // never saw this match.                matches->Remove(bestmatch);            }            // Update the 'empty' attribute            SetContainerAttrs(content, bestmatch);        }    }    return NS_OK;}