Copied to clipboard

Flag this post as spam?

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


  • mfeola 117 posts 221 karma points
    Oct 27, 2010 @ 21:18
    mfeola
    0

    Get Nodes sorted by property in for-each loop

    I am having an issue with the XSLT properties selection in the latest download of umbraco

    here is my code:

    <xsl:param name="currentPage"/>
    <xsl:param name="root" select="$currentPage/ancestor-or-self::* [@level = '1']"/>
        
    <xsl:template match="/">
      
    <ul>
      <xsl:for-each select="$root//*[self::NewsPage and string(umbracoNaviHide) != '1']">
        <xsl:sort select="data[@alias = 'date']" order="descending"/>
        <xsl:if test="position() &lt; 10">
          <li>
            <a href="{umbraco.library:NiceUrl(@id)}">
              <xsl:value-of select="@nodeName"/>
              <xsl:value-of select="data[@alias = 'date']"/>
              <xsl:value-of select="title"/>
            </a>
          </li>
        </xsl:if>
      </xsl:for-each
    </ul>

    </xsl:template>

    @nodeName displays fine but date and title do not display at all, as if they were empty but they aren't. I want to sort by the date field specifically and I tried the old way and the new way and neither seem to be working.  Does anyone have any experience with the same issue?

  • mfeola 117 posts 221 karma points
    Oct 27, 2010 @ 21:25
    mfeola
    0

    The code should get the latest NewPage documenttype in any folder and place it in a list. The latest item will be decided by the date field rather than @createDate because i had to import all these files so all the files are displayed by an arbitrary date of some time last week.  

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Oct 27, 2010 @ 21:33
    Chriztian Steinmeier
    0

    Hi mfeola,

    Try this:

    <xsl:param name="currentPage" />
    <xsl:param name="root" select="$currentPage/ancestor-or-self::*[@level = '1']" />
    
    <xsl:template match="/">
    <ul>
      <xsl:for-each select="$root//NewsPage[not(umbracoNaviHide = 1)]">
        <xsl:sort select="date" order="descending" />
        <xsl:if test="position() &lt; 10">
          <li>
            <a href="{umbraco.library:NiceUrl(@id)}">
              <xsl:value-of select="@nodeName" /> 
              <xsl:value-of select="date" /> 
              <xsl:value-of select="pageTitle" /> 
            </a>
          </li>
        </xsl:if>
      </xsl:for-each>  
    </ul>
    
    </xsl:template>

    The data[@alias = 'PROPERTY_ALIAS'] was the old way of doing it.

    /Chriztian

  • mfeola 117 posts 221 karma points
    Oct 27, 2010 @ 21:36
    mfeola
    0

    No change to the content and i am double checking to make sure the document type has a date and title property and it does.  It's weird because I did other XSLTs before but they requested information from the currentnode and they had no issues.

  • mfeola 117 posts 221 karma points
    Nov 03, 2010 @ 22:16
    mfeola
    0

    bah, i went ahead and just created a c# user control instead

    i added the date and id to a datatable, sorted that, and displayed that information.  it that works fine.

  • Paul Blair 466 posts 731 karma points
    Nov 03, 2010 @ 23:10
    Paul Blair
    0

    You could try

    <xsl:value-of select="./date" /> 

    or

     

    <xsl:value-of select="current()/date" /> 

    failing that have a look at your /app_data/umbraco.config file to see how the values were stored

  • mfeola 117 posts 221 karma points
    Nov 04, 2010 @ 19:17
    mfeola
    0

    i didnt know current was a function.  i might try that in a future item and see if it works but for now i just did the datatable thing.  i wish there was another way to mark this forum post as something other than solved... like not solvable or no longer an issue so i will just mark the last message as the solved one

Please Sign in or register to post replies

Write your reply to:

Draft