Copied to clipboard

Flag this post as spam?

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


  • Jan Fosgerau 65 posts 89 karma points
    Jun 29, 2010 @ 12:43
    Jan Fosgerau
    0

    Got pictures with a value - wanna sort them by their value

    Hello

     

    i have a page that contains some pictures. these pictures need to be posted in a specific order

    each picture has a Value <votes> and i wish to sort them from highest <votes> to lowest.

    i tried fiddling alittle - but im terrible with xsl.

    here is my code so far

    <xsl:for-each select="umbraco.library:GetXmlNodeById(1332)/node [string(data [@alias='umbracoNaviHide']) != '1']">
        <xsl:if test="data[@alias='pollpicture'] != ''">
             
        <!-- get the media XML and assign it to a variable -->
        <xsl:variable name="media" select="umbraco.library:GetMedia(number(data[@alias='pollpicture']), 0)" />                                                  
        <!-- check if the media XML contains an image path 'umbracoFile' -->
            <xsl:if test="count($media/data[@alias='umbracoFile']) &gt; 0">
                      <div style="width:30px; padding-top:5px;">

                      <img style="width:30px;" src="{$media/data[@alias='umbracoFile']}" />

                      </div>              
            </xsl:if>
        </xsl:if>
    </xsl:for-each>

     

    they all have a value "votes" which they need to be sorted too.
    any suggestions would be helpfull

  • Rich Green 2246 posts 4008 karma points
    Jun 29, 2010 @ 12:49
    Rich Green
    1

    Hi Jan,

    You can use the XSLT sort method to order your results by Vote.

    The link below has a simple example of sorting using XSLT with umbraco.

    http://en.wikibooks.org/wiki/Umbraco/Various_useful_XSLT_methods_in_Umbraco

    Best of luck

    Rich

  • Jan Fosgerau 65 posts 89 karma points
    Jun 29, 2010 @ 13:10
    Jan Fosgerau
    0

    hm that did something but it messes it up -

    The type im using is numeric.

    if i type in the votes as such

    4
    3
    2
    1
    it shows everything like i want it. the highest value in the top.
    but when i tried it like such

    4
    3
    1
    11

    it put my highest value in the bottom? this is what i wrote out


            <xsl:sort select="data [@alias = 'votes']" order="descending"/>

    is there a way to make it sort it by highest numerial value ? right now it seems like its sorting them with what it begins with.



     

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Jun 29, 2010 @ 13:19
    Peter Dijksterhuis
    1

    Hi,

    use this:

    <xsl:sort select="data [@alias = 'votes']" data-type="number" order="descending"/>

    HTH,

    Peter

  • Jan Fosgerau 65 posts 89 karma points
    Jun 29, 2010 @ 13:39
    Jan Fosgerau
    0

    yeh just tried that one - but problem with identical votes persists.

    i got a user control that posts a poll with the values.

    the pictures are placed in a macro beside these polls. and what im trying to do is to match them in position.

    but when the values are identical now - the pictures (with identical votes) get posted in a wrong order compared to the poll next to it - thats also sorted by highest value first?. unsure if there are other things its sorting by - can i add more sorting options ? - so it sorts by value primarily - and secondarily name? nodeid? etc etc ?

    getting close to a solution :D j

  • Rich Green 2246 posts 4008 karma points
    Jun 29, 2010 @ 13:56
    Rich Green
    1

    You can add multiple XSLT sort values to get what you need :)

    http://www.programmersheaven.com/2/FAQ-XML-Sort-XML-By-Multiple-Attributes-XSLT

    Rich

  • Jan Fosgerau 65 posts 89 karma points
    Jun 30, 2010 @ 09:11
    Jan Fosgerau
    0

    how do i sort values from a usercontrol ?

  • 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