Copied to clipboard

Flag this post as spam?

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


  • Claushingebjerg 939 posts 2574 karma points
    Jul 31, 2013 @ 13:30
    Claushingebjerg
    0

    Sorting in xslt

    When using your example i get some strange sorting. It seems to only sort on the first character in the count number.

    Example: a page with 7 views is sorted higher than one with 43 views.

    Im sorting like this

    <xsl:sort select="ViewCount:GetViews(number(@id), 'uboldcounter')//@count" order="descending"/>

    Am i doing something wrong or is it by design. If so how do i get it sorted correctly.

  • Claushingebjerg 939 posts 2574 karma points
    Jul 31, 2013 @ 13:34
    Claushingebjerg
    100

    Fixed it by doing

    <xsl:sort select="format-number(ViewCount:GetViews(number(@id), 'uboldcounter')//@count, '0000')" order="descending"/>
  • Robert Foster 459 posts 1820 karma points MVP 3x admin c-trib
    Jul 31, 2013 @ 13:37
    Robert Foster
    0

    It's most likely because the returned count is treated as text  (it's an attribute on an XML node, so XSLT is unlikely to know that it's a number unless you tell it).

    If you were to wrap the select statement in number(..) how does that affect the sort?

    i.e. change

    ViewCount:GetViews(number(@id), 'uboldcounter')//@count

    to

    number(ViewCount:GetViews(number(@id), 'uboldcounter')//@count)

     

  • Robert Foster 459 posts 1820 karma points MVP 3x admin c-trib
    Jul 31, 2013 @ 13:38
    Robert Foster
    0

    lol too quick with the response :)

     

Please Sign in or register to post replies

Write your reply to:

Draft