Copied to clipboard

Flag this post as spam?

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


  • Nik Wahlberg 639 posts 1237 karma points MVP
    Feb 03, 2010 @ 02:48
    Nik Wahlberg
    0

    Grouping nodes by Month

    Hi Community, 

    I have been trying to create a grouping of events by using the Muncheun method. It's been producing varying results (see the this post). So, I thought, forget about that method, i'll just use a standard variable grouping by looking ar preceding-sibling. Unfortunately, that doesn't work either since I am trynig to group by a date field and simply using masks to format the data. Like this:

    <xsl:for-each select="$eventNodes">
      <xsl:sort select="data [@alias='eventStartDate']"/>
    
      <xsl:variable name="lastMonth" select="umbraco.library:FormatDateTime(data [@alias='eventStartDate'],'MMMM')" />
      !!!!! <xsl:if test="not(preceding-sibling::umbraco.library:FormatDateTime(data [@alias='eventStartDate'],'MMMM')=$lastMonth)">
        <h2 class="dotted">
          <xsl:value-of select="umbraco.library:FormatDateTime(data [@alias='eventStartDate'],'MMMM - yyyy')" />
        </h2>
        <div class="ctr-events">
          <ul>
        <xsl:for-each select="$eventNodes[umbraco.library:FormatDateTime(data [@alias='eventStartDate'],'MMMM')=$lastMonth]">
          <xsl:sort select="data [@alias='eventStartDate']"/>
    
                <li>
                  <div class="event_date_cal">
                    <span class="event_date_cal_day">
                      <xsl:value-of select="umbraco.library:FormatDateTime(data [@alias=$groupByAlias], 'ddd')"/>
                    </span>
                    <span class="event_date_cal_month">
                      <xsl:value-of select="umbraco.library:FormatDateTime(data [@alias=$groupByAlias], ' d')"/>
                    </span>
                  </div>
                  <div class="info">
                    <div class="title">
                      <a href="{umbraco.library:NiceUrl(@id)}">
                        <xsl:value-of select="@nodeName"/>
                      </a>
                    </div>
                    <span class="location">
                      Location:
                      <span class="bold">
                        <xsl:value-of select="data [@alias = 'eventPrimaryLocation']"/>
                      </span>
                    </span>
                  </div>
                  <div class="clear"><xsl:text> </xsl:text></div>
                </li>
    
        </xsl:for-each>
          </ul>
        </div>
      </xsl:if>
    </xsl:for-each>

    !!!! = not working

    The grouping doesn't work since preceding-sibling::umbraco.library.... doesn't work syntactically. 

    So, my question is, has anyone successfully grouped nodes by month/year using XSLT? If so, would you mind sharing it here? 

    Thanks!

    -- Nik

  • Tommy Poulsen 514 posts 708 karma points
    Feb 03, 2010 @ 07:23
    Tommy Poulsen
    0

    Hi Nik, I'm using grouping by date by  the Munchean method on a couple of sites. My approach is this:

    http://blackpoint.dk/umbraco-workbench.aspx?Snippet=/umbraco-workbench/xslt/grouping--distinct-values.aspx

    In this example I'm using a formatted date string as the key to group from, but you have any option. If you cannot work it out, I can try to adapt the method to your purpose - just let me know. Now I have to take the kids to kindergarden...

    >Tommy

     

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Feb 03, 2010 @ 08:59
    Chriztian Steinmeier
    0

    Hi Nik,

    I can not test if this works for you, but the syntax for doing what you want is wrong - you need to specify the element name after an axis, so to correct the line you're having trouble with, do:

    <xsl:if test="not(preceding-sibling::node[umbraco.library:FormatDateTime(data [@alias='eventStartDate'],'MMMM')=$lastMonth])">

    ("If there's not a preceding sibling named node, having ..... ")

    /Chriztian

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Feb 03, 2010 @ 14:51
    Nik Wahlberg
    0

    Hi,

    @Tommy, the strange this is I CAN get it to work in dev but not production. So weird, and I actually use that grouping on other macros a swell (by month/year). I've abandoned this for now as I have to move on. I'll dig in deeper using this method at later time to see if I can figure it out. 

    @Chriztian, thanks! I think that is exactly what my problem is. I'll give it a test and let you know. Appreciate the insight!

    Best,
    Nik

  • Connie DeCinko 931 posts 1160 karma points
    May 04, 2011 @ 17:51
    Connie DeCinko
    0

    Not meaning to hijaak this thread, but I don't see that there was a resolution.  Below is my latest attempt.  The code works great for content below currentpage but fails for content in sibling nodes.  I am getting every node for the entire site.

      <xsl:for-each select="$currentPage/preceding-sibling::* | $currentPage/following-sibling::* [@isDoc][(generate-id()=generate-id(key('years', Exslt.ExsltDatesAndTimes:year(publicationDate))[1]))]">
        <xsl:sort select="publicationDate" order="descending"/>

        <h3><strong><xsl:value-of select="Exslt.ExsltDatesAndTimes:year(publicationDate)"/></strong></h3>
        
        <xsl:for-each select="key('years',Exslt.ExsltDatesAndTimes:year(publicationDate)) [(generate-id()=generate-id(key('months', Exslt.ExsltDatesAndTimes:monthname(publicationDate))[1]))]">
          <xsl:sort select="publicationDate" order="descending"/>

          <div style="margin-left:10px;">
            <h3><xsl:value-of select="Exslt.ExsltDatesAndTimes:monthname(publicationDate)"/></h3>
        
            <xsl:for-each select="key('months',Exslt.ExsltDatesAndTimes:monthname(publicationDate))">
              <xsl:sort select="publicationDate" order="descending"/>

              <div style="margin-left:10px;">
                <div style="width:64px; float:left;"><xsl:value-of select="Exslt.ExsltDatesAndTimes:formatdate(publicationDate,'MM/dd/yy')"/></div>
                  <div style="margin-left: 64px;"><p><xsl:value-of select="@nodeName"/>
                    </p></div>
                </div>
            </xsl:for-each>
          </div>
        </xsl:for-each>
        <br />
      </xsl:for-each>
  • jayanthi 66 posts 86 karma points
    Sep 07, 2011 @ 17:24
    jayanthi
    0

    Hi all,

    I am trying to categorize or group my press releases based on the year of publishing.When i am using key 'year' (i.e; using formatdatetime )the results are not coming. and when using key 'uniquedate' duplicate years are appearing,can anyone let me know what is the error?

     

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

      <xsl:param name="currentPage"/>
      <xsl:key name="uniqueDate" match="PressRelease" use="pressPublishDate"/>
      <xsl:key name="year" match="PressRelease" use="umbraco.library:FormatDateTime(pressPublishDate,'YYYY')"/>
      <xsl:key name="kNewsByY" match="PressRelease" use="Exslt.ExsltDatesAndTimes:year(pressPublishDate)"    />
     
      <xsl:template match="/">

        <xsl:for-each select="$currentPage/child::*[generate-id() = generate-id(key('year', umbraco.library:FormatDateTime(pressPublishDate,'YYYY'))[1])]">
          <xsl:value-of select="substring(pressPublishDate, 1, 4)"/>

         <br/>
        </xsl:for-each>
        <div class="subnavTabs clearfix" id="subNavTabs">
          <ul>
            <xsl:apply-templates select="$currentPage/child::*[generate-id() = generate-id(key('uniqueDate', pressPublishDate)[1])]" mode="PressRelease">
              <xsl:sort select="pressPublishDate" order="descending" />
            </xsl:apply-templates>
          </ul>
         
        </div>
     
        <!--<xsl:for-each select="$currentPage/child::*">
          <xsl:value-of select="pressPublishDate"/>

          <xsl:value-of select="substring(pressPublishDate, 1,4)"/>
          <br/>
        </xsl:for-each>-->

      </xsl:template>
      <xsl:template match="PressRelease" mode="PressRelease">
        <xsl:variable name="PublishDate">
          <xsl:value-of select="substring(pressPublishDate, 1, 4)" />
        </xsl:variable>

        <xsl:variable name="DivId" select="concat('Div',$PublishDate)" />

        <li>
          <xsl:attribute name="id">
            <xsl:if test="$PublishDate = '2010'">
              <xsl:text>current</xsl:text>
            </xsl:if>
          </xsl:attribute>

          <a href="javascript:Toggle();">
            <xsl:attribute name="onclick">
              <xsl:value-of select="concat('ShowTab(',$DivId,',this);')"/>
            </xsl:attribute>
            <xsl:value-of select="$PublishDate"/>
          </a>
        </li>

      </xsl:template>

Please Sign in or register to post replies

Write your reply to:

Draft