Skip to main content

Modifying SharePoint's ItemStyle.xsl causes problem with Summary Link Web Part

Today I discovered an issue with some customisations I did for a client. The customisations involved changing the ItemStyle.xsl file, to add new templates for a Content Query Web Part.

More specifically, the client wanted to show a view of news items, the latest news item to be displayed in full, and the remaining x number of items to display in summary form.

This can be done with a test for preceding sibling nodes, e.g.
<xsl:test="count(preceding-sibling::*)=0">


This particular client had one more specific requirement, to also show images associated to the latest News Item. To do this, I created a new XSL variable, pulling in the URL of the image with the following code:
<xsl:variable name="NewsItemImage">
<xsl:call-template name="OuterTemplate.FormatValueIntoUrl">
<xsl:with-param name="Value" select="@ImageUrl">
</xsl:with-param>
</xsl:call-template>
</xsl:variable>

After some fiddling around with HTML to ensure news items would display in a pleasant manner, I checked in all changes to ItemStyle.xsl, and finished configuring the Content Query Web Part's Item style (under Modify Shared Web Part -> Presentation) to use the new style. All was good in the world.

But, a few days later after the client had begun adding content to the site, they noticed they couldn't add Summary Link Web Parts. All Summary Link Web Parts would display the old "Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Windows SharePoint" error message.

After digging around in the SharePoint log files, I found that every time a page that contains a Summary Link Web Part was loaded, the following error would occur:
The named template 'OuterTemplate.FormatValueIntoUrl' does not exist. An error occurred at http://xxx/Style Library/XSL Style Sheets/ItemStyle.xsl(392,10).     at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)     at System.Xml.Xsl.XslCompiledTransform.Load(XmlReader stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)     at Microsoft.SharePoint.WebPartPages.DataFormWebPart.GetXslCompiledTransform()

So apparently, the OuterTemplate in the of a Summary Link Web Part doesn't have the same <xsl:template>'s defined as the OuterTemplate of a Web Part that sources data from a list. This makes sense, since the links contained in a Summary Link Web Part are stored within the Web Part contents themselves, and not queried from elsewhere in the site.

The solution?

Add a dummy <xsl:template name="OuterTemplate.FormatValueIntoUrl"> element to the bottom of your ItemStyle.xsl. That way, when the Summary Link Web Part tries to validate the contents of ItemStyle.xsl, it has an <xsl:template> to refer to for "OuterTemplate.FormatValueIntoUrl", and when the Content Query Web Part parses the data through the Item Style, it refers to it's real OuterTemplate's <xsl:template> instead. Here's an example of the actual XSL code to add:
<!-- The following is used to fool the summary links web part into thinking the OuterTemplate.FormatValueIntoUrl template exists -->
<xsl:template name="OuterTemplate.FormatValueIntoUrl"></xsl:template>

Comments

  1. Thank you - this was so helpful. I had the exact same problem and you just saved me a ton of time.

    Lindy Gibbons

    ReplyDelete
  2. Thanks, I too had this exact problem and am glad that someone posted it up. You saved me a lot of time and frustration.

    ReplyDelete
  3. I've learned since writing this post that the best way to avoid this issue is to use your own ItemStyle.xsl and leave the default SharePoint version intact.

    Heather Solomon (http://www.heathersolomon.com/blog/articles/CustomItemStyle.aspx) and the MSDN (http://msdn.microsoft.com/en-us/library/bb850574%28office.12%29.aspx) both suggest editing ItemStyle.xsl itself. This is bad in my opinion as its very dificult to back-out the change, say if your modification was deployed via a Site-level feature. If your ItemStyle XSL sits in its own file, its a lot easier to delete.

    ReplyDelete
  4. I had this exact problem too. I'm just wondering if there is a way to prevent "OuterTemplate.FormatValueIntoUrl" from displaying in the 'Item style:' dropdown list within the 'Presentation' section of the sharepoint GUI?

    ReplyDelete

Post a Comment

Popular posts from this blog

Thoughts, shortcomings, gotchas on SPFx Dynamic Data capabilities

It's the festive break, and I thought I'd try the new Dynamic Data capabilities that recently went to General Availability in SharePoint Framework 1.7.

I've been building a lot of React components lately, and all the SPFx web parts and application customisers with visual elements we create at Engage Squared, are built on React.  Dynamic Data in SPFx introduces a whole new world of modularity that we haven't had before. We can now split up the page elements into multiple web parts that, in the past, have been combined as one web part so state can be passed between them.  Doing this gives control back to the page author, with the ability to position components how they wish.

Breaking components up in to individual web parts also changes the way the components are designed, and forces the developer to leverage the responsive capabilities of modern pages.  Modern pages are designed from the ground up to work on many different screen sizes, and as long as each individual co…

Apps for SharePoint 2013 - Client and Server-side code

It's about time I blew the dust off this blog. Tonight I did a presentation at the Melbourne SharePoint User Group entitled Apps For SharePoint (2013). It included two demos based on the App For SharePoint 2013 solution template in Visual Studio 2012.

The two demos illustrated how you can create a separate ASP.Net Web Application. Demo 1 showed how easy it is to hook in to SharePoint to obtain List properties via server-side code (populating an ASP.Net Repeater Control). Demo 2 showed what you can do with SharePoint 2013's Javascript hooks. Specifically, using SP.UI.Controls.js from the /_layouts/15/ SharePoint folder to pull chrome elements out of SharePoint, and render them in your ASP.Net web app.

No animals were harmed in the making of these demos, but a few articles kindly provided on the Microsoft MSDN site helped put it together:
How to: Set up an on-premises development environment for apps for SharePointHow to: Create high-trust apps for SharePoint 2013 using the se…

SharePoint "Like" button

Ever wondered what the users of your Intranet really like or don't like? Ever wanted your SharePoint 2007 site to be more "web 2.0"-ey? Well I've published this quick and dirty codeplex project that allows the addition of a "Like" button the any SharePoint List item page.
The project is available as a WSP, and source code.
It consists of two things - a Web Part that is the button that users click to "Like" or "Unlike" something, and a List Template that can be used to create a list to store who "Likes" an item.
The button has two ways of operating. If it finds a list that was built on the List Template included in the WSP, it allows each user to Like or Unlike an item as they see fit. The button uses the List it found to keep track of who likes a given item, and queries the list when it renders to determine which option should be presented. Along with the button, the web part also displays a brief message explaining how many pe…