if (aNewMatch) {
if (!aNewMatch) {
nsXULContentBuilder::ReplaceMatch(nsIRDFResource* aMember,                                  const nsTemplateMatch* aOldMatch,                                  nsTemplateMatch* aNewMatch){    if (aOldMatch) {        // 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.        Value value;        PRBool hasassignment =            aOldMatch->mAssignments.GetAssignmentFor(mContentVar, &value);        NS_ASSERTION(hasassignment, "no content assignment");        if (! hasassignment)            return NS_ERROR_UNEXPECTED;        nsIContent* content = VALUE_TO_ICONTENT(value);        PRInt32 membervar = aOldMatch->mRule->GetMemberVariable();        hasassignment = aOldMatch->mAssignments.GetAssignmentFor(membervar, &value);        NS_ASSERTION(hasassignment, "no member assignment");        if (! hasassignment)            return NS_ERROR_UNEXPECTED;        nsIRDFResource* member = VALUE_TO_IRDFRESOURCE(value);        RemoveMember(content, member, PR_TRUE);        if (aNewMatch) {            // If there's no new match, then go ahead an update the            // container attributes now.            SetContainerAttrs(content, aOldMatch);        }    }    if (aNewMatch) {        // Get the content node to which we were bound        Value value;        PRBool hasassignment =            aNewMatch->mAssignments.GetAssignmentFor(mContentVar, &value);        NS_ASSERTION(hasassignment, "no content assignment");        if (! hasassignment)            return NS_ERROR_UNEXPECTED;        nsIContent* content = VALUE_TO_ICONTENT(value);        // Update the 'empty' attribute. Do this *first*, because        // we may decide to nuke aNewMatch in a minute...        SetContainerAttrs(content, aNewMatch);        // See if we've built the container contents for "content"        // yet. If not, we don't need to build any content. This        // happens, for example, if we recieve an assertion on a        // closed folder in a tree widget or on a menu that hasn't        // yet been dropped.        PRBool contentsGenerated = PR_TRUE;        nsCOMPtr<nsIXULContent> xulcontent = do_QueryInterface(content);        if (xulcontent)            xulcontent->GetLazyState(nsIXULContent::eContainerContentsBuilt, contentsGenerated);        if (contentsGenerated) {            nsCOMPtr<nsIContent> tmpl;            aNewMatch->mRule->GetContent(getter_AddRefs(tmpl));            BuildContentFromTemplate(tmpl, content, content, PR_TRUE,                                     aMember, PR_TRUE, aNewMatch,                                     nsnull, nsnull);        }    }    return NS_OK;}