SharePoint Content Query Web Part (CQWP) Toolset

The CQWP is a fantastic tool built into SharePoint Sever edition which allows an admin to retrieve items from lists within a site collection. What makes it powerful is its out of the box functionality to style the items retrieve using XSLT & CSS. This article provides some common toolsets that use on a common basis.

There are some great blogs around that provide instructions on how to use this web part so Im not going to do that again here. This is simply a cheat sheet when using the CQWP. If you are new to this web part on want to learn the basics I recommend this article by Paul Galvin

CommonViewFields – Types

<property name="CommonViewFields" type="string">InternalColumn1, FieldType; InternalColum2, FieldType;</property>

  • Text
  • Note
  • Number
  • Currency
  • Integer
  • Boolean
  • DateTime
  • Threading
  • Lookup
  • Choice
  • URL
  • Counter
  • DisplayOnly (DisplayOnly field type has no storage of its own)
  • RichHTML
  • Image

Available Fields For Use

To iterate through all of your available fields use the following:

    <xsl:for-each select="@*">
      P:<xsl:value-of select="name()" /><br/>

Retrieve Value of Field

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

Force tag to render

An empty html tag will be stripped out if it contains no content. For example if you want to render <div class=”clear”></clear> this would be stripped out. The easiest way I have found to ensure it renders is to use the following:

<xsl:text> </xsl:text>
<div class="clear" ><xsl:text> </xsl:text></div>

Format URL to get Display Text & URL

<a href="{substring-before(@Link1,’,’)}"><xsl:value-of select="substring-after(@Link1,’, ‘)"/></a>

Render a list of Links


<xsl:template name="QuickLinks" match="Row[@Style='QuickLinks']" mode="itemstyle">
   <xsl:param name="CurPos" />
   <xsl:param name="Last" />
   <xsl:variable name="tableStart">
      <xsl:if test="$CurPos = 1">
            <ul id="quickLinkList">
   <xsl:variable name="tableEnd">
      <xsl:if test="$CurPos = $Last">
         <![CDATA[ </ul>  ]]>
   <xsl:variable name="SafeLinkUrl">
      <xsl:call-template name="OuterTemplate.GetSafeLink">
         <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
   <xsl:variable name="SafeImageUrl">
      <xsl:call-template name="OuterTemplate.GetSafeStaticUrl">
         <xsl:with-param name="UrlColumnName" select="'ImageUrl'"/>
   <xsl:variable name="DisplayTitle">
      <xsl:call-template name="OuterTemplate.GetTitle">
         <xsl:with-param name="Title" select="@Title"/>
         <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
   <xsl:value-of select="$tableStart" disable-output-escaping="yes"/>
   <div class="QLitem">
      <div class="link-item">
         <a href="{$SafeLinkUrl}" title="{@LinkToolTip}">
            <xsl:value-of select="$DisplayTitle"/>
   <xsl:value-of select="$tableEnd" disable-output-escaping="yes"/>


One Response to SharePoint Content Query Web Part (CQWP) Toolset

  1. Pingback: Anonymous

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: