Welcome to EMC Consulting Blogs Sign in | Join | Help

Matt Lally's Blog

Adding XSL to a SharePoint Visual Studio Solution

When working with custom SharePoint search results web parts, inheriting from CoreResultsWebpart you’ll often use XSL to transform the search results display (this is not limited to this type of web part, you can use for list views too).  You could deploy the web part and configure the XSL after deployment or you could include the link to your XSL in your web part and package the XSL with your Visual Studio 2010 project.  To do the latter, from your Visual Studio Project, right click the name of the project in the Solution Explorer pane, select Add, and select SharePoint Mapped Folder.


In resulting window, select the folder at path Template\LAYOUTS\XSL to map.  Once mapped, I suggest adding a custom folder so it’s clear that this is custom XSL and then either upload your existing *.xsl file or create a new one and add your XSL (Side Note, SharePoint Designer does a great job of generating XSL based on any sample XML).


In the inherited class’ ConfigureDataSourceProperties set the XslLink property to the path of the XSL in the hive (“/_layouts/xsl/xyzcustom” in this case).

protected override void ConfigureDataSourceProperties()
      this.XslLink = "/_layouts/xsl/xyzcustom/xyzsearch.xsl";


Now, wherever you deploy the web part and add to a page, it will use your custom XSL.

Using this method, the XSL can not be overridden, If you want to overide after adding the web part, instead add to your web part's properties like this.

<?xml version="1.0" encoding="utf-8"?>
  <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
      <type name="XYZSearchBuilder, $SharePoint.Project.AssemblyFullName$" />
        <property name="Title" type="string">My Core Search Results</property>
        <property name="Description" type="string">Inherits from Core Results Web Part.  This web part provides a fixed query builder configuration to set keyword values to provide results containg the currently logged in user.  The web part also provides configuration to sort results by a managed property (reduce storage may need to be set).</property>
        <property name="XslLink" type="string">/_layouts/xsl/xyzcustom/xyzsearch.xsl</property>

Published Thursday, December 29, 2011 8:23 PM by matt.lally

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS



drew said:

Using this method of deployment, if you want to update the XSL styling how do you go about refreshing the web part?

Do you have to redeploy the web part / feature?  Or can you manually deploy a new version of the XSL?


November 20, 2012 2:38 PM

Leave a Comment

Powered by Community Server (Personal Edition), by Telligent Systems