[xsl] Re:

Subject: [xsl] Re:
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Mon, 29 Jan 2001 21:19:12 +0000
Hi Frank,

> please, is there any way to affect an xml variable with the output
> return of a JavaScript function ?

Yes, but be aware that Javascript isn't incorporated into XSLT until
XSLT 1.1 or unless you're using MSXML.  The first thing that you need
to do is to declare the function within an msxsl:script element:

<msxsl:script language="javascript"
   function retrieveData() {
      return true;

In order to do this, you need to declare the 'msxsl' namespace
(urn:schemas-microsoft-com:xslt) and your own 'foo' namespace. The
'msxsl' namespace needs to be declared as an extension element prefix
(using the extension-element-prefixes attribute on xsl:stylesheet) and
the 'foo' namespace should be excluded from your result tree (using
the exclude-result-prefixes or extension-element-prefixes attribute on

Once you've declared the Javascript functions like this, you can call
them within any XPath expression using, e.g.:


So, to set $my_var to have the value returned by the function, use:

  <xsl:variable name="my_var" select="foo:retrieveData()" />

There's nothing in XSLT that interprets the content of an element as
something to run: calls to functions are *always* in attribute values.
I hope that helps,


Jeni Tennison

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread