Exposing .net object to xslt file in Sitecore

I’ve used this solution a long time now, it works great. The main idea is to provide the same object to not only my .net classes but also my xslt files. The first time I found myself in this position, I was looking for a way to pass application settings to my xslts without having to read the same sitecore item more than once per request.

After investigating a bit, it turns out it’s quite simple to do actually. All I had to do was extend the XslFile control. Since I only use XslFile inside ascx or aspx files and not as renderings, that’s all I had to do.

    public class XslFile : Sitecore.Web.UI.WebControls.XslFile
    {

        override protected void AddExtensionObjects(XsltArgumentList list, Sitecore.Data.Items.Item item)
        {
            base.AddExtensionObjects(list, item);
            list.AddExtensionObject("http://www.website.com/settings", RequestManager.SettingsManager);
            list.AddExtensionObject("http://www.website.com/assets", RequestManager.AssetsManager);
        }
    }

In my xslt file I then defined the required namespaces and that was it.

RequestManager.SettingsManager

Leave a Reply