I'm trying to display some products within their product category on multiple levels. There is also a filter option, which allows you to only see products within a specific brand group. (No e-commerece! Just pure Umbraco).
In the explanation below I use 1 and 2 to tell, what document types that are used on the different levels. 1 = Products 2 = Product
However I'm having two issues I'm in doubt about how I'm adressing (Head is not working :-)).
If there is no products matching the filter I want these 2 things to happen
1) Show message "No products matches your query" displayed only once. 2) Make sure the headings for the categories not containing any products are not displayed.
Hmm, as this point I usually give up trying to cram the logic into xslt (before my brain implodes) and switch to a usercontrol. Sorry, not helpful at all :)
Thanks for the great confidence — I actually took a look at the code right when you posted, but then I saw the heavy use of CSV storage and decided "not today" :-)
4 days later, I'll try again: I don't believe that you can't figure #1 out yourself, so I'll give a little hint about #2 and then I'll take a second look at the code and come back with something later.
One of the big differences between C# and XSLT (from what I've experienced) is that when you're doing something like this, where you've got a set of objects/nodes that needs filtering, the C# version usually puts the filter inside, e.g.:
foreach (var d in docs) {
if (somefilterExpression == true) {
# Do something with d
}
}
whereas, the XSLT version puts the filter up front:
<xsl:for-each select="$docs[someFilterExpression]">
<!-- Do something with current() -->
</xsl:for-each>
<!-- or you could do a simple apply-templates and have separate output templates -->
<xsl:apply-templates select="$docs[someFilterExpression]" />
- You see? The xsl:if and xsl:choose constructs should largely be avoided for this kind of selection (IMO).
My suggestion regarding your second "problem" is, of course, to make sure that you filter the nodes from the start - then you'll have a simple way of testing for goal #1, and that your code will almost automatically take care of satisfying #2, too.
BUT: The thing that makes it hard to do in your code is all the comma-separated stuff, which isn't a good "data-type" for XSLT, so...
Thanks for the reply. I'm sure you're right about that I should be able to figure no. 1 out myself - at some point my brain just started to not function. Know the feeling? :-)
I'm looking forward to you getting back - In the meantime I think I have got an idea on how to solve this better thanks to your reply above.
Applying filtering options on product nodes
Hi All
I'm trying to display some products within their product category on multiple levels. There is also a filter option, which allows you to only see products within a specific brand group. (No e-commerece! Just pure Umbraco).
In the explanation below I use 1 and 2 to tell, what document types that are used on the different levels.
1 = Products
2 = Product
My structure within Umbraco is the following
Products (1)
Tables (1)
Meeting tables (1)
Table 1 (2)
Table 2 (2)
Sofa Tables (1)
Table 1 (2)
Table 2 (2)
Chairs (1)
Chair 1 (2)
Chair 2 (2)
Currently I have the following XSLT that is in fact working...
http://pastebin.com/6TLxkEEV
However I'm having two issues I'm in doubt about how I'm adressing (Head is not working :-)).
If there is no products matching the filter I want these 2 things to happen
1) Show message "No products matches your query" displayed only once.
2) Make sure the headings for the categories not containing any products are not displayed.
Any ideas are highly appreciated! :-)
Hmm, as this point I usually give up trying to cram the logic into xslt (before my brain implodes) and switch to a usercontrol. Sorry, not helpful at all :)
Haha, well...Unfortunately I'm no C# shark...that's why. But will wait and see if maybe Chriztian sees this later ;-)
/Jan
Hi Jan,
Thanks for the great confidence — I actually took a look at the code right when you posted, but then I saw the heavy use of CSV storage and decided "not today" :-)
4 days later, I'll try again: I don't believe that you can't figure #1 out yourself, so I'll give a little hint about #2 and then I'll take a second look at the code and come back with something later.
One of the big differences between C# and XSLT (from what I've experienced) is that when you're doing something like this, where you've got a set of objects/nodes that needs filtering, the C# version usually puts the filter inside, e.g.:
whereas, the XSLT version puts the filter up front:
- You see? The xsl:if and xsl:choose constructs should largely be avoided for this kind of selection (IMO).
My suggestion regarding your second "problem" is, of course, to make sure that you filter the nodes from the start - then you'll have a simple way of testing for goal #1, and that your code will almost automatically take care of satisfying #2, too.
BUT: The thing that makes it hard to do in your code is all the comma-separated stuff, which isn't a good "data-type" for XSLT, so...
"I'll be back",
/Chriztian
Hi Chriztian
Thanks for the reply. I'm sure you're right about that I should be able to figure no. 1 out myself - at some point my brain just started to not function. Know the feeling? :-)
I'm looking forward to you getting back - In the meantime I think I have got an idea on how to solve this better thanks to your reply above.
/Jan
is working on a reply...