I was asked to do a roll-up for announcements and was frustrated that the Content Query WebPart does not have a out-of-the box transform for displaying announcements. I could get the title but that was about it.
I have cobbled togther a transform to be put in the ItemStyle.xsl file to give the rolled-up announcements an almost identical look to the normal announcements webpart.
Note:
- You need to add the Dataviewer namespace to your ItemStyle.xsl file.
- You need to export you CQWP add "Body,text" into your commonviewfields property and import it back in.
<!-- JBoman: Start announcement transform -->
<xsl:template name="removeHtmlTags">
<xsl:param name="html"/>
<xsl:choose>
<xsl:when test="contains($html, '<')">
<xsl:value-of select="substring-before($html, '<')"/>
<!-- Recurse through HTML -->
<xsl:call-template name="removeHtmlTags">
<xsl:with-param name="html" select="substring-after($html, '>')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$html"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="Announcements" match="Row[@Style='Announcements']" 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="LinkTarget">
<xsl:if test="@OpenInNewWindow = 'True'" >_blank</xsl:if>
</xsl:variable>
<xsl:variable name="AuthorName">
<xsl:call-template name="OuterTemplate.GetGroupName">
<xsl:with-param name="GroupName" select="@Author"/>
<xsl:with-param name="GroupType" select="'User'"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="TextBody">
<xsl:call-template name="removeHtmlTags">
<xsl:with-param name="html" select="@Body" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="AuthorID">
<xsl:value-of select="ddwrt:UserLookup(string(@Author) ,'ID')" />
</xsl:variable>
<xsl:variable name="AuthorEmail">
<xsl:value-of select="ddwrt:UserLookup(string(@Author) ,'EMail')" />
</xsl:variable>
<TABLE class="ms-summarycustombody">
<TBODY>
<TR>
<TD class="ms-vb" style="PADDING-BOTTOM: 3px" width="80%">
<SPAN class="ms-announcementtitle">
<A onfocus="OnLink(this)" onclick="GoToLink(this);return false;" href="{$SafeLinkUrl}" target="_self"><xsl:value-of select="@Title"/></A>
</SPAN>
<BR />
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
by<xsl:value-of select="'&nbsp;'" disable-output-escaping="yes" />
</td>
<!--
<td>
<span class="presence-status-icon">
<img src="/_layouts/images/imnhdr.gif" onload="IMNRC('{$AuthorEmail}')" ShowOfflinePawn="1" alt="" id="{concat('MWP_pawn_',@ID,'type=sip')}" />
</span>
</td>
-->
<td>
<a href="/_layouts/userdisp.aspx?ID={$AuthorID}"><xsl:value-of select="$AuthorName" /></a>
</td>
</tr>
</table>
<!-- Attempt at Presence icon, $ClientId is undefined :( <img src="/_layouts/images/imnhdr.gif" onload="IMNRC('{$AuthorEmail}')" ShowOfflinePawn="1" alt="" id="{concat('MWP_pawn_',$ClientId,'_',@ID,'type=sip')}" /> -->
<!--
<A onclick="GoToLink(this);return false;" href="/_layouts/userdisp.aspx?ID={$AuthorID}"><xsl:value-of select="$Author" /></A>
<IMG height="1" alt="" src="/_layouts/images/blank.gif" width="3" border="0" />
-->
</TD>
<TD class="ms-vb" align="right" width="20%">
<xsl:value-of select="'&nbsp;'" disable-output-escaping="yes" />
<xsl:value-of disable-output-escaping="no" select="ddwrt:FormatDateTime(string(@Created) ,1033 ,'d-MMM-yyyy hh:MM tt')" />
</TD>
</TR>
<TR>
<TD class="ms-vb" colSpan="2">
<DIV>
<xsl:value-of select="substring($TextBody,0,200)" disable-output-escaping="yes" />
<xsl:if test="string-length(@Body) > 200">...</xsl:if>
</DIV>
</TD>
</TR>
<TR>
<TD>
<FONT size="1">
<xsl:value-of select="'&nbsp;'" disable-output-escaping="yes" />
</FONT>
</TD>
</TR>
</TBODY>
</TABLE>
</xsl:template>
<!-- JBoman: End announcement transform -->