Quantcast
Channel: < I runat="server" / >
Viewing all articles
Browse latest Browse all 10

Registering XSLT Extension Objects with the ASP XML control

$
0
0

I once inherited a sublayout that inlcuded an asp:xml control. The asp:xml control was there to handle and display an xml feed from another system, while the rest of the sublayout concentrated on rendering related feed content from Sitecore. The presentation of the xml feed was handled via an xlst rendering.

In this particular situation, I made use use of XSL extensions in the XSLT file. Registering the XSL Extension was fairly easy.

<xslExtensions>   <extension mode="on" type="Utils.XslHelper, Utils"
	           namespace="http://www.sitecore.net/Utils" 
		   singleInstance="true" />
	   .....</xslExtensions>



Registering the extension in the xsl file

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:MyExtension="http://www.sitecore.net/Utils"
 exclude-result-prefixes="MyExtension" ><xsl:value-of select="MyExtension:HelloWorld()" />



Binding the XML control to the XML Data

protected override void OnInit(EventArgs e)
    {
        if (!this.IsPostBack)
        {
            string xmlContent = "xml data goes here";
            XsltArgumentList list = new XsltArgumentList();
            Utils.XslHelper ext = new Utils.XslHelper();
            list.AddExtensionObject("http://www.sitecore.net/Utils", ext);
            Xml1.TransformArgumentList = list;
            Xml1.DocumentContent = xmlContent;
        }
    }

It turns out that, even though I had previously registered the xsl extension in the xslt file, I also had to register it via code as well. Otherwise, the following exception occurs at runtime.

Cannot find the script or external object that implements prefix 'MyExtension'.

Sorted!


Viewing all articles
Browse latest Browse all 10

Trending Articles