|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Extension functions in XT (was Re: HTML forms with XSLT slid
On Mon, Sep 27, 1999 at 12:49:28PM +0700, James Clark wrote:
> Beyond that is the issue of allowing extension functions to be written
> in other languages. In particular it would be nice to support
> JavaScript (using Rhino).
I've had some success using FESI with XT
<http://home.worldcom.ch/~jmlugrin/fesi/>, license here:
<http://home.worldcom.ch/~jmlugrin/fesi/copyright.html>
using a small glue class to define the following ECMAScript extension
functions:
ecma:include-file(), interprets an external ECMAScript file
ecma:interpret(), interprets the argument as ECMAScript and uses the
result as a resultfragment
ecma:interpret-silent(), interprets the argument as ECMAScript and
suppresses any return value
I've not tried yet with JPython, but I don't imagine it would be too
difficult (I can send the source code to anyone who's interested).
I can then invoke the ECMAScript either explicitly in my stylesheet or
define a template to catch a specific tag and then execute its text
contents as script.
Some obvious unwieldiness occurs, e.g. defining a function to wrap
double quotes around a string:
<xsl:value-of select="ecma:interpret('
function quote(d) { return "\""+d+"\""; }
')"/>
Although this goes away if all the functions are put in an external
file and I use include-file() instead.
One problem that I've come across, and I may have already received an
answer from James (but I had some ISP problems recently and so wouldn't
know if I had or not!), is this:
It would be very very useful if extension functions could return Nodes
to be subsequently fed to the stylesheet. However I have a suspicion
that extension functions are only allowed within the WD to return parts
of a Result. What I'd like to be able to do is define a function which
returns a Node structure, and then say:
<xsl:apply-templates select="myfn:createMeNodes()"/>
An example application of this would be in servlet pages for grabbing in
session information from the web server and formatting it.
I know it's possible to hand back Nodes in XT and have it work properly,
as I can construct an identity function which just hands back the Nodes
it gets, but that's as far as I can get. I suspect this is because of
what James writes here:
> Closely related is the issue of supporting extension elements. I
> haven't yet tried to implement this, so I'm very open to suggestions.
> The one major constraint that may be peculiar to XT is that the public
> interfaces to XT are based on SAX not DOM, and I want to keep it that
> way.
Does this mean there's a SAX way I can do what I want?
Or is what I'm trying to do more suited to extension elements?
> James
Help appreciated.
Edd
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








