Skip to main content
Boman.Biz

Boman.Biz

Go Search
Home
Mobile Monger
  

Boman.Biz > Posts > Announcements Transform for CQWP
Announcements Transform for CQWP
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, '&lt;')">
      <xsl:value-of select="substring-before($html, '&lt;')"/>
      <!-- Recurse through HTML -->
      <xsl:call-template name="removeHtmlTags">
        <xsl:with-param name="html" select="substring-after($html, '&gt;')"/>
      </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="'&amp;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="'&amp;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) &gt; 200">...</xsl:if>
    </DIV>
   </TD>
  </TR>
  <TR>
   <TD>
    <FONT size="1">
    <xsl:value-of select="'&amp;nbsp;'" disable-output-escaping="yes" />
    </FONT>
   </TD>
  </TR>
 </TBODY>
</TABLE>
  
 </xsl:template>
 <!-- JBoman: End announcement transform -->

Comments

convert @Author to userdisp.aspx

Exactly what I was looking for in relation to WCM page rollups. Thank you!
at 17/12/2009 3:29 AM

Problem with Author name

I use your xsl idea but I have problem with the Author name. Author name is Blank and I do not why. I use the field Author;

any idea??
at 2/09/2010 5:11 AM

RE: Problem with Author name

I would start by checking to see if the actual @Author variable is being passed into your transform by outputting it directly in the table somewhere like this:

<xsl:value-of select="@Author"/>

If no luck there - do a Google on CommonViewFields and read-up about the process of making sure you have added it into list of fields by exporting your webpart, editing it, and re-importing it.

Good luck,
 James.
at 2/09/2010 10:47 AM

Add Comment

Title


Body *


From *


If you are commenting to add SPAM - what is your motivation? *


Attachments