Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ralph van Vugt 57 posts 101 karma points
    Jan 03, 2011 @ 09:12
    Ralph van Vugt
    0

    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? 

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 03, 2011 @ 09:17
    Jan Skovgaard
    0

    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

  • Ralph van Vugt 57 posts 101 karma points
    Jan 03, 2011 @ 09:33
    Ralph van Vugt
    0

    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 

  • Ralph van Vugt 57 posts 101 karma points
    Jan 03, 2011 @ 09:34
    Ralph van Vugt
    1

    Jan,

    Maybe I've found the answer here: http://www.w3schools.com/Xsl/func_formatnumber.asp

    I'll try.

    Thanks!

    Ralph

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 03, 2011 @ 10:07
    Jan Skovgaard
    0

    Hi Ralph

    Ah yes I should had thought of that option myself. It makes sense I it really should solve your problem.

    /Jan

  • Ralph van Vugt 57 posts 101 karma points
    Jan 03, 2011 @ 10:18
    Ralph van Vugt
    0

    Hi Jan,

    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" />

Please Sign in or register to post replies

Write your reply to:

Draft