Copied to clipboard

Flag this post as spam?

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


  • Vishal G.P 62 posts 122 karma points
    Mar 28, 2012 @ 10:57
    Vishal G.P
    0

    XSL:key strange behavior

    Hey guys,

     

    i have a couple of NewsItems with a date property...

     

    Now i want to make an archive with all the distinct years below each other.. I made my key as below. 

    And below that i have my foreach which loops thru all my NewsItems... 

    The problem here is i have 8 or so newsitems, with all different years (as a test).. also i have one with 2012 in the date... But i get all the other years except for the 2012 one... If i change the year (of the date property) to another year say 2014, then i see that year appear in the list. But once put back to any date in 2012, it refuses to show the distinct 2012 year... All other years appear properly... 

    I dont think i'm doing anything wrong here... right?

     

    In the last code line, i also tried another for-each procedure of the MUENCHIAN method. But the same behaviour as well.

     

        <xsl:key name="years" match="NewsItem" use="umbraco.library:FormatDateTime(date,'yyyy')" />
    <xsl:for-each select="$currentPage/..//*[generate-id() = generate-id(key('years',umbraco.library:FormatDateTime(date,'yyyy'))[1])]">
              <xsl:sort order="descending" select="umbraco.library:FormatDateTime(date,'yyyy')"/>
              <xsl:variable name="currentYear" select="umbraco.library:FormatDateTime(./date,'yyyy')" />
              <div class="year">
                <p class="year-title">
                  <a href="#">
                    <xsl:value-of select="umbraco.library:FormatDateTime(./date,'yyyy')"/>
                  </a>
                </p>
              </div>
            </xsl:for-each>
    
    <xsl:for-each select="$currentPage/..//*[count(. | key('years',umbraco.library:FormatDateTime(date,'yyyy'))[1]) = 1]">
    

     

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Mar 29, 2012 @ 22:30
    Chriztian Steinmeier
    0

    Hi Vishal,

    You're right, the code looks like it should work... you could try the following snippet, just as a sanity-check:

    <xsl:key name="years" match="NewsItem" use="substring(date, 1, 4)" />
    
    <xsl:for-each select="$currentPage/..//*[generate-id() = generate-id(key('years', substring(date, 1, 4))[1])]">
        <xsl:sort select="date" data-type="text" order="descending" />
    
        <xsl:variable name="currentYear" select="substring(date, 1, 4)" />
        <div class="year">
            <p class="year-title">
                <a href="#">
                    <xsl:value-of select="$currentYear" />
                </a>
            </p>
        </div>
    </xsl:for-each>
    
    It does the same thing, but without calling any extension functions (not necessary in this case) ... ?
    If this gives you the same result, I'd bet there's something fishy with that 2012 node.

    /Chriztian

  • Vishal G.P 62 posts 122 karma points
    Mar 29, 2012 @ 22:48
    Vishal G.P
    0

    Hi Chriztian,

     

    i tried that code as well yesterday, but still got the same result.. I converted to C# extension method to get the distinct years and that worked :-)

    So for now this still remains a puzzle... anywho... thanks for your input..

     

     

Please Sign in or register to post replies

Write your reply to:

Draft