AlertThis post is over a year old, some of this information may be out of date.
Discussion Board Style for the Content Query Web Part
When you want to create a rollup from all discussion board (or a specific one) in SharePoint, you will notice that the Content Query Web Part does not have an appropriate style for it.
Every out of the box style from the Content Query Web Part returns the following result.
As you can see in the image above, the content query web part returns (Blank) messages. These (Blank) messages are the replies users have made.
So why do messages return as (Blank)?
As you may or may not know, the discussion board contains two content types.
Discussion;
Message.
Message can only be used when you do a reply on a discussion (which creates folders), and they do not contain a Title/Subject field (this is hidden by default).
Because you do not need to add the subject in your reply, the title/subject field automatically gets (Blank) as field value.
Discussion Board Content Query Web Part Style
The result of the Discussion Board Style will be the following:
As you can see the (Blank) messages are replaced with the discussion subject. To do this, you can retrieve the subject from the LinkUrl of the message.
The subject of the discussion exists in the LinkUrl, because when a discussion is started, it creates a folder with the subject as folder value.
<!-- Discussion Style --><xsl:templatename="DiscussionStyling"match="Row[@Style='DiscussionStyling']"mode="itemstyle"><!-- Retrieve the content type: 'Content Type' --><xsl:variablename="Type"select="@Type"/><!-- Retrieve the discussion/message creatore: 'Created By' --><xsl:variablename="Creator"select="@Creator"/><xsl:choose><!-- Check if item is a reply --><xsl:whentest="$Type='Message'"><!-- Retrieve the ReplyId, ex: '7_.000' --><xsl:variablename="MessageId"><xsl:call-templatename="StripSlash"><xsl:with-paramname="text"select="@LinkUrl"/></xsl:call-template></xsl:variable><!-- Remove the ReplyId from the discussion URL --><xsl:variablename="DiscussionUrl"select="substring-before(@LinkUrl, concat('/', $MessageId))"/><!-- Retrieve the discussion title from the URL --><xsl:variablename="DiscussionTitle"><xsl:call-templatename="StripSlash"><xsl:with-paramname="text"select="$DiscussionUrl"/></xsl:call-template></xsl:variable><spanstyle="font-style:italic;"> [
<xsl:value-ofselect="$DiscussionTitle"/> ]({$DiscussionUrl}) (Replied by: <xsl:value-ofselect="$Creator"/>)
</span></xsl:when><xsl:otherwise> [
<xsl:value-ofselect="@Title"/> ]({@LinkUrl}) (Posted by: <xsl:value-ofselect="$Creator"/>)
</xsl:otherwise></xsl:choose></xsl:template><xsl:templatename="StripSlash"><xsl:paramname="text"/><xsl:choose><xsl:whentest="contains($text, '/')"><xsl:call-templatename="StripSlash"><xsl:with-paramname="text"select="substring-after($text, '/')"/></xsl:call-template></xsl:when><xsl:otherwise><xsl:value-ofselect="$text"/></xsl:otherwise></xsl:choose></xsl:template>
For the messages the ID (12_.000) will be removed from the LinkUrl, otherwise you will end up on a page that does not exist.
The XSL style can be added to the ItemStyle.xsl, which can be found at the following location: http://your_sitecollection_url/Style Library/XSL Style Sheets/ItemStyle.xsl.
When you add the content query to you page, change the Styles and Fields settings to match as in the following image.
When you save these settings, the result should be like this: