All about the Strategy, Design, Customisation, Deployment and Development of SharePoint and its related Technologies

  Administration   All Me!! Baby!!   BDC   Book Review   Business   CKS   Conferences   CQWP   Development   Duffer Moments   Email   Errors   Family   Fixes   General   Groove   How To   How To Code   InfoPath   iPhone   IRM   Longhorn   Lotus Notes   Migration   Mobility   Office System 2007   Personal Projects   Powershell   Records Management   REST Services   Search Server   Security   SEO   SharePoint   SharePoint 2010   Silverlight   SQL   Tech Ed 2008   Testing   Vista   VSTO   WCF   WSS   XSL

[10/05/2008] CQWP HINTS – Import XSL Styles into “ItemStyle.xsl”
 
Categories: Development, Office System 2007, SharePoint, CQWP, XSL
 

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".

 
3 Comments
 

Comments

Thursday, 17 Jul 2008 10:23 by Bob
Hi Liam, I typed this in as shown above but my CQWP errored out after changing the itemstyles.xsl. Perhaps I placed the two pieces of code you show in your example in the wrong area. Can you explain where the two lines of code for the itemstyle.xsl file? One other question... I cut and paste the exact chunk of code that you show in your example into my imported.xsl file. Perhaps I was to leave the header information at the top... I'm just not sure, can you let me know. Thank you -Bob

Friday, 7 Nov 2008 02:02 by Denis
Same problem, very weird, can't figure out the bug. When i try to view the XSL from SharePoint I get the following error: The XML page cannot be displayed Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later. -------------------------------------------------------------------------------- The operation completed successfully. Error processing resource 'http://nielsenisharedev.nielsen.com:8090/Style%20Library/X... Mean anythign to you?

Friday, 7 Nov 2008 02:32 by Denis
Another weird thing when the stylesheets are in draft mode, everything seems to function as expected. Once i publish them to major copies all of the associated webparts break. I'd love this solution if i could get it to work properly. Thanks again.

Name:

URL:

Email:

Comments: