for (PRUint32 i = 0; i < nodeCount; ++i) { result->SnapshotItem(i, getter_AddRefs(node)); NS_ASSERTION(node, "incorrect snapshot length");  document->CreateElementNS(NS_LITERAL_STRING(NS_NAMESPACE_XFORMS), NS_LITERAL_STRING("item"), getter_AddRefs(itemNode));  if (!itemNode) return NS_OK;  nsCOMPtr<nsIDOMElement> modelElement = do_QueryInterface(model); nsAutoString modelID; modelElement->GetAttribute(NS_LITERAL_STRING("id"), modelID);  itemNode->SetAttribute(NS_LITERAL_STRING("model"), modelID);  nsCOMPtr<nsIXFormsSelectChild> item = do_QueryInterface(itemNode); NS_ASSERTION(item, "item must be a SelectChild!");  item->SetContext(nsCOMPtr<nsIDOMElement>(do_QueryInterface(node)), i, nodeCount);   for (PRUint32 j = 0; j < templateNodeCount; ++j) { templateNodes->Item(j, getter_AddRefs(templateNode)); templateNode->CloneNode(PR_TRUE, getter_AddRefs(cloneNode)); itemNode->AppendChild(cloneNode, getter_AddRefs(templateNode));
nsCOMPtr<nsIDOMNode> parent, tmp; mElement->GetParentNode(getter_AddRefs(parent)); PRBool parentIsSelect1 = PR_FALSE; while (parent && !nsXFormsUtils::IsXFormsElement(parent, NS_LITERAL_STRING("select"))) { if (nsXFormsUtils::IsXFormsElement(parent, NS_LITERAL_STRING("select1"))) { parentIsSelect1 = PR_TRUE; break; } tmp.swap(parent); tmp->GetParentNode(getter_AddRefs(parent)); }  if (parentIsSelect1) {  nsCOMPtr<nsIXFormsItemSetUIElement> uiItemSet(do_QueryInterface(mElement)); nsCOMPtr<nsIDOMElement> anonContent; if (uiItemSet) { uiItemSet->GetAnonymousItemSetContent(getter_AddRefs(anonContent));
nsXFormsItemSetElement::Refresh(){  mItems.Clear();  // We need to create item elements for each element referenced by the  // nodeset.  Each of these items will create an anonymous HTML option element  // which will return from GetAnonymousNodes.  We then clone our template  // content and insert the cloned content as children of the HTML option.  nsCOMPtr<nsIDOMDocument> domDoc;  mElement->GetOwnerDocument(getter_AddRefs(domDoc));  if (!nsXFormsUtils::IsDocumentReadyForBind(domDoc)) {    // not ready to bind yet, defer    nsXFormsModelElement::DeferElementBind(domDoc, this);    return NS_OK;  }  nsCOMPtr<nsIModelElementPrivate> model;  nsCOMPtr<nsIDOMXPathResult> result;  nsXFormsUtils::EvaluateNodeBinding(mElement,                                     nsXFormsUtils::ELEMENT_WITH_MODEL_ATTR,                                     NS_LITERAL_STRING("nodeset"),                                     EmptyString(),                                     nsIDOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE,                                     getter_AddRefs(model),                                     getter_AddRefs(result));  if (!result)    return NS_OK;  nsCOMPtr<nsIDOMNode> node, templateNode, cloneNode;  nsCOMPtr<nsIDOMElement> itemNode, itemWrapperNode;  nsCOMPtr<nsIDOMNodeList> templateNodes;  mElement->GetChildNodes(getter_AddRefs(templateNodes));  PRUint32 templateNodeCount = 0;  if (templateNodes)    templateNodes->GetLength(&templateNodeCount);    nsCOMPtr<nsIDOMDocument> document;  mElement->GetOwnerDocument(getter_AddRefs(document));  if (!document)    return NS_OK;  PRUint32 nodeCount;  result->GetSnapshotLength(&nodeCount);  for (PRUint32 i = 0; i < nodeCount; ++i) {    result->SnapshotItem(i, getter_AddRefs(node));    NS_ASSERTION(node, "incorrect snapshot length");    document->CreateElementNS(NS_LITERAL_STRING(NS_NAMESPACE_XFORMS),                              NS_LITERAL_STRING("item"),                              getter_AddRefs(itemNode));    if (!itemNode)      return NS_OK;    nsCOMPtr<nsIDOMElement> modelElement = do_QueryInterface(model);    nsAutoString modelID;    modelElement->GetAttribute(NS_LITERAL_STRING("id"), modelID);    itemNode->SetAttribute(NS_LITERAL_STRING("model"), modelID);    nsCOMPtr<nsIXFormsSelectChild> item = do_QueryInterface(itemNode);    NS_ASSERTION(item, "item must be a SelectChild!");    item->SetContext(nsCOMPtr<nsIDOMElement>(do_QueryInterface(node)),                     i, nodeCount);    // Clone the template content under the item    for (PRUint32 j = 0; j < templateNodeCount; ++j) {      templateNodes->Item(j, getter_AddRefs(templateNode));      templateNode->CloneNode(PR_TRUE, getter_AddRefs(cloneNode));      itemNode->AppendChild(cloneNode, getter_AddRefs(templateNode));    }    mItems.AppendObject(item);  }  // refresh parent control, since we are being defered  nsCOMPtr<nsIDOMNode> parentNode;  mElement->GetParentNode(getter_AddRefs(parentNode));  if (parentNode) {    nsCOMPtr<nsIXFormsControlBase> stub = do_QueryInterface(parentNode);    if (stub) {      stub->Refresh();    }  }  return NS_OK;}