.NET allows to extend XSLT by using the so called extension object. Very handy and very convenient. You do so by creating a class:
public class VeryHandyExtensionFunctions
{
public string VerySmartStringConcat(XPathNodeIterator NodeList)
{
return "some very smart string concat based on NodeList";
}
}
pending some magic (see bellow) you can refer to VerySmartStringConcat as part of your xslt:
<xsl:value-of select="someprefix:VerySmartStringConcat(nodes[@withsomeattribute])"/>
The only thing to do in order to make it happen is to pass an instance of your extension class (VeryHandyExtensionFunctions above) to the XslCompiledTransform class, using a XsltArgumentList:
XsltArgumentList xsltArg = new XsltArgumentList();
xsltArg.AddExtensionObject("SomeUriResolvingToSomePrefix",new VeryHandyExtensionFunctions);
XslCompiledTransform xslTransform;
XmlWriter W = XmlWriter.Create(SomeTarget, Xslt.OutputSettings);
xslTransform.Transform(SomeXmlDocument, xsltArg, W);
.NET is fairly smart in figuring out how to convert the XML types to the input parameters & return types of the extension functions. However, every once in a while it complains about a not support type. What are the supported types?