0

I have created XSLT to display all news archive using Content query webpart in sharepoint 2010. Currently the list display the record ordered by Created date ASC. I would like to know how i can implement group by Month and Year of create date ASC. Please advise, thank you

this is the template that i have so far:

 <xsl:template name="allNews" match="Row[@Style='allNews']" mode="itemstyle">


        <xsl:variable name="SafeLinkUrl">
            <xsl:call-template name="OuterTemplate.GetSafeLink">
                <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
            </xsl:call-template>
        </xsl:variable> 
        <xsl:variable name="DisplayTitle">
            <xsl:call-template name="OuterTemplate.GetTitle">
                <xsl:with-param name="Title" select="@Title"/>
                <xsl:with-param name="ArticleStartDate" select="'LinkUrl'"/>
            </xsl:call-template>
        </xsl:variable>
        <xsl:variable name="Created">
            <xsl:value-of select="ddwrt:FormatDateTime(string(@ArticleStartDate) ,1033 ,'dd/MM/yyyy')" />
        </xsl:variable>
        <xsl:variable name="LinkTarget">
            <xsl:if test="@OpenInNewWindow = 'True'" >_blank</xsl:if>
        </xsl:variable>

    <!-- First row -->
    <xsl:variable name="CurPosition" select="count(./preceding-sibling::*)" />
    <xsl:if test="count(preceding-sibling::*)=0"> 
    <div class="CQWP-AllNewsHeader">News Archieve</div>
    </xsl:if>

    <!-- Create var for alternate classes -->
    <xsl:variable name="OddOrEven" >
        <xsl:choose>     
            <xsl:when test="($CurPosition mod 2 = 0)">        
                <xsl:text>CQWP-AllNewsOdd</xsl:text>     
            </xsl:when>
            <xsl:otherwise>
                <xsl:text>CQWP-AllNewsEven</xsl:text>
            </xsl:otherwise>     
        </xsl:choose>
    </xsl:variable>

    <!-- All rows between the first and the last -->
    <div id="linkitem" class="{$OddOrEven}">
        <xsl:value-of select="$Created"/>

            <a href="{$SafeLinkUrl}" target="{$LinkTarget}" title="{@LinkToolTip}" >
                <xsl:call-template name="FirstNWords">
                    <xsl:with-param name="TextData" select="$DisplayTitle"/>
                    <xsl:with-param name="WordCount" select="7"/>
                    <xsl:with-param name="MoreText" select="'...'"/>
                </xsl:call-template>
            </a>
    </div>



 </xsl:template>

1 Answer 1

0

Christian Stahl has an approach for DVWP (not CQWP) that involves creating two calculated columns to store year and month.

For the month use

=TEXT([TheDate],”MM”)

and for the year use

=TEXT([TheDate],”yyyy”)

The DVWP can then be built using these two columns for the grouping. You can do the main grouping through the ribbon tools in the DVWP and then fine tune the XSL templates as desired.

Here is Christian Stahl's approach: http://chrisstahl.wordpress.com/2011/09/18/how-to-customize-a-grouped-view-in-the-data-view-web-part/

The principle can be applied to the CQWP XSL as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.