Copied to clipboard

Flag this post as spam?

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


  • Andres Cano 22 posts 42 karma points
    Apr 08, 2011 @ 16:36
    Andres Cano
    0

    Cant Short using Sort Function

    Hi Everyone, im new to the forum, i like umbraco a lot, and im trying to use it in every single proyect that i have

    Now, i have a big question about what is the best way to aproach sort functions using xslt

    i have a front page where all the info for birthdays in my intranet is showed with name, month and day, but i just can find a way to sort the output of the macro in my frontpage.

    this is the code of the xlst.

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet 
      version="1.0" 
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
      xmlns:msxml="urn:schemas-microsoft-com:xslt" 
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" 
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">

    <xsl:output method="xml" omit-xml-declaration="no"/>

    <xsl:param name="currentPage"/>

    <!-- update this variable on how deep your site map should be -->
    <xsl:variable name="maxLevelForSitemap" select="6"/>
        
    <xsl:template match="/">
    <xsl:call-template name="drawNodes">  
      <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::* [@isDoc and @level=1]"/>
      
    </xsl:call-template>  
    </xsl:template>
        
       
        
    <xsl:template name="drawNodes">
    <xsl:param name="parent"/> 
      <xsl:if test="umbraco.library:IsProtected($parent/@id, $parent/@path) = 0 or (umbraco.library:IsProtected($parent/@id, $parent/@path) = 1 and umbraco.library:IsLoggedOn() = 1)">
        <xsl:for-each select="$parent/*[@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevelForSitemap]"
          
          <!--<xsl:value-of select="name(./*[@isDoc])"/><br/>-->
          
          <xsl:sort select="birthdayEY" order="descending"/>
          
          <xsl:if test="@template = 1165"<!-- Fix to all folders with template id -->
            
            
            <xsl:variable name="DateToday" select="umbraco.library:CurrentDate()"/>
            
            <xsl:if test="umbraco.library:FormatDateTime($DateToday, 'MMMM') = umbraco.library:FormatDateTime(birthdayEY, 'MMMM') ">

            <tr>
            <td>  
              <span style="color:#747170"<xsl:value-of select="nameEY"/></span>
            </td>
            <td>  
               <xsl:value-of select="umbraco.library:FormatDateTime(birthdayEY, 'MMMM d')"/>
            </td>
            </tr>
            
            </xsl:if>
          
          </xsl:if
          
     
          <xsl:if test="count(./* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevelForSitemap]) &gt; 0">   

            <xsl:call-template name="drawNodes">    
              <xsl:with-param name="parent" select="."/>    
            </xsl:call-template>
            
          </xsl:if

        </xsl:for-each>

      </xsl:if>
    </xsl:template>    
        
    </xsl:stylesheet>

     

    and this is a picture of the output content in the front page

    any ideas? thanks a lot for help i really need it!

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Apr 08, 2011 @ 17:36
    Michael Latouche
    0

    Hi Andres,

    My guess is that you get it sorted, but per level or something like that. If you want a full list, I think you need to get all nodes at once in you first for each. Try something like this:

    <xsl:template name="drawNodes">
    <xsl:param name="parent"/>
      <xsl:if test="umbraco.library:IsProtected($parent/@id, $parent/@path) = 0 or (umbraco.library:IsProtected($parent/@id, $parent/@path) = 1 and umbraco.library:IsLoggedOn() = 1)">
        <xsl:for-each select="$parent//*[@isDoc and string(umbracoNaviHide) != '1' and @level <= $maxLevelForSitemap]"> 
     

    Notice that I have put a // after $parent, this should look through the whole hierarchy under $parent. Also, if you are only interested in a specific template Id, you might want to filter there too

    If you do like this, your recursive call to drawnodes at the end can be removed also.

    Hope this helps!

    Cheers,

    Michael.

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Apr 08, 2011 @ 17:42
    Michael Latouche
    0

    Maybe to make it more clear, this is the full XSL I would try:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">

    <xsl:output method="xml" omit-xml-declaration="no"/>

    <xsl:param name="currentPage"/>

    <!-- update this variable on how deep your site map should be -->
    <xsl:variable name="maxLevelForSitemap" select="6"/>
       
    <xsl:template match="/">
    <xsl:call-template name="drawNodes">  
      <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::* [@isDoc and @level=1]"/>
     
    </xsl:call-template>  
    </xsl:template>
       


    <xsl:template name="drawNodes">
    <xsl:param name="parent"/>
    <xsl:variable name="DateToday" select="umbraco.library:CurrentDate()"/>
     
    <xsl:if test="umbraco.library:IsProtected($parent/@id, $parent/@path) = 0 or (umbraco.library:IsProtected($parent/@id, $parent/@path) = 1 and umbraco.library:IsLoggedOn() = 1)">
        <xsl:for-each select="$parent//*[@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevelForSitemap and @template = 1165]">    
          <!--<xsl:value-of select="name(./*[@isDoc])"/><br/>-->      
          <xsl:sort select="birthdayEY" order="descending"/>
                 
            <xsl:if test="umbraco.library:FormatDateTime($DateToday, 'MMMM') = umbraco.library:FormatDateTime(birthdayEY, 'MMMM') ">

            <tr>
            <td>  
              <span style="color:#747170"> <xsl:value-of select="nameEY"/></span>
            </td>
            <td>  
               <xsl:value-of select="umbraco.library:FormatDateTime(birthdayEY, 'MMMM d')"/>
            </td>
            </tr>
           
            </xsl:if>
           
        </xsl:for-each>

      </xsl:if>
    </xsl:template>    
       
    </xsl:stylesheet>

    Cheers,

    Michael

  • Andres Cano 22 posts 42 karma points
    Apr 08, 2011 @ 19:27
    Andres Cano
    0

    Hi Michael thanks for your comment, i follow your instructions, thanks for the tip, i accidentally open this twice and Daniel help me to find the solution, i let here the link just in case.

    http://our.umbraco.org/forum/developers/xslt/19292-Can't-Sort-Content-Using-Xslt

    Thanks & Have a Good Day Michael!

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Apr 09, 2011 @ 00:32
    Michael Latouche
    0

    You're very welcome :-)

    Good to hear you sorted it out!

    Have a nice week-end

    Cheers,

    Michael.

Please Sign in or register to post replies

Write your reply to:

Draft