Project

Profile

Help

Passing a .NET instance through paramater

Added by Anonymous almost 17 years ago

Legacy ID: #4671687 Legacy Poster: Thibault (thibault-g)

Hi, I read on the documentation (http://www.saxonica.com/documentation/extensibility/dotnetextensions/instance-methods.net.html) that it's possible to provided an intancied instance to a global parameter. I'm using SAXON 9b API for .NET My problem is with the .NET API : { //INIT SAXON ENGINE Processor processor = new Processor(); XsltTransformer xsltTransformer = processor.NewXsltCompiler(); [...] //TRY TO PASS AN INSTANCE MyClass myClass = new MyClass( ... ,..., ... ); [...] QName qName = new QName( string.Empty, string.Empty, "myParameter" ); xsltTransformer.SetParameter( qName, ? ); } the XdmAtomicValue class don't allow me to pass an object, XdmValue don't allow to use anything else than an enumeration of XdmItem So I don't know if it's possible to do that or if I have to use static method instead (I can't use a constructor inside the xslt because of the heavy initialyzation cost of my class) Regards Thibault


Replies (5)

Please register to reply

RE: Passing a .NET instance through paramater - Added by Anonymous almost 17 years ago

Legacy ID: #4672692 Legacy Poster: Michael Kay (mhkay)

Yes, sorry, the API doesn't make this easy. I think it might be possible by resorting to the static method XdmValue.Wrap(new net.sf.saxon.value.ObjectValue(obj)) where net.sf.saxon.value.ObjectValue is a class found in saxon9.dll I'll remedy this omission for the next release. Michael Kay http://www.saxonica.com/

RE: Passing a .NET instance through paramater - Added by Anonymous almost 17 years ago

Legacy ID: #4673665 Legacy Poster: Thibault (thibault-g)

Thank for your time, Your C# code works, but it seems to be difficult to use this object (call method) from the XSL : //C# : MyClass myClass = new MyClass(); transformer.SetParameter(new QName("", "", "myClass"), XdmValue.Wrap(new net.sf.saxon.value.ObjectValue(myClass))); //XSLT <xsl:param name="myClass"/> <xsl:value-of select="$myClass"/> -> return MyNamespace.MyClass (default ToString()) but : {MyClass:ToString($myClass)} don't work even if xmlns:MyClass="clitype:MyNamespace.MyClass?asm=MyDll" was set correctly before. i think i'm going to build satic wrappers instead, and that's work fine. Thanks again for your answer and for this great API. Best regards Thibault

RE: Passing a .NET instance through paramater - Added by Anonymous almost 17 years ago

Legacy ID: #4675503 Legacy Poster: Thibault (thibault-g)

Thank for your time, Your C# code works, but it seems to be difficult to use this object (call method) from the XSL : //C# : MyClass myClass = new MyClass(); transformer.SetParameter(new QName("", "", "myClass"), XdmValue.Wrap(new net.sf.saxon.value.ObjectValue(myClass))); //XSLT <xsl:param name="myClass"/> <xsl:value-of select="$myClass"/> -> return MyNamespace.MyClass (default ToString()) but : {MyClass:ToString($myClass)} don't work even if xmlns:MyClass="clitype:MyNamespace.MyClass?asm=MyDll" was set correctly before. i think i'm going to build satic wrappers instead, and that's work fine. Thanks again for your answer and for this great API. Best regards Thibault

RE: Passing a .NET instance through paramater - Added by Anonymous almost 17 years ago

Legacy ID: #4675933 Legacy Poster: Michael Kay (mhkay)

>transformer.SetParameter(new QName("", "", "myClass"), XdmValue.Wrap(new net.sf.saxon.value.ObjectValue(myClass))); I regret I misadvised you here. Please use instead: transformer.SetParameter(new QName("", "", "myClass"), XdmValue.Wrap(new net.sf.saxon.dotnet.DotNetObjectValue(myClass))); However, I'm going to change it so you don't have to go directly into the saxon9 DLL to achieve this.

RE: Passing a .NET instance through paramater - Added by Anonymous almost 17 years ago

Legacy ID: #4675947 Legacy Poster: Michael Kay (mhkay)

It turns out there is a method in the API already that you can use: transformer.SetParameter(new QName("", "", "myClass"), XdmAtomicValue.wrapExternalObject(myClass)); Michael Kay

    (1-5/5)

    Please register to reply