Copied to clipboard

Flag this post as spam?

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


  • Chad 68 posts 133 karma points c-trib
    Sep 17, 2009 @ 15:11
    Chad
    0

    Conditional xsl:sort

    What I'm trying to accomplish

    <var name="sortOrder" />

    <xsl:for-each>

        <choose>

            <when $sortOrder = 'something'>

                <xsl:sort select=$sortOrder />

            </when>

            <otherwise>

                <xsl:sort select='defaultVal' />

            </otherwise>

        </choose>

    </xsl:foreach>

     

    Sorry I've no idea on how to format code in this forum.. :/

  • Richard Soeteman 4054 posts 12927 karma points MVP 2x
    Sep 17, 2009 @ 15:31
    Richard Soeteman
    0

    In the old CWS package from Warren, he build something like this

    <xsl:variable name="SortOrder" select="$currentPage/data [@alias = 'SortOrder']" /> 
    <xsl:variable name="SortBy" select="$currentPage/data [@alias = 'SortBy']" />

    Then he did some magic to determine the datatype

    <!-- We need to set data-type to number or text depending on what sortby equals -->
    <xsl:variable name="DataType"> 
    <xsl:choose> 
    <xsl:when test="$SortBy='sortOrder'"> 
    <xsl:value-of select="'number'" /> 
    </xsl:when> 
    <xsl:otherwise> 
    <xsl:value-of select="'text'" /> 
    </xsl:otherwise> 
    </xsl:choose> 
    </xsl:variable>
    And finally the FOr each with conditional sort
    <xsl:for-each>
     <xsl:sort select="@*[name() = $SortBy]" order="{$SortOrder}" data-type="{$DataType}"/>
    </ssl:for-each>

    Hope this helps you,

    Richard

     

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Sep 17, 2009 @ 15:33
    Warren Buckley
    0

    Hello Chad to format code use the style dropdown box in the editor (where is says paragraph by deafult - hilight code and change to code)

    <xsl:variable name="sortOrderQuerystring" select="umbraco.library:RequestQueryString('sortOrder')"/>

    <xsl:variable name="sortOrder">
    <xsl:choose>
    <xsl:when test="$sortOrderQuerystring = 'asc'">
    <xsl:text>ascending</xsl:text>
    </xsl:when>
    <xsl:otherwise>
    <xsl:text>descending</xsl:text>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    <xsl:for-each select="you XPATH here">
    <xsl:sort select="@nodeName" order="$sortOrder"/>

    <!-- Your for each loop here -->
    </xsl:for each>

     

  • Chad 68 posts 133 karma points c-trib
    Sep 17, 2009 @ 16:30
    Chad
    0

    Still not having much luck here..

    <xsl:sort select="@*[name() = $SortBy]" />

    This is basically what im after, I want to sort by @nodeName by default, but if there's a querystring present, then I want it to sort by:

    <xsl:sort select="./data [@alias = 'colourCode']" />

    Having:

    <xsl:sort select="@*[name() = 'colourCode]" 

    For instance... no dice :/

  • Jonas Høiby 62 posts 53 karma points
    Oct 12, 2009 @ 15:09
    Jonas Høiby
    0

    im having the same issues .. :-/

  • Jonas Høiby 62 posts 53 karma points
    Oct 12, 2009 @ 16:00
    Jonas Høiby
    0

    except im getting my data from SQL database with an XSLT extension ... and i need to sort it by querystring parameter .. :-/ ..

     

    thinking it might be smarter to sort it in the SQL query ...?

  • 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