Subject: [xsl] Writing extension functions (& elements) From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Wed, 31 Jan 2001 11:22:54 +0000 |
I said: > : Yes, but be aware that Javascript isn't incorporated into XSLT until > : XSLT 1.1 or unless you're using MSXML. Eugene pointed out: > The binding mechanism wasn't standardized in XSLT 1.0, same as Java, > but there are several implementations besides MSXML... Unicorn XSLT > processor has one, for example, and I believe Xalan does too. Eugene's absolutely right, of course, although I can't see any way in Unicorn XSLT to include Javascript *in the stylesheet itself* - I think you have to import a script using obj:import (obj being bound to http://www.unicorn-enterprises.com/XSLT/Extensions/ECMAScript/1.0) and then can call a function in that script either with function syntax like obj:call(object, function, arguments*) or with element syntax. I'd be pleased to be corrected - this is just what I've gathered from a quick read of the documentation. Xalan-Java has some Really Cool Stuff that enables you to define not only your own functions, but also your own elements, actually within a stylesheet. You can also use loads of different languages to define them (though not, sadly, XSLT ;) Using a Javascript function in XSLT when you're using Xalan involves the same kind of preparatory steps as using msxsl:script: (a) declaring the Xalan namespace (http://xml.apache.org/xslt) - for some reason the Xalan documentation uses the prefix lxslt (b) declaring your own namespace (e.g. http://www.foo.com/) (c) declaring the namespace prefixes you use as extension element prefixes You need to use two extension elements to define functions when using Xalan: lxslt:component and lxslt:script. The equivalent of the msxsl:script element: <msxsl:script language="javascript" implements-prefix="foo"> function retrieveData() { return true; } </msxsl:script> is: <lxslt:component prefix="foo" functions="retrieveData"> <lxslt:script lang="javascript"> function retrieveData() { return true; } </lxslt:script> </lxslt:component> While msxsl:script will disappear when XSLT 1.1 is finalised and supported, it looks as though lxslt:component and lxslt:script will still have a place because they allow you to write your own extension elements as well. Does anyone have any experience with writing extension elements in Xalan that they could share? Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Re:, Kaganovich, Yevgeniy | Thread | Re: [xsl] Writing extension functio, Alexey Gokhberg |
[xsl] What is the benefit of xml ov, Ashish Patidar | Date | Re: [xsl] xsl, position, template P, David Carlisle |
Month |