When working with customizing the Content Query Web Part (aka CQWP), you often want to know what you're dealing with. In this article I'm going to show you how you can show all the fields and their contents for all the items being displayed.
There are several suggestions out there on how to accomplish this, but here's my take. This recipe involves editing the style sheets (XSLT) for the CQWP. The CQWP uses three different style sheets for rendering the content set up to be displayed. By default these three are:
- /Style Library/XSL Style Sheets/ContentQueryMain.xsl
- /Style Library/XSL Style Sheets/Header.xsl
- /Style Library/XSL Style Sheets/ItemStyle.xsl
The one we are going to focus on, is the last one: ItemStyle.xsl.
Using SharePoint Designer, open this file. Add the following template text in the bottom of the file (but before the closing tag):
<xsl:template name="ShowXML" match="Row[@Style='ShowXML']" mode="itemstyle">
<xsl:variable name="SafeLinkUrl">
<xsl:call-template name="OuterTemplate.GetSafeLink">
<xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
</xsl:call-template>
</xsl:variable>
<b>
Item: <i>
<a href="{@LinkUrl}">
<xsl:value-of select="@Title" />
</a>
</i>:
</b>
<ol>
<xsl:for-each select="@*">
<xsl:sort select="name()"/>
<li>
<xsl:value-of select="name()" />
<xsl:text disable-output-escaping="yes"> </xsl:text>
<i>
<xsl:value-of select="." />
</i>
</li>
</xsl:for-each>
</ol>
<br />
</xsl:template>
- Save the file, and do a Check-in.
- Now go back to your page containing your CQWP, Edit Page, and choose Modify Shared Web Part on the CQWP.
- Under the Category Presentation, in the Item Styles dropdown list, now choose your new style called ShowXML. See screen shot below
- Finally, click Apply or OK.
The CQWP will now display all the items with all the fields and their content. I've formatted the output somewhat, but as you can see from the code pasted into ItemStyle.xsl earlier, it's easy to make changes.
For example of result, see screen shot below.
That's it! There's nothing to it!
But, the point of doing this in the first place is not only to see which fields you have available. You have probably created your own fields you want to use in the CQWP. So, to make them available here, I would like to send you over to Heather Solomons' excellent article on how to accomplish this. Check it out here:
Customizing the Content Query Web Part and Custom Item StylesFor more information on how to customize the CQWP and its style sheets, check out my de.icio.us bookmarks on
http://feeds.delicious.com/rss/frankove/cqwp. I won't bother posting all the links in this post, since I constantly find new good links. But here are a few good ones: