Hi Tom, thanks for answering. I've been testing the sample you sent me, but I do not work yet. Can you help some more? to see if I can solve this problem, I'm not very expert in Umbraco XSLT
Try removing the xsl:choose and xsl:when statements and just list the sort statements - if you look at the gist I linked it's not using them. It's deciding which statements to use via the predicates ($createDate [$page = 'desc']) - if $page = asc this statement will be ignored. At least I'm pretty sure that's how it works :)
The main reason your code won't work is because xsl:sort is only allowed inside xsl:for-each and xsl:apply-templates - but there's another very tricky problem which you can stare at all day long until you suddenly see it:
You need to know that a select attribute always takes an XPath expression, so what your $page variable is actually set to is the value of a <byNameAsc> element in a context you can't even get access to – you just want it to be a string, so you need to put some single-quotes around it:
<xsl:variable name="page" select="'byNameAsc'" />
With that out of the way, rewrite th rest to something like this:
Yupiii! Thank you very much friends, the code has worked for me perfectly, I am eternally grateful to you both for your time and ezfuerso. A Tom and Chriztian a hug.
Before this I would like to clarify that static works very well:
<xsl:variable name="page" select="'byNameAsc'"/>
But if you want the value of $ page, a dynamic Through of the url ex:
Problems to sort in xslt
Hello friends
I'm having trouble sorting a list of products, which are sorted in ascending, descending, by date, most recent, etc ... I'm trying to do this,
but I get an error.
Help please!.Thank you!
Hi,
Check out this gist from Chriztian, think it does exactly what you need (just change @createDate to @nodeName).
-Tom
Hi Tom, thanks for answering. I've been testing the sample you sent me, but I do not work yet. Can you help some more? to see if I can solve this problem, I'm not very expert in Umbraco XSLT
This is what I have:
Hi,
Try removing the xsl:choose and xsl:when statements and just list the sort statements - if you look at the gist I linked it's not using them. It's deciding which statements to use via the predicates ($createDate [$page = 'desc']) - if $page = asc this statement will be ignored. At least I'm pretty sure that's how it works :)
-Tom
Hi umbracocool,
The main reason your code won't work is because xsl:sort is only allowed inside xsl:for-each and xsl:apply-templates - but there's another very tricky problem which you can stare at all day long until you suddenly see it:
You need to know that a select attribute always takes an XPath expression, so what your $page variable is actually set to is the value of a <byNameAsc> element in a context you can't even get access to – you just want it to be a string, so you need to put some single-quotes around it:
With that out of the way, rewrite th rest to something like this:
(data-type defaults to "text" so I removed it to reduce clutter)
/Chriztian
- and Tom: You're right about how it works :)
Yupiii! Thank you very much friends, the code has worked for me perfectly, I am eternally grateful to you both for your time and ezfuerso. A Tom and Chriztian a hug.
Before this I would like to clarify that static works very well:
But if you want the value of $ page, a dynamic Through of the url ex:
http://mysite.com.do/?order=desc
This would be the best solution:
My final code is this:
Thank you both! I served very helpful! :)
is working on a reply...