diff --git a/content/xul/templates/src/nsXULTemplateResultXML.cpp b/content/xul/templates/src/nsXULTemplateResultXML.cpp index 4052bd249813..8383c324d1eb 100644 --- a/content/xul/templates/src/nsXULTemplateResultXML.cpp +++ b/content/xul/templates/src/nsXULTemplateResultXML.cpp @@ -51,8 +51,30 @@ NS_IMPL_ISUPPORTS1(nsXULTemplateResultXML, nsIXULTemplateResult) nsXULTemplateResultXML::nsXULTemplateResultXML(nsXMLQuery* aQuery, nsIDOMNode* aNode, nsXMLBindingSet* aBindings) - : mId(++sTemplateId), mQuery(aQuery), mNode(aNode) + : mQuery(aQuery), mNode(aNode) { + nsCOMPtr content = do_QueryInterface(mNode); + + // If the node has an id, create the uri from it. Otherwise, there isn't + // anything to identify the node with so just use a somewhat random number. + nsCOMPtr id = content->GetID(); + if (id) { + nsCOMPtr uri = content->GetBaseURI(); + nsCAutoString spec; + uri->GetSpec(spec); + + mId = NS_ConvertUTF8toUTF16(spec); + + nsAutoString idstr; + id->ToString(idstr); + mId += NS_LITERAL_STRING("#") + idstr; + } + else { + nsAutoString rowid(NS_LITERAL_STRING("row")); + rowid.AppendInt(++sTemplateId); + mId.Assign(rowid); + } + if (aBindings) mRequiredValues.SetBindingSet(aBindings); } @@ -97,9 +119,7 @@ nsXULTemplateResultXML::GetMayProcessChildren(PRBool* aMayProcessChildren) NS_IMETHODIMP nsXULTemplateResultXML::GetId(nsAString& aId) { - nsAutoString rowid(NS_LITERAL_STRING("row")); - rowid.AppendInt(mId); - aId.Assign(rowid); + aId = mId; return NS_OK; } diff --git a/content/xul/templates/src/nsXULTemplateResultXML.h b/content/xul/templates/src/nsXULTemplateResultXML.h index 9792ade67b22..73ea80655344 100644 --- a/content/xul/templates/src/nsXULTemplateResultXML.h +++ b/content/xul/templates/src/nsXULTemplateResultXML.h @@ -38,6 +38,7 @@ #define nsXULTemplateResultXML_h__ #include "nsCOMPtr.h" +#include "nsIURI.h" #include "nsIRDFResource.h" #include "nsXULTemplateQueryProcessorXML.h" #include "nsIXULTemplateResult.h" @@ -62,8 +63,11 @@ public: protected: - // result id - PRUint32 mId; + // ID used for persisting data. It is constructed using the mNode's + // base uri plus the node's id to form 'baseuri#id'. If the node has no + // id, then an id of the form 'row' is generated. In the + // latter case, persistence will not work as there won't be a unique id. + nsAutoString mId; // query that generated the result nsCOMPtr mQuery; diff --git a/content/xul/templates/tests/chrome/animals.xml b/content/xul/templates/tests/chrome/animals.xml index 1c2723c4f939..f73ec718b1ec 100644 --- a/content/xul/templates/tests/chrome/animals.xml +++ b/content/xul/templates/tests/chrome/animals.xml @@ -1,15 +1,19 @@ + +]> + Reptiles - + Birds - - - + + + Aviary diff --git a/content/xul/templates/tests/chrome/test_tmpl_xmlquerysimple.xul b/content/xul/templates/tests/chrome/test_tmpl_xmlquerysimple.xul index fdf968534c35..c2165c6a7604 100644 --- a/content/xul/templates/tests/chrome/test_tmpl_xmlquerysimple.xul +++ b/content/xul/templates/tests/chrome/test_tmpl_xmlquerysimple.xul @@ -30,10 +30,10 @@ var notWorkingYet = false; var notWorkingYetDynamic = false; var expectedOutput = -