Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I have a small problem with sorting prices ascending.
Product 1 costs € 15,00, product 2 costs 9,00 and product 3 costs 7,50. When sorting using xslt:sort this is the result:
- product 1- product 3- product 2
That is because 1 comes before 7 and 9
But in price, the order must be product 3 - product 2 - product 1.
How can I let XSLT know it is a price instead of a number?
Hi Ralph
What value do you have in your sort order? Does'nt it help to just set sort="ascending" ?
You can see the different options here: http://w3schools.com/xsl/el_sort.asp
/Jan
Hi Jan,
Unfortunately not. I've set the order to ascending, but it doesn't make a difference.
If I format the prices with two digits for the comma (such as 07,50) it sorts right, but when losing the '0' it sorts wrong.
Ralph
Jan,
Maybe I've found the answer here: http://www.w3schools.com/Xsl/func_formatnumber.asp
I'll try.
Thanks!
Ah yes I should had thought of that option myself. It makes sense I it really should solve your problem.
Found it. Check http://efreedom.com/Question/1-3758978/XSLT-Format-Number-Comma
<xsl:decimal-format name="nl" decimal-separator="," grouping-separator="."/>[...]<xsl:sort select="format-number(translate($price, ',','.'), '00,00', 'nl')" order="ascending" />
<xsl:decimal-format name="nl" decimal-separator="," grouping-separator="."/>
[...]
<xsl:sort select="format-number(translate($price, ',','.'), '00,00', 'nl')" order="ascending" />
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Sort order problem
I have a small problem with sorting prices ascending.
Product 1 costs € 15,00, product 2 costs 9,00 and product 3 costs 7,50. When sorting using xslt:sort this is the result:
- product 1
- product 3
- product 2
That is because 1 comes before 7 and 9
But in price, the order must be product 3 - product 2 - product 1.
How can I let XSLT know it is a price instead of a number?
Hi Ralph
What value do you have in your sort order? Does'nt it help to just set sort="ascending" ?
You can see the different options here: http://w3schools.com/xsl/el_sort.asp
/Jan
Hi Jan,
Unfortunately not. I've set the order to ascending, but it doesn't make a difference.
If I format the prices with two digits for the comma (such as 07,50) it sorts right, but when losing the '0' it sorts wrong.
Ralph
Jan,
Maybe I've found the answer here: http://www.w3schools.com/Xsl/func_formatnumber.asp
I'll try.
Thanks!
Ralph
Hi Ralph
Ah yes I should had thought of that option myself. It makes sense I it really should solve your problem.
/Jan
Hi Jan,
Found it. Check http://efreedom.com/Question/1-3758978/XSLT-Format-Number-Comma
is working on a reply...