nsXULTemplateBuilder::ContentIdTestNode::FilterInstantiations(InstantiationSet& aInstantiations) const
nsXULTemplateBuilder::ContentIdTestNode::FilterInstantiations(InstantiationSet& aInstantiations, void* aClosure) const
nsXULTemplateBuilder::ContentIdTestNode::FilterInstantiations(InstantiationSet& aInstantiations) const{    nsresult rv;    nsCOMPtr<nsISupportsArray> elements;    rv = NS_NewISupportsArray(getter_AddRefs(elements));    if (NS_FAILED(rv)) return rv;    InstantiationSet::Iterator last = aInstantiations.Last();    for (InstantiationSet::Iterator inst = aInstantiations.First(); inst != last; ++inst) {        Value contentValue;        PRBool hasContentBinding = inst->mBindings.GetBindingFor(mContentVariable, &contentValue);        Value idValue;        PRBool hasIdBinding = inst->mBindings.GetBindingFor(mIdVariable, &idValue);        if (hasContentBinding && hasIdBinding) {            // both are bound, consistency check            nsCOMPtr<nsIRDFResource> resource;            gXULUtils->GetElementRefResource(VALUE_TO_ICONTENT(contentValue), getter_AddRefs(resource));                        if (resource.get() == VALUE_TO_IRDFRESOURCE(idValue)) {                inst->AddSupportingElement(new Element(VALUE_TO_ICONTENT(contentValue)));            }            else {                aInstantiations.Erase(inst--);            }        }        else if (hasContentBinding) {            // the content node is bound, get its id            nsCOMPtr<nsIRDFResource> resource;            gXULUtils->GetElementRefResource(VALUE_TO_ICONTENT(contentValue), getter_AddRefs(resource));            if (NS_FAILED(rv)) return rv;            if (resource) {                Instantiation newinst = *inst;                newinst.AddBinding(mIdVariable, Value(resource.get()));                newinst.AddSupportingElement(new Element(VALUE_TO_ICONTENT(contentValue)));                aInstantiations.Insert(inst, newinst);            }            aInstantiations.Erase(inst--);        }        else if (hasIdBinding) {            // the 'id' is bound, find elements in the content tree that match            const char* uri;            rv = VALUE_TO_IRDFRESOURCE(idValue)->GetValueConst(&uri);            if (NS_FAILED(rv)) return rv;            rv = mDocument->GetElementsForID(NS_ConvertASCIItoUCS2(uri), elements);            if (NS_FAILED(rv)) return rv;            PRUint32 count;            rv = elements->Count(&count);            if (NS_FAILED(rv)) return rv;            for (PRInt32 j = PRInt32(count) - 1; j >= 0; --j) {                nsISupports* isupports = elements->ElementAt(j);                nsCOMPtr<nsIContent> element = do_QueryInterface(isupports);                NS_IF_RELEASE(isupports);                if (IsElementContainedBy(element, mRoot)) {                    Instantiation newinst = *inst;                    newinst.AddBinding(mContentVariable, Value(element.get()));                    newinst.AddSupportingElement(new Element(element));                    aInstantiations.Insert(inst, newinst);                }            }            aInstantiations.Erase(inst--);        }    }    return NS_OK;}