I'm having problems calling a .NET method from an XSLT file. What do I have to do in the XSLT to make sure I can call the method?
If I have a class that I would normally refer to in .NET as MyClient.MyProject.Helper, with a static method called GetComments that returned a XPathNodeIterator object, should I be able to call the GetComments method just be doing the following?
Calling .NET static method from XSLT
I'm having problems calling a .NET method from an XSLT file. What do I have to do in the XSLT to make sure I can call the method?
If I have a class that I would normally refer to in .NET as MyClient.MyProject.Helper, with a static method called GetComments that returned a XPathNodeIterator object, should I be able to call the GetComments method just be doing the following?
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library"
xmlns:Helper="urn:MyClient.MyProject.Helper"
exclude-result-prefixes="msxml umbraco.library Helper">
<xsl:output method="html" omit-xml-declaration="yes" />
<xsl:param name="currentPage"/>
<xsl:template match="/">
<xsl:variable name="comments" select="Helper.GetComments($currentPage/@id)//comment"/>
</xsl:template>
</xsl:stylesheet>
Currently I'm getting an error - 'Error parsing XSLT file'. If I remove the <xsl:variable /> tag there is no error.
Have you added your assembly to ~/config/xsltExtensions.config ?
I think you'll also need a semi-colon in there, like this: Helper:GetComments
Hi Alex,
haven't got my code with me at the moment, however there is an excellent series on Xslt extensions with step by step guide in the Umbraco.tv section:
http://umbraco.org/documentation/videos/for-developers/xslt-extensions/introduction-to-xslt-extensions
Have a look,
Sascha
is working on a reply...