Connecting the CQWP without changing ItemStyle.xsl

I found this article on Brendon Schwart’s blog.

Reading over articles using the Content Query Web Part (CQWP) to connect your XSLT styles by putting a reference in the ItemStyle.xsl file is a good idea, but it still modifies the Out of the Box (OOB) ItemStyle.xsl.  In many cases, in large companies you can’t change the OOB files and this file is no exception, especially since your changes would be overwritten by any product that changed the file also.

The approach to use if you are using a different style than the out of the box style is to deploy your own .webpart of the Content Query Web Part that references a different style sheet than the ItemStyle.xsl file.

First let’s look at what the .webpart would look like, the change to notice is that we have added an import statement to the supporting XSL element not to the ItemStyle.xsl

<webPart xmlns=”″>

Microsoft.SharePoint.Publishing, Version=, Culture=neutral,
PublicKeyToken=71e9bce111e9429c” />
<importErrorMessage>Cannot import this Web Part.</importErrorMessage>
<property name=”Title” type=”string”>Custom XSLT Style Content Query WebPart</property>
<property name=”Description” type=”string”>Adds other templates to the ItemStyle.xsl</property>
<property name=”ItemXslLink” type=”string”>/Style Library/XSL Style Sheets/DevCowItemStyle.xsl</property>

The ItemXslLink contains a link to the XSLT file that has the item templates.  Make sure that the XSLT file is available or the webpart will display that it cannot import the XSLT file.  Also notice that the path is relative, so you will need to put your files in the based site collection or you will need a way to update the location based on sub site collections.  I couldn’t find a way around this, but maybe the product team will know how.

Now just create your separate file for your XSLT and make sure to add it to you Solution and Feature.

exclude-result-prefixes=”x d xsl msxsl cmswrt”
xmlns:xsl=”” xmlns:msxsl=”urn:schemas-microsoft-com:xslt”>
<xsl:template name=”ShowXML” match=”Row[@Style=’ShowXML’]” mode=”itemstyle”>
<xsl:for-each select=”@*”>
<br />
Name: <xsl:value-of select=”name()” />
<br />Value:<xsl:value-of select=”.” />

Here is what the drop down would now look like.  Keep in mind if you want all of the ItemStyle.xsl items to show up, you can simply copy them from the ItemStyle.xsl.  This will allow you to manage your customizations and not be impacted during changes to the ItemStyle.xsl.