Sitecore, XSL

XslExtensions be gone! – part 1


One of the features of Sitecore which challenges correct development practise is XslExtensions (or XslHelpers as we call them). Good examples of XslExtensions are the Sitecore.Xml.Xsl.XslHelper and Sitecore.Xml.Xsl.SqlHelper classes (read more here).

The possibility of hooking in your own .NET functions into your XSLT code is a vital part of Sitecore, but the concept of XslExtensions brings a few problems to the party:

  • XslExtensions are actually a return to the world of functional programming and removes the concept of which context your code is running.
  • XslExtensions are loosly bound to where it is used. In practise it is difficult to know from where your code is being called – if it is called at all.
  • Hooking in XslExtensions requires changes to your web.config file. This is actually not a big problem, but it would be nice to be without.
  • XslExtension methods require specific types as input and output. Therefore if you introduce nice functionality in a XslExtension method, it is bound to the XSLT compliant types.
  • XslExtensions lies on the border between the UI and the business logic tier of your application. Therefore XslExtensions can often be cluttered with methods which replicate and port functionality in your business logic to XSLT compliancy, or actually introduces new business logic functionality.

A good example of this last two points are Sitecore.Xml.Xsl.XslHelper.HasBaseTemplate() method, which is actually the only place in the Sitecore API where you can query whether an Item derives from a given template. This means that if you need this code in ASP.NET, you need to replicate the functionality in your own classes or – even worse – call Sitecore.Xml.Xsl.XslHelper.HasBaseTemplate() from your ASP.NET codebehind.

So, what can we do to try to enforce good development practise while still maintaining the essential functionality of exposing .NET methods to XSLT’s? I’ll get back to that in part two of my post.

Standard

3 thoughts on “XslExtensions be gone! – part 1

  1. In general XSLT is functional style coding. I’m also absolutely unhappy with . This is a casing unexpected side effect which are unexplaining as well. You cannot call it a monad as the behaviour can’t be described.
    I’ve talked about this with Ole and the reason to introduce this is that we’re not here to provide purity to developers, but productivity. Nevertheless, you are right that it’s not fancy.

    Looking forward to your next post :).

    – Alex

  2. Pingback: Sitecore Fetch Squad » Blog Archive » XslExtensions be gone! - part 1

  3. Pingback: Sitecore Shared source is growing « Sitecore Shared Source Weblog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s