Best practice getting data from Multi-Node Tree Picker
Assume I want to select e.g. 20 nodes from all-over the content tree using the Multi-Node Tree Picker or another tree picker able to save multiple values.
What would be the best way of getting the data from these nodes? Loop through the id's from the tree picker and then use GetXmlNodeById to retrieve the data for each node? Filter $currentPage using contains? Please note that I would prefer having one nodeset to work with for further sorting, filtering etc.
Surely the best would be to have a something like GetXmlNodesById(string[]) as an extension which would serve me all data as a complete nodeset... ;)
I've been doing that on a couple of sites - basically I have a template for a single item (e.g.: match="Textpage"), and in the root ("/") template I fetch the content of the Multi Picker, tokenize the ids and apply templates to each one in succession; either via GetXmlNodeById() or if they're all below some specific node, by matching the id (e.g.: $newsRoot//Textpage[@id = current()])
<xsl:variable name="products" select="$currentPage/ancestor-or-self::*[@isDoc and @level = 1]/descendant-or-self::Product[@isDoc and contains($productIds, concat(@id, ','))]"/>
The variable productIds is just the CSV from the tree picker. Seems fast enough for now, but I've not tested with a huge amount of nodes in the currentPage.
Afterwards I apply a template to this nodeset matching product.
What do you think? Any drawbacks with this approach?
Nope - been doing that too - just gotta be careful with the commas - you get a trailing "," in the $productIds property (or do you put an extra in there when fetching it?)
I usually prepend a comma too though, to safeguard against the node with id="2345" not being matched when "12345" was actually picked...
Actually the productIds I tested with was created from the XML format of the tree picker so I added the comma at that point. I was also planning to edit the post and pinpoint exactly what you're writing about using a prepending comma as well since I'm aware of that easily made mistake with mismatches when you're exceeding 9999 nodes! ;)
Best practice getting data from Multi-Node Tree Picker
Assume I want to select e.g. 20 nodes from all-over the content tree using the Multi-Node Tree Picker or another tree picker able to save multiple values.
What would be the best way of getting the data from these nodes? Loop through the id's from the tree picker and then use GetXmlNodeById to retrieve the data for each node? Filter $currentPage using contains? Please note that I would prefer having one nodeset to work with for further sorting, filtering etc.
Surely the best would be to have a something like GetXmlNodesById(string[]) as an extension which would serve me all data as a complete nodeset... ;)
Hi Nikolas,
I've been doing that on a couple of sites - basically I have a template for a single item (e.g.: match="Textpage"), and in the root ("/") template I fetch the content of the Multi Picker, tokenize the ids and apply templates to each one in succession; either via GetXmlNodeById() or if they're all below some specific node, by matching the id (e.g.: $newsRoot//Textpage[@id = current()])
If this is too sketchy, let me know :-)
/Chriztian
Hi Chriztian,
I tried the following:
The variable productIds is just the CSV from the tree picker. Seems fast enough for now, but I've not tested with a huge amount of nodes in the currentPage.
Afterwards I apply a template to this nodeset matching product.
What do you think? Any drawbacks with this approach?
Nik
Hi Nik,
Nope - been doing that too - just gotta be careful with the commas - you get a trailing "," in the $productIds property (or do you put an extra in there when fetching it?)
I usually prepend a comma too though, to safeguard against the node with id="2345" not being matched when "12345" was actually picked...
/Chriztian
Hi Chriztian,
Thanks for your comments!
Actually the productIds I tested with was created from the XML format of the tree picker so I added the comma at that point. I was also planning to edit the post and pinpoint exactly what you're writing about using a prepending comma as well since I'm aware of that easily made mistake with mismatches when you're exceeding 9999 nodes! ;)
Nik
is working on a reply...