Project

Profile

Help

creating .Net extension functions

Added by Anonymous over 17 years ago

Legacy ID: #3984291 Legacy Poster: TMM (tmcgilvreay)

Hi, I'm having trouble creating/using my own .Net extension functions. I'm using Saxon version 8.8b. I have a C# class library with a class, "MyClass", and a static function, Hello(), which takes a string as input and returns a string. The namespace is "XSLFunctions". I made sure my DLL is signed and in the GAC, but when I try to follow the documentation: <xsl:variable name="arg" value="hello world" /> <xsl:value-of select="m:Hello($arg)" xmlns:m="clitype:XSLFunctions.MyClass"/> I get the error: C:\Program Files\Saxon 8b\bin>transform -o test.html factiva2.xml new.xslt Error at xsl:value-of on line 94 of file:///C:/Program Files/Saxon 8b/bin/new.xs lt: XPST0003: XPath syntax error at char 13 on line 94 in {m:Hello($arg)}: Cannot find a matching 1-argument function named {clitype:XSLFunctions.MyCla ss}Hello() Failed to compile stylesheet. 1 error detected. I attempted the other way specified: <xsl:variable name="arg" value="hello world" /> <xsl:value-of select="m:Hello($arg)" xmlns:m="clitype:XSLFunctions.MyClass?asm=XSLFunctions;ver=1.0.0.0;sn=dc089108649c7080"/> But that gave me a similar message. I have tried creating static methods that take no inputs, passing nothing to them, but the result is the same. What am I doing wrong? Thanks.


Replies (10)

Please register to reply

RE: creating .Net extension functions - Added by Anonymous over 17 years ago

Legacy ID: #3984515 Legacy Poster: TMM (tmcgilvreay)

oops... that was a mis-type in the <xsl:variable /> elements. I meant "select=..." not "value=..."

RE: creating .Net extension functions - Added by Anonymous over 17 years ago

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

I'm afraid there's a known bug here: see https://sourceforge.net/tracker/index.php?func=detail&amp;aid=1558459&amp;group_id=29872&amp;atid=397617 The subversion source contains a fix, but I'm rather aware that expecting users to build the .NET product on their own is asking a lot. It's time I did a patch release, but I can't promise anything.

RE: creating .Net extension functions - Added by Anonymous over 17 years ago

Legacy ID: #3991431 Legacy Poster: TMM (tmcgilvreay)

Ok, thanks! I'm looking forward to the patch release :). Thanks...

RE: creating .Net extension functions - Added by Anonymous about 17 years ago

Legacy ID: #4253931 Legacy Poster: TMM (tmcgilvreay)

Hi, Has this issue been resolved in Saxon 8.9b? I have picked this project up again and noticed a new version of Saxon, which I downloaded with the hope that it would resolve the problems I was having with creating my own extension functions in .Net and calling them in the XSLT. Still no luck, though. Thanks, Tim

RE: creating .Net extension functions - Added by Anonymous about 17 years ago

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

Yes, .Net extension functions should be working properly in 8.9. As always with .NET, the dynamic loading is pretty sensitive to getting everything exactly right. If you're having problems, start by telling us exactly what you are doing amd what effect it is having.

RE: creating .Net extension functions - Added by Anonymous about 17 years ago

Legacy ID: #4254050 Legacy Poster: TMM (tmcgilvreay)

Thanks. Ok, here goes. I created a Class library project in C#, called "XSLFunctions," with one class in it, called MyClass. Here is the code: using System; using System.Collections.Generic; using System.Text; namespace XSLFunctions { public class MyClass { public static string Hello(string s) { return "Hello"; } } } I build the DLL, it is signed and GAC'd. In Windows/Assembly, I see the following info for it: Assembly Name=XSLFunctions, Version=1.0.0.1, Culture=Neutral, Public Key token=dc089108649c7080, Processor Architecture=MSIL I have a very basic XSLT file, for testing purposes, that looks like this: <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <xsl:variable name="arg" select="test" /> <xsl:value-of select="m:Hello($arg)" xmlns:m="clitype:XSLFunctions.MyClass?asm=XSLFunctions;ver=1.0.0.1;sn=dc089108649c7080"/> </body> </html> </xsl:template> </xsl:stylesheet> When I do the command-line "Transform" with a simple xml file, I get the following error: Loading clitype:XSLFunctions.MyClass?asm=XSLFunctions;ver=1.0.0.1;sn=dc089108649c7080 No Java class clitype:XSLFunctions.MyClass?asm=XSLFunctions;ver=1.0.0.1;sn=dc089108649c7080 could be loaded Error at xsl:value-of on line 10 of file:///C:/Program Files/Saxon 8b/bin/exttes t.xslt: XPST0003: XPath syntax error at char 13 on line 10 in {m:Hello($arg)}: Cannot find a matching 1-argument function named {clitype:XSLFunctions.MyClass?asm=XSLFunctions;ver=1.0.0.1;sn=dc089108649c7080}Hello() Failed to compile stylesheet. 1 error detected. I tried just using what the documentation says for static functions: <xsl:variable name="arg" select="test" /> <xsl:value-of select="m:Hello($arg)" xmlns:m="clitype:XSLFunctions.MyClass"/> But that has the same problem What am I missing? :) Thanks!

RE: creating .Net extension functions - Added by Anonymous about 17 years ago

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

What diagnostics do you get when you use the -TJ option? Michael Kay

RE: creating .Net extension functions - Added by Anonymous about 17 years ago

Legacy ID: #4254090 Legacy Poster: TMM (tmcgilvreay)

Here is the command-line and the full results C:\Program Files\Saxon 8b\bin>transform -TJ -o test1.html test1.xml exttest.xslt Loading clitype:XSLFunctions.MyClass?asm=XSLFunctions;ver=1.0.0.1;sn=dc089108649 c7080 No Java class clitype:XSLFunctions.MyClass?asm=XSLFunctions;ver=1.0.0.1;sn=dc089 108649c7080 could be loaded Error at xsl:value-of on line 10 of file:///C:/Program Files/Saxon 8b/bin/exttes t.xslt: XPST0003: XPath syntax error at char 13 on line 10 in {m:Hello($arg)}: Cannot find a matching 1-argument function named {clitype:XSLFunctions.MyClass?asm=XSLFunctions;ver=1.0.0.1;sn=dc089108649c7080 }Hello() Failed to compile stylesheet. 1 error detected.

RE: creating .Net extension functions - Added by Anonymous about 17 years ago

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

It looks as if my test cases were either (a) running from the command line and calling extension functions either in the .NET system classes or in Saxon itself, or (b) running from a user-written application and calling extension functions in an assembly where the user-written application declared a reference to the assembly containing the extension function. I'll work on it. Clearly the first thing is to improve the diagnostics.

RE: creating .Net extension functions - Added by Anonymous about 17 years ago

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

Running Transform from the command line, I've successfully loaded an assembly Ext.dll containing extension functions using the following techniques: 1. Copy Ext.dll into the directory containing the Transform command and reference it as xmlns:ext="clitype:Namespace.ClassName?asm=Ext" 2. Use the location of Ext.dll xmlns:ext="clitype:Namespace.ClassName?from=file:///c:/lib/Ext.dll" (this can also be a relative address, but it is currently relative to the current directory; I intend to change this so that it is relative to the base URI of the stylesheet) 3. Give the assembly a strong name, copy it into the GAC, and load it using partial name: xmlns:ext="clitype:Namespace.ClassName?partialname=Ext" What doesn't appear to work is loading by strong name. I haven't worked out why; however, I've changed the code to construct the fully-qualified assembly name as a string rather than as an AssemblyName object, and that appears to work. So I'll put the changed code as a patch into Subversion, and it will appear next time I do a maintenance build. Michael Kay

    (1-10/10)

    Please register to reply