- Products (node id 2878) ---product ---product ---product
The product document type has properties which say which categories the product belongs to. These are done using a content picker so the user can just select the categories applicable. I am having some problems writing the XSLT.
On the category page I need to have a products listing. This was easy enough but on the category page I want the products that are in the sub categories to show too. So if I am on "categoryone" page I want to show the products that are in the category plus the ones in the sub categories.
I have tried to use descendant or self but I can't get it to work. Here is my code:
I've had the same challenge in a project. I solved it by making an variable containing all the wanted categorie IDs sepereated by komma - and then used contains in my xpath.
I'm not totally sure how your categoryOne property works - is it a plain Content Picker (so only a single category can be picked) or is it maybe a Multi-Node Tree Picker for selecting multiple categories?
I'm guessing it's a Content Picker, so you should be able to do it like this:
<!-- Grab all product nodes -->
<xsl:variable name="products" select="umbraco.library:GetXmlNodeById(2878)//product" />
<!-- Select product nodes where the productOne property points to the current category or one of its descendants -->
<xsl:for-each select="$products[categoryOne = $currentPage/descendant-or-self::category/@id]">
...
</xsl:for-each>
(This assumes that the category + subcategory nodes have the alias category - but you can of course change that very easily)
Using descendant or self
Hi,
I have created a little product listing in Umbraco, my node structure is like this...
- Categories
---category_one
-----sub_category
-----sub_category
---category_two
---category_three
- Products (node id 2878)
---product
---product
---product
The product document type has properties which say which categories the product belongs to. These are done using a content picker so the user can just select the categories applicable. I am having some problems writing the XSLT.
On the category page I need to have a products listing. This was easy enough but on the category page I want the products that are in the sub categories to show too. So if I am on "categoryone" page I want to show the products that are in the category plus the ones in the sub categories.
I have tried to use descendant or self but I can't get it to work. Here is my code:
<xsl:for-each select="umbraco.library:GetXmlNodeById(2878)/descendant-or-self::product [$currentPage/descendant-or-self::category [@id = categoryOne]]">
Could anyone point me in the right direction please?
Thanks in advance
Hi Dave,
I've had the same challenge in a project. I solved it by making an variable containing all the wanted categorie IDs sepereated by komma - and then used contains in my xpath.
It goes something like this:
*I assume categoryOne is your category-property on your product? :)
Hope this helps.
-Kim
Hi Kim
Thanks for the suggestion, I think that could do the trick :-)
Thanks again!
You're welcome :)
Hi Dave,
I'm not totally sure how your categoryOne property works - is it a plain Content Picker (so only a single category can be picked) or is it maybe a Multi-Node Tree Picker for selecting multiple categories?
I'm guessing it's a Content Picker, so you should be able to do it like this:
(This assumes that the category + subcategory nodes have the alias category - but you can of course change that very easily)
/Chriztian
Thank you Kim and Chriztian - both of those methods worked for me
is working on a reply...