Copied to clipboard

Flag this post as spam?

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


  • syn-rg 282 posts 425 karma points
    Mar 02, 2011 @ 07:07
    syn-rg
    0

    Alphabetical sort by second word in the node name

    I've created a list displaying child nodes and wondered if it were possible to sort the list alphabetically by the second word in the node name?

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

    Hi JV

    Hmm, that's a good question...I guess it should be possible to do a substring on the string you want the nodes to be sorted by and then instruct it to start by the 2. character....like this

    <xsl:sort select="substring(title,2)" />

    This will make it start from the 2. character. Have a look at this reference if in doubt http://zvon.org/xxl/XSLTreference/Output/function_substring.html

    I'm a bit unsure if you can use it directly in the select of sort...perhaps you need to assign it to a variable and use that in the sort select...

    Hope this helps.

    /Jan

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Mar 02, 2011 @ 08:50
    Chriztian Steinmeier
    1

    Hi JV,

    You can do that with the substring-after() function:

    <xsl:sort select="substring-after(@nodeName, ' ')" data-type="text" order="ascending" />

    and you can even add a second sort instruction to subsequently sort by the first word, if desired:

    <xsl:sort select="substring-after(@nodeName, ' ')" data-type="text" order="ascending" />
    <xsl:sort select="substring-before(@nodeName, ' ')" data-type="text" order="ascending" />

     

    /Chriztian

  • syn-rg 282 posts 425 karma points
    Mar 02, 2011 @ 23:21
    syn-rg
    0

    Thanks Chriztian!

    That's a very handy piece of code, especially in my case as I am sorting a list of staff members by surname.

Please Sign in or register to post replies

Write your reply to:

Draft