Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the allowed .NET return types from a XSLT extension object method?

Tags:

c#

.net

xslt

.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?

like image 568
Boaz Avatar asked Dec 13 '08 20:12

Boaz


1 Answers

After some research I found this on http://msdn.microsoft.com/en-us/magazine/bb986125.aspx :

3C XPath Type -> Equivalent .NET Class (Type)
String -> System.String
Boolean -> System.Boolean
Number -> System.Double
Result Tree Fragment -> System.Xml.XPath.XPathNavigator
Node Set -> System.Xml.XPath.XPathNodeIterator

like image 84
Boaz Avatar answered Nov 15 '22 17:11

Boaz