I've done something similar using keys, which are perfect for this.
If you have a Product doctype with a categories property, which is an MNTP that allows the user to select one or more Category nodes, then you can do something like the following:
You're essentially creating an index of Product nodes that kan be queried by the @id of their associated categories, and when you render your Category page, you simply apply-templates to the products that are associated with that category.
Taking away all the pagination noise from your XSLT (I should know, I wrote it - LOL!), you essentially need to select the correct nodes for the "matchedNodes" variable:
<xsl:variable name="matchedNodes" select=" ... XPath for nodes with selected category ... " />
So, couple of questions... are you using XML as the data-format for your MNTP? For this, you should do - makes it much easier!
Now is this XSLT being ran on the category page itself? Meaning that the $currentPage/@id could be a value in the "selectedCategory"?
You could try this XPath:
<xsl:variable name="matchedNodes" select="$currentPage/descendant::*[@isDoc and selectCategories/MultiNodePicker/nodeId = $currentPage/@id]" />
Most likely need to play around with the XPath until it's right.
Ah, good point from Lee on ensuring that the MNTP saves data as XML -- that is also required for my key example. And I didn't think to add it, but my example also requires a template to actually output the Product data, e.g.:
The solution that Lee mentioned work fine for child pages of a category, but in this case the products are on the same level as the categories. Now I changed the xpath to (so only the nodes with the ProductDetail will be displayed):
<xsl:variable name="matchedNodes" select="$currentPage/descendant::ProductDetail[@isDoc and selectCategories/MultiNodePicker/nodeId = $currentPage/@id and @level = 4]" />
But this returns nothing, i'm now playing around with this xpath. I hope to get back with the solution soon. ( help is appreciated ;-) )
Thanks Dan for mentioning the technique with 'keys', I will definitely be using that in the near future.
If the categories and the product detail pages are on the same level, then the problem is the descendent:: axis, since you're looking for siblings rather than descendants.
Also, since ProductDetail is a doctype, then the [@isDoc] test is superfluous (the [@level] test might be as well, but that depends on your XML). So I'd think that this should work:
<xsl:variablename="matchedNodes"select="$currentPage/../ProductDetail[selectCategories/MultiNodePicker/nodeId = $currentPage/@id and @level = 4]"/>
Multiple-Node Tree Picker (uComponents) challenge
I want to use the MNTP to catagorize nodes/products, to accomplish this I want select a few category-nodes on every node/product.
On the categorie-pages I want to show the nodes which are relevant/selected for that page. I try to do the following thing in the xslt (with paging):
Please help me on this one.
No one?
I've done something similar using keys, which are perfect for this.
If you have a Product doctype with a categories property, which is an MNTP that allows the user to select one or more Category nodes, then you can do something like the following:
You're essentially creating an index of Product nodes that kan be queried by the @id of their associated categories, and when you render your Category page, you simply apply-templates to the products that are associated with that category.
I've tried your solution, but it doesn't worked for me. It returns no value.
Hi Niels,
Taking away all the pagination noise from your XSLT (I should know, I wrote it - LOL!), you essentially need to select the correct nodes for the "matchedNodes" variable:
So, couple of questions... are you using XML as the data-format for your MNTP? For this, you should do - makes it much easier!
Now is this XSLT being ran on the category page itself? Meaning that the $currentPage/@id could be a value in the "selectedCategory"?
You could try this XPath:
Most likely need to play around with the XPath until it's right.
Cheers, Lee.
Ah, good point from Lee on ensuring that the MNTP saves data as XML -- that is also required for my key example. And I didn't think to add it, but my example also requires a template to actually output the Product data, e.g.:
Hi Dan,
I usually use keys too - love 'em! So a good fit for Niels solution would be:
Cheers, Lee.
Hi Dan and Lee, Thanks for your reactions.
The solution that Lee mentioned work fine for child pages of a category, but in this case the products are on the same level as the categories. Now I changed the xpath to (so only the nodes with the ProductDetail will be displayed):
But this returns nothing, i'm now playing around with this xpath. I hope to get back with the solution soon. ( help is appreciated ;-) )
Thanks Dan for mentioning the technique with 'keys', I will definitely be using that in the near future.
If the categories and the product detail pages are on the same level, then the problem is the descendent:: axis, since you're looking for siblings rather than descendants.
Also, since ProductDetail is a doctype, then the [@isDoc] test is superfluous (the [@level] test might be as well, but that depends on your XML). So I'd think that this should work:
Sorry for not getting back to you sooner, but thanks a lot! You've made my day guys!
Thanks for the explaining, it helps me further to understand xslt and Umbraco.
is working on a reply...