SP CQWP custom ContentQueryMain.xsl
Posted by PANVEGA on March 20, 2009
I would like to get the web part title in the Contentquerymain.xsl. I don’t want to put the title in the normal web part header, because it will modify all web parts headers and I only want to modify the CQWPs ones.
Here I described a way how to add any functionality to your CQWP. You can create your own version of the ContentQueryMain.xsl file that you can use for that specific web part.
While customizing the ItemStyle.xsl stylesheet is a quick and easy way to stylize your rollups and other output, it doesn’t really give you the ability to make any major changes to the structure or behavior of the CQWP. To do this, you’ll need to modify the stylesheet titled “ContentQueryMain.xsl,” which is located in the same folder as the ItemStyle.xsl file (/Style Library/XSL Style Sheets/). The problem with modifying the ContentQueryMain.xsl file is that any changes you make to this file will affect all CQWP’s site-wide. That’s not desirable in just about any situation, so you’ll have to create your own version of the ContentQueryMain.xsl file that you can use for that specific web part.
The first step is to make a copy of the ContentQueryMain.xsl file. You can do this from within Microsoft SharePoint Designer 2007.
- Open the site you wish to modify
- Browse to “/Style Library/XSL Style Sheets”
- Make a copy of ContentQueryMain.xsl and rename it as you see fit
- Open the file and make any modifications that you see fit
Now that you have a working copy of the stylesheet, you’ll have to reference it in your CQWP. Browse to the page that contains the web part you wish to customize, and then go into edit mode in order to edit that particular web part.
Once in edit mode:
- Click on the edit menu for the CQWP that you wish to customize
- Click on Export…
- You will be prompted to save a “.webpart” file somewhere on your local machine
- Save the file and then open it up with SharePoint Designer
There are a number of web part properties that you can modify here within SharePoint Designer. Scroll down the file and look for the line that begins with <property name=”MainXslLink”… You will have to replace this line with the following code, replacing “MyCustomCQMain.xsl” with the name of your own file.
<property name=”MainXslLink” type=”string”>/Style Library/XSL Style Sheets/(your own file name).xsl</property>
Now save your changes, then browse back to your website and (once again in edit mode):
- Click on Add a Web Part
- Click on Advanced Web Part gallery and options (near the bottom-right of the pop-up window)
- At the top of the Add Web Parts task pane, click on Browse and select Import
- Browse to your custom .webpart file
- Click on Upload
- Select a web part zone from the “Add to:” menu and then click on Import
You should now see any changes that you have made in your custom stylesheet. Note that any subsequent changes that you make to this XSL file may not be viewable unless you go into and then out of edit mode. On publishing sites, you may have to check in your files and stylesheets to view the changes.