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) BuildInsertionTable();
clonedContent = do_QueryInterface(clonedNode); SetAnonymousContent(clonedContent);  if (hasInsertionPoints) {      mPrototypeBinding->InstantiateInsertionPoints(this);        ContentListData data(this, bindingManager); mInsertionPointTable->Enumerate(BuildContentLists, &data);    nsCOMPtr<nsIContent> singlePoint; PRUint32 index = 0; PRBool multiplePoints = PR_FALSE; nsCOMPtr<nsIContent> singleDefaultContent; GetSingleInsertionPoint(getter_AddRefs(singlePoint), &index, &multiplePoints, getter_AddRefs(singleDefaultContent));  if (children) { if (multiplePoints) {   children->GetLength(&length); for (PRUint32 i = 0; i < length; i++) { children->Item(i, getter_AddRefs(node)); childContent = do_QueryInterface(node);   nsCOMPtr<nsIContent> point; PRUint32 index; nsCOMPtr<nsIContent> defContent; GetInsertionPoint(childContent, getter_AddRefs(point), &index, getter_AddRefs(defContent)); bindingManager->SetInsertionParent(childContent, point);   nsVoidArray* arr; GetInsertionPointsFor(point, &arr); nsXBLInsertionPoint* insertionPoint = nsnull; PRInt32 arrCount = arr->Count(); for (PRInt32 j = 0; j < arrCount; j++) { insertionPoint = NS_STATIC_CAST(nsXBLInsertionPoint*, arr->ElementAt(j)); if (insertionPoint->Matches(point, index)) break; insertionPoint = nsnull; }  if (insertionPoint) insertionPoint->AddChild(childContent); else {    nsINodeInfo *ni = childContent->GetNodeInfo();  if (!ni || (!ni->Equals(nsXULAtoms::observes, kNameSpaceID_XUL) && !ni->Equals(nsXULAtoms::templateAtom, kNameSpaceID_XUL))) {  mContent = nsnull; bindingManager->SetContentListFor(mBoundElement, nsnull); bindingManager->SetAnonymousNodesFor(mBoundElement, nsnull); return NS_OK; } } } } else {  nsVoidArray* arr; GetInsertionPointsFor(singlePoint, &arr); nsXBLInsertionPoint* insertionPoint = NS_STATIC_CAST(nsXBLInsertionPoint*, 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); } } }     mInsertionPointTable->Enumerate(RealizeDefaultContent, &data); } }  mPrototypeBinding->SetInitialAttributes(mBoundElement, mContent); }     PRUint32 length = content->GetAttrCount();  PRInt32 namespaceID; nsCOMPtr<nsIAtom> name; nsCOMPtr<nsIAtom> prefix;  for (PRUint32 i = 0; i < length; ++i) { content->GetAttrNameAt(i, &namespaceID, getter_AddRefs(name), getter_AddRefs(prefix));  if (name != nsXBLAtoms::includes) { nsAutoString value; mBoundElement->GetAttr(namespaceID, name, value); if (value.IsEmpty()) { nsAutoString value2; content->GetAttr(namespaceID, name, value2); mBoundElement->SetAttr(namespaceID, name, value2, PR_FALSE); } }   if (mContent) mContent->UnsetAttr(namespaceID, name, PR_FALSE);
nsXBLBinding::GenerateAnonymousContent(nsIContent* 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;  // 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)      BuildInsertionTable();  }    /* XXX Handle selective decision to build anonymous content.  if (mNextBinding) {    return mNextBinding->GenerateAnonymousContent(aBoundElement);  }  */  return NS_OK;}