[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

Subject: Extension functions in XT (was Re: HTML forms with XSLT slideshow question)
From: Edd Dumbill <edd@xxxxxxxxxxxxx>
Date: Mon, 27 Sep 1999 12:30:56 +0000
xslt formatting forms
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 &quot;\&quot;&quot;+d+&quot;\&quot;&quot;; }
')"/>

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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.