Yesterday, I had to do few changes on some files of the code base of our intranet.
To set the grounds of my post I will tell you more about the issue I had to work on. Our intranet is a Sitecore intranet. Hence, the development environment is .NET C#. I had to do a modification to a page which is rendered using XSL/XSLT. But the changes I had to do on this file need to call a function sitting on C# file. Basically, it is a matter of calling a C# function from XSL file.
How I am going to do it, especially in Sitecore environment.
As I went searching in google, I found a post called “Calling C# function in XSL“ which helped to initiate the grounds although I need to find how it works in sitecore environment to sort my issue fully. But I should thank Pierre-Emmanuel for posting that important information on web for .NET community. It was very useful.
Then I went into Sitecore developer network and found a pdf article called “presentationcomponentxslreference-a4.pdf” which explains how XSL rendering functions have been integrated to Sitecore. It is a fantastic file you should read if you need to know about XSL rendering in Sitecore if you are a Sitecore developer. You may need to log in to sitecore developer network first before you access this link.
Basically, Sitecore renders pages using two ways.
- XSL extension controls
- XSL extension methods
XSL extension controls are XML elements in the XSL code that correspond to .NET classes. For example, the <sc:text> element corresponds to the .NET XSL extension control class Sitecore.Web.UI.XslControls.Text. XSL extension controls are standalone elements in the XSL code.
XSL extension methods correspond to methods in a class. For example, the sc:fld() XSL extension method corresponds to the fld() method of the Sitecore.Xml.Xsl.XslHelper class represented by the sc namespace. XSL extension methods appear within attribute values of XSL elements and cannot stand alone.
Since I needed to call a C# function from XSL I need to follow second method. If your Sitecore code base has been set up by someone else, there is a high chance of finding that XslHelper class file inside “util” folder.
Cheers