nsCOMPtr<nsIDOMNode> attribute; for (PRUint32 i = 0; i < length; ++i) { namedMap->Item(i, getter_AddRefs(attribute)); nsCOMPtr<nsIDOMAttr> attr(do_QueryInterface(attribute)); nsAutoString name; attr->GetName(name); if (!name.EqualsWithConversion("excludes")) { nsAutoString value; nsCOMPtr<nsIDOMElement> element(do_QueryInterface(mBoundElement)); element->GetAttribute(name, value); if (value.IsEmpty()) { nsAutoString value2; attr->GetValue(value2); nsCOMPtr<nsIAtom> atom = getter_AddRefs(NS_NewAtom(name)); mBoundElement->SetAttribute(kNameSpaceID_None, atom, value2, PR_FALSE);
nsCOMPtr<nsIContent> point; PRUint32 index; GetInsertionPoint(content, getter_AddRefs(point), &index); bindingManager->SetInsertionParent(content, point);   nsCOMPtr<nsIXBLInsertionPoint> insertionPoint; nsCOMPtr<nsISupportsArray> arr; GetInsertionPointsFor(point, getter_AddRefs(arr)); PRUint32 arrCount; arr->Count(&arrCount); for (PRUint32 j = 0; j < arrCount; j++) { insertionPoint = getter_AddRefs((nsIXBLInsertionPoint*)arr->ElementAt(j)); PRBool matches; insertionPoint->Matches(point, index, &matches); if (matches) break; insertionPoint = nsnull; }  if (!insertionPoint) { NS_ERROR("Filtered insertion point wasn't properly constructed.\n"); return NS_ERROR_FAILURE; } else insertionPoint->AddChild(content); } } else {  nsCOMPtr<nsISupportsArray> arr; GetInsertionPointsFor(singlePoint, getter_AddRefs(arr)); PRUint32 arrCount; arr->Count(&arrCount); nsCOMPtr<nsIXBLInsertionPoint> insertionPoint = getter_AddRefs((nsIXBLInsertionPoint*)arr->ElementAt(0));  nsCOMPtr<nsIDOMNode> node; nsCOMPtr<nsIContent> content; PRUint32 length; children->GetLength(&length); for (PRUint32 i = 0; i < length; i++) { children->Item(i, getter_AddRefs(node)); content = do_QueryInterface(node); bindingManager->SetInsertionParent(content, singlePoint); insertionPoint->AddChild(content); }
nsXBLBinding::GenerateAnonymousContent(nsIContent* aBoundElement){  // Set our bound element.  mBoundElement = aBoundElement;  // Fetch the content element for this binding.  nsCOMPtr<nsIContent> content;  GetImmediateChild(kContentAtom, getter_AddRefs(content));  if (!content) {    // We have no anonymous content.    if (mNextBinding)      return mNextBinding->GenerateAnonymousContent(aBoundElement);    else return NS_OK;  }  // Plan to build the content by default.  PRBool buildContent = PR_TRUE;  PRInt32 childCount;  aBoundElement->ChildCount(childCount);  if (childCount > 0) {    // See if there's an excludes attribute.    // We'll only build content if all the explicit children are     // in the excludes list.    nsAutoString excludes;    content->GetAttribute(kNameSpaceID_None, kExcludesAtom, excludes);    if (!excludes.EqualsWithConversion("*")) {      if (!excludes.IsEmpty()) {        // Walk the children and ensure that all of them        // are in the excludes array.        for (PRInt32 i = 0; i < childCount; i++) {          nsCOMPtr<nsIContent> child;          aBoundElement->ChildAt(i, *getter_AddRefs(child));          nsCOMPtr<nsIAtom> tag;          child->GetTag(*getter_AddRefs(tag));          if (!IsInExcludesList(tag, excludes)) {            buildContent = PR_FALSE;            break;          }        }      }      else buildContent = PR_FALSE;    }  }    nsCOMPtr<nsIContent> childrenElement;        if (!buildContent) {    // see if we have a <children/> element    GetNestedChild(kChildrenAtom, content, getter_AddRefs(childrenElement));    if (childrenElement) {      buildContent = PR_TRUE;    }  }    if (buildContent) {     // Always check the content element for potential attributes.    nsCOMPtr<nsIDOMNode> node(do_QueryInterface(content));    nsCOMPtr<nsIDOMNamedNodeMap> namedMap;    node->GetAttributes(getter_AddRefs(namedMap));    PRUint32 length;    namedMap->GetLength(&length);    nsCOMPtr<nsIDOMNode> attribute;    for (PRUint32 i = 0; i < length; ++i)    {      namedMap->Item(i, getter_AddRefs(attribute));      nsCOMPtr<nsIDOMAttr> attr(do_QueryInterface(attribute));      nsAutoString name;      attr->GetName(name);      if (!name.EqualsWithConversion("excludes")) {        nsAutoString value;        nsCOMPtr<nsIDOMElement> element(do_QueryInterface(mBoundElement));        element->GetAttribute(name, value);        if (value.IsEmpty()) {          nsAutoString value2;          attr->GetValue(value2);          nsCOMPtr<nsIAtom> atom = getter_AddRefs(NS_NewAtom(name));          mBoundElement->SetAttribute(kNameSpaceID_None, atom, value2, PR_FALSE);        }      }    }      nsCOMPtr<nsIDOMElement> domElement = do_QueryInterface(content);    nsCOMPtr<nsIDOMNode> clonedNode;    domElement->CloneNode(PR_TRUE, getter_AddRefs(clonedNode));        nsCOMPtr<nsIContent> clonedContent = do_QueryInterface(clonedNode);    SetAnonymousContent(clonedContent);    if (childrenElement) {      GetNestedChild(kChildrenAtom, clonedContent, getter_AddRefs(mChildrenElement));    }  }    if (mNextBinding) {    return mNextBinding->GenerateAnonymousContent(aBoundElement);  }  return NS_OK;}