Copied to clipboard

Flag this post as spam?

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


  • Stefan 117 posts 215 karma points
    Sep 16, 2013 @ 23:38
    Stefan
    0

    Sort nodes properly (not like 1, 10, 2, 3, 33, 4 etc)

    I'm using the great greystate XSLT helper (paginationhelper) (from a branch that allows for sorting), but I just noticed that the nodes are not sorted properly. I don't know if this is just how xslt behaves, or if its a bug in the helper.

    As far as I remember I have not made any changes that could have impacted this functionality (or if it ever has worked as expected...).

    This is the order of which I expect the nodes to appear: Text-10 Text-15 Text-25 ...

    And this is the order of which they are rendered: Text-10 Text-100 Text-125 Text-15 Text-150 Text-200 Text-25 ... and you get the point.

    This is how the pagination template is called:

    <xsl:call-template name="PaginateSelection">
        <xsl:with-param name="selection" select="$paginationSelection" />
        <xsl:with-param name="sortBy" select="'@nodeName ASC'" />
        <xsl:with-param name="showPager" select="false()" />
        <xsl:with-param name="perPage" select="$PerPage" />
        <xsl:with-param name="pageLinksBeside" select="$PageLinksBeside" />
    </xsl:call-template>
    

    Please let me know if you want a copy of the XML. But it should not be necessary since I'm just sorting on the @nodeName attribute.

    Thanks.

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Sep 17, 2013 @ 01:10
    Chriztian Steinmeier
    0

    Hi Stefan,

    Yeah that's a little tricky - and let me just explain why: XSLT can sort either as text or number - your nodes will need to sort in two steps, first by the part before the dash, as text; then by the part after the dash, as number. So with a normal apply-templates or for-each, you'd do something like this:

    <xsl:for-each select="$nodes">
        <xsl:sort select="substring-before(@nodeName, '-')" data-type="text" order="ascending" />
        <xsl:sort select="substring-after(@nodeName, '-')" data-type="number" order="ascending" />
        <!-- ... -->
    </xsl:for-each>
    

    The way I've implemented sorting in the helper is limited to full properties/attributes, and only a single sort is supported. So basically, we'll need to customize your helper file to accomplish this, or...

    The way I'd recommend would be to use the word $CUSTOM (or similar) in the sortBy parameter to trigger this, and then branch off in the preSort template and do the two sort statements - that way, you'll still have all the other features of the helper available.

    I'll try a few things and might push a solution for this soon, provided I can get it working reasonably quick...

    I've added a feature-request here: https://github.com/greystate/Greystate-XSLT-Helpers/issues/18

    /Chriztian

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Sep 17, 2013 @ 08:41
    Chriztian Steinmeier
    0

    Update: There's a new version of Pagination Helper available here that implements this — see the section in the README about how it works.

    /Chriztian

  • Stefan 117 posts 215 karma points
    Sep 17, 2013 @ 19:25
    Stefan
    0

    Thank you very much for your nice explanation - and even more for the implementation! That was not something I would have expected ;)

    But I'm sure that I'm not the only one finding the new extension useful.

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Sep 17, 2013 @ 21:17
    Chriztian Steinmeier
    0

    Hi Stefan,

    You're welcome - I've wanted to implement more advanced sorting for a while, but didn't really have any use cases or ideas as to how to do it — but describing the problem for you, trying to keep changes to the existing helper to a minimum, suddenly made me realize how to actually do it, so thanks for that, I guess :-)

    /Chriztian

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies