Copied to clipboard

Flag this post as spam?

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


  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 03, 2012 @ 22:33
    Fuji Kusaka
    0

    Sort 2 Values

    Hi guys, i have the following tree Node and i would like to make a sorting depending on the docType and the number of count view.

    So the tree node looks like this

    - FOLDER
    -- Vids AB
      --Vids 3(count 10)
    --Vids 4(count 6)
    -- Vids BC
    -- Vids 2 (count 3)
    -- Vids BC
    -- Vids 1(count 12)

    Only the child nodes will be displayed here thought. I did try this but its not reflecting the right descending output which shoulb be

    Vids 1 (count 12)
    Vids 3 (count 10)
    Vids 4 (count 6)
    Vids 2 (count 3)

    <xsl:sort select="self::DocName| ViewCount:GetViews(number(@id))//@count" order="descending"  data-type="number"/>
     <xsl:sort select="self::TerraVideoLinks|@count" order="descending"  data-type="number"/>

    Both not working, 

    Any suggestion??

     

     

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jul 03, 2012 @ 23:54
    Chriztian Steinmeier
    0

    Hi Fuji,

    Are you not only sorting by count? (It looks like that to me but it may of course be because you've simplified the problem here).

    Anyways, how is the count stored? Is it a property on the documents or do you have to call that extension to get it?

    If you need to call the extension, this should work:

    <xsl:sort select="ViewCount:GetViews(@id)//@count" data-type="number" order="descending" />

    Could you post the XML you get from a call to ViewCount:GetViews(@id) ?

    /Chriztian

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 04, 2012 @ 06:59
    Fuji Kusaka
    0

    Hi Chriztian,

    Yes its a property in the document, and using the Refactored Content Views package to get the number of views a node has been viewed.

    Here i need to sort all child nodes displaying the most viewed one. Here is how my code looks like

    <xsl:if test="*[@isDoc][not(umbracoNaviHide = 1)]">            
             <xsl:for-each select="./* [@isDoc and string(umbracoNaviHide) !='1']">    
          <xsl:sort select="ViewCount:GetViews(@id)/@count" data-type="number" order="descending" />
               <xsl:variable name="counter" select="ViewCount:GetViews(number(@id))" />    
    <li>
               <href="{umbraco.library:NiceUrl(../@id)}"><xsl:value-of select="../@nodeName"/></a <br/>
               <small><xsl:value-of select="umbraco.library:FormatDateTime(../@createDate, 'dd MMMM yyyy')" /></small><br/>
               <small style="color:#000;">Number of views : <xsl:value-of select="$counter//@count" /></small>
                 <br/>   
                 <href="{umbraco.library:NiceUrl(../@id)}" class="rd">view more &#187; </a>
               </li>           
            </xsl:for-each>      
          </xsl:if>

    You will notice am displaying the parent name thought instead of the Child. Unfortunately the sorting is still not working. I also tried but without any success

    <xsl:sort select="ViewCount:GetViews(number(@id))//@count" order="descending"  data-type="number"  />
    


  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 04, 2012 @ 07:59
    Fuji Kusaka
    0

    Chriztian,

    Sorry the sorting is working but what i would like is sorting all child nodes depending on the Count regardless of the parent. Right now the sorting is working as such 

    - FOLDER
    -- Vids AB
     --Vids 3(count 10)
    --Vids 4(count 16)
    -- Vids BC
    -- Vids 2 (count 3)
          -- Vids 6(count 5)
    -- Vids BC
    -- Vids 1(count 12)

    Output right now when using  is 

    • Vids 4 (count 16)
    • Vids 3 (count 10)
    • Vids 6 (count 5)
    • Vids 2 (count 3)
    • Vids 1 (count 12)
     <xsl:sort select="ViewCount:GetViews(@id)//@count" order="descending"  data-type="number" />

    Expected output

    • Vids 4 (count 16)
    • Vids 1 (count 12)
    • Vids 3 (count 10)
    • Vids 6 (count 5)
    • Vids 2 (count 3)
  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 04, 2012 @ 20:12
    Fuji Kusaka
    0

    Any suggestions on this please?? Getting the impression that this is not possible because of each Parent Node. Am i right on this or is there a way od achiving the sorting?

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jul 04, 2012 @ 23:43
    Chriztian Steinmeier
    1

    Hi Fuji,

    I'm certain it's possible - but I guess I still just don't really understand the problem...

    Please try this, and post the results so I can get an idea about what's happening (change the stuff I've highlighted in bold):

       <xsl:variable name="folder" select="/SELECT/FOLDER/HERE" />
    
        <xsl:template match="/">
            <xsl:for-each select="$folder//VIDS_DOCTYPE_ALIAS[not(umbracoNaviHide = 1)]">
                <xsl:sort select="ViewCount:GetViews(@id)//@count" data-type="number" order="descending" />
    
                <h2>
                    <xsl:value-of select="@nodeName" />
                </h2>
                <p>
                    <textarea cols="50" rows="8">
                        <xsl:copy-of select="ViewCount:GetViews(@id)" />
                    </textarea>
                </p>
    
            </xsl:for-each>
        </xsl:template>
    

    /Chriztian

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 05, 2012 @ 07:09
    Fuji Kusaka
    0

    Hi Chriztian,

    Thanks for the help. I guess you changed the way i see xslt again!! My error was in my loop, changing it so check all DocType made it easier.

    My previous code 

    <xsl:for-each select="umbraco.library:GetXmlNodeById($List)/* [@isDoc][not(umbracoNaviHide != '1')]">
    <xsl:if test="*[@isDoc] [not(umbracoNaviHide != '1')] ">             
             <xsl:for-each select="./* [@isDoc ][not(umbracoNaviHide) !='1']">   
    <xsl:sort select="ViewCount:GetViews(@id)//@count" order="descending"  data-type="number" />
               <xsl:variable name="counter" select="ViewCount:GetViews(number(@id))" /> 
                <xsl:value-of select="../@nodeName" />     
    <xsl:value-of select="$counter//@count" /> 
     </xsl:for-each>        
          </xsl:if> 
    </xsl:for-each>  

    Working one

    <xsl:variable name="folder" select="umbraco.library:GetXmlNodeById($List)" />  
    <xsl:for-each select="$folder//DocTypeAlias[not(umbracoNaviHide != '1')]">
    ......
     </xsl:for-each>

    Thanks for the help 
    //Fuji 

Please Sign in or register to post replies

Write your reply to:

Draft