Re: [xsl] Embedding javascript code into the XSL

Subject: Re: [xsl] Embedding javascript code into the XSL
From: "J.Pietschmann" <j3322ptm@xxxxxxxx>
Date: Wed, 01 May 2002 21:24:30 +0200
David Carlisle wrote:

The normal extension language for the java XSLT engines is java rather
than javascript (but you need to check the docs for each processor)

Xalan can be extended using JavaScript. It does so, of course, in a slightly different way that MSXML. You'll need bsf.jar (the Bean Scripting Framework) an a JavaScript implementation (i used rhino I think bsf.jar is already distributed with Xalan.

Here is an example on how to define and use JavaScript
functios in Xalan:

<?xml version='1.0' encoding='ISO-8859-1' ?>
<xsl:stylesheet version="1.0"
  <lxslt:component prefix="counter" functions="count">
    <lxslt:script lang="javascript">
   var i = 1;
   function count() {
      return i;

  <xsl:template match="/">
    <xsl:value-of select="counter:count()" />
    <xsl:value-of select="counter:count()" />

Note that you should really know what you are doing,
your stylesheets will be non-protable and have a good
chance to grow into a maintenance nightmare.


XSL-List info and archive:

Current Thread