The Processor class is in the Saxon.Api namespace, which is in the saxon9he-api assembly. To reference this class from a C# program, you need a using directive for the namespace (which you have), and a reference to the assembly.

The interface net.sf.saxon.functions.ExtensionFunctionDefinition  is intended for extension functions written in Java. For extension functions written in C# or other .NET languages, I would expect you to be using the very similar interface Saxon.Api.ExtensionFunctionDefinition, and this is what Processor.RegisterExtensionFunction expects. I suspect your type mismatch is because you have confused these two types. (You can use Java extension functions via the .NET interface if you want, but that's a bit more complicated).

Is there any particular reason why your code is doing dynamic loading of the assembly containing the extension function? The whole point of the ExtensionFunctionDefinition mechanism is to make dynamic loading unnecessary - largely because it is so fragile - you don't really want hard-coded paths to the location of the code if you can avoid it.

On 20/10/2010 10:07, Saxena, Parag Behari wrote:

I am very new to saxon. I am trying to call external .net function from XSLT. Below is my code. I have implemented SaxonChartRenderer.dll using net.sf.saxon.function.ExtensionFunctionDefinition . But when try to register it in processor it is giving me type mismatch error.
Which can be due to different namespace of Saxon.Api and net.sf.saxon.
In net.sf.saxon namespace I am not able to find Processor class. I have searched it internet but not able to find any solution for this. Now I posting this here. How can we implement this?
using net.sf.saxon;
using Saxon.Api;
XmlReader xmlReader = XmlReader.Create(sourceUri);
            XmlReader xslReader = XmlReader.Create(xsltUri);
                // Create a Processor instance.
                Processor processor = new Processor();
                // Load the source document.
                //XdmNode input = processor.NewDocumentBuilder().Build(new Uri(sourceUri));
                XdmNode input = processor.NewDocumentBuilder().Build(xmlReader);
                // Create a transformer for the stylesheet.
                //XsltTransformer transformer = processor.NewXsltCompiler().Compile(new Uri(xsltUri)).Load();
                XsltTransformer transformer = processor.NewXsltCompiler().Compile(xslReader).Load();
                // Set the root node of the source document to be the initial context node.
                transformer.InitialContextNode = input;
                Assembly asm = Assembly.LoadFrom(@"C:\Projects\Projects\SaxonTestApp\extensions\SaxonChartRenderer.dll");
                object extObject = asm.CreateInstance("ChartRenderer.SaxonChartRenderer");
                if (extObject is net.sf.saxon.functions.ExtensionFunctionDefinition)
                    processor.RegisterExtensionFunction(extObject as ExtensionFunctionDefinition);
                transformer.SetParameter(new QName(new XmlQualifiedName("ibase")), new XdmAtomicValue(@"C:\Projects\Projects\SaxonTestApp\Images\"));
                transformer.SetParameter(new QName("", "", "ixsl"), new XdmAtomicValue(@"C:\Projects\Projects\SaxonTestApp\xsl\"));
                transformer.SetParameter(new QName("", "", "xmlfragment"), new XdmAtomicValue("//result[@type=\"practice:TimeSeries\"]"));
                transformer.SetParameter(new QName("", "", "vtype"), new XdmAtomicValue("monthly_revenue"));
                transformer.SetParameter(new QName("", "", "xs"), new XdmAtomicValue("actual;goal;"));
                // Create a serializer.
                StringBuilder output = new StringBuilder();
                StringWriter writer = new StringWriter(output);
                Serializer serializer = new Serializer();
                serializer.SetOutputProperty(Serializer.INDENT, "yes");
                // Transform the source XML to System.out.
                this.textBox1.Text = output.ToString();
            catch (Exception ex)
                this.textBox1.Text = ex.Message;
Parag Saxena

Important Notice to Recipients:


It is important that you do not use e-mail to request, authorize or effect the purchase or sale of any security or commodity, to send fund transfer instructions, or to effect any other transactions.  Any such request, orders, or instructions that you send will not be accepted and will not be processed by Morgan Stanley Smith Barney.


The sender of this e-mail is an employee of Morgan Stanley Smith Barney LLC. If you have received this communication in error, please destroy all electronic and paper copies and notify the sender immediately.   Erroneous transmission is not intended to waive confidentiality or privilege.  Morgan Stanley Smith Barney reserves the right, to the extent permitted under applicable law, to monitor electronic communications. By e-mailing with Morgan Stanley Smith Barney you consent to the foregoing.

------------------------------------------------------------------------------ Nokia and AT&T present the 2010 Calling All Innovators-North America contest Create new apps & games for the Nokia N8 for consumers in U.S. and Canada $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
_______________________________________________ saxon-help mailing list archived at