Copied to clipboard

Flag this post as spam?

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


  • Connie DeCinko 931 posts 1160 karma points
    Jul 13, 2012 @ 20:09
    Connie DeCinko
    0

    Sort Reapeatable Custom Content

    I am using a Repeatable Custom Content v2 control, displaying the results via XSLT. I need to know if there is a way to sort via one of the properties of the control. The property is a full name, so I would also need to sort by the last word, then the first word, then any second or third word.

     

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jul 25, 2012 @ 01:15
    Chriztian Steinmeier
    0

    Hi Connie,

    A simple example: If your property is named "people", you could have something like this:

    <people>
        <items>
            <item>
                <data alias="FullName">Jamie Jamieson</data>
                <data alias="ShoeSize">43</data>
            </item>
            <item>
                <data alias="FullName">Jamie Anderson Lee</data>
                <data alias="ShoeSize">45</data>
            </item>
            <item>
                <data alias="FullName">John James Anderson-Lee</data>
                <data alias="ShoeSize">41</data>
            </item>
            <item>
                <data alias="FullName">John Andersen</data>
                <data alias="ShoeSize">42</data>
            </item>
            <item>
                <data alias="FullName">John Peter Anderson</data>
                <data alias="ShoeSize">43</data>
            </item>
        </items>
    </people>
    

    Then this XSLT would take care of sorting by lastname then firstname:

    <xsl:template match="/">
        <xsl:apply-templates select="$currentPage/people" />
    </xsl:template>
    
    <xsl:template match="people">
        <xsl:apply-templates select="items/item">
            <xsl:sort select="substring-after(data[@alias = 'FullName'], ' ')" data-type="text" order="ascending" />
            <xsl:sort select="substring-before(data[@alias = 'FullName'], ' ')" data-type="text" order="ascending" />
        </xsl:apply-templates>
    </xsl:template>
    
    <!-- Display template for a single item -->
    <xsl:template match="item">
        <h2><xsl:value-of select="data[@alias = 'FullName']" /></h2>
        <p>
            Shoe size: <xsl:value-of select="data[@alias = 'ShoeSize']" />
        </p>
    </xsl:template>
    

    Hopefully, you'll be able to complete the puzzle - otherwise, let us know!

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft