NOTE: Brendon beat me too the next post!! :-)
Check it here: http://blogs.sharepointguys.com/brendon/sharepoint-2007/programming/connecting-the-cqwp-without-changing-itemstyle-xsl/
One of the problems with using the CQWP in SharePoint is that if you want to try and style the content it renders you, have to add the new styles into the "ItemStyle.xsl" file. This is great but also means that you have to manage the modification of these styles very closely as this is the only file that is referenced. What we can do however to remedy this is to create different XSL style sheets and reference these within the "ItemStyle.xsl". This means that the styles can be modified without actually messing with the "ItemStyle.xsl" and you are also able to set permissions for editing the specific files. So enough about talking about it lets look at how we do it. Firstly I have taken a copy of the "ItemStyle.xsl" so I can work offline and then upload when ready. I am also using Visual Studio 2008 as my XSL editor. So let's open up the "ItemStyle.xsl" file and copy the default style:
We will now need to create a new XSL Style sheet; mine is called "Imported.xsl". We need to add this code block to the new XSL style sheet and make the following changes:
The name in this example has also been changed to the following:
Now we have the new XSL Style Sheet completed lets simply modify the "ItemStyle.xsl" to not only import the new style sheet but also create a new style that calls the template we added to the new XSL Style Sheet.
Import Statement:
Custom Style:
Now we have our new style sheet completed we need to upload them to the "Style Library".
NOTE: Make sure these files are checked in
Once the files are checked in you should be now be able to select the style from the presentation section of the CQWP.
Using our demonstration XSL Style Sheet it should render as shown below:
As you can see this approach gives you a better option when creating XSL Styles that are to be used by the CQWP. This allows for easier management of changes of the styles, as well as controlling the overall changes being made to the "ItemStyle.xsl". |