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

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

    <!-- Create var for alternate classes -->
    <xsl:variable name="OddOrEven" >
            <xsl:when test="($CurPosition mod 2 = 0)">        

    <!-- 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="'...'"/>


1 Answer 1


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

For the month use


and for the year use


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 you have read our privacy policy.

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