June 2008
Intermediate to advanced
986 pages
27h 8m
English
We’ll use Mozilla’s Rhino JavaScript engine to illustrate JavaScript support. We define the
namespace prefix javascript-extension and associate it with
the URI http://www.mozilla.org/rhino. The JavaScript
code looks like this:
<?xml version="1.0"?> <!-- piechart-javascript.xsl --> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:svg="http://www.w3.org/2000/svg" xmlns:months="http://www.oreilly.com/xslt/months" xmlns:lxslt="http://xml.apache.org/xslt" xmlns:javascript-extension="http://www.mozilla.org/rhino" extension-element-prefixes="javascript-extension" exclude-result-prefixes="lxslt"> ... <lxslt:component prefix="javascript-extension" functions="cos sin"> <lxslt:script lang="javascript"> function cos(d) { return Math.cos(d); } function sin(d) { return Math.sin(d); } </lxslt:script> </lxslt:component>
To use these extension functions, your CLASSPATH must contain
js.jar, available at http://www.mozilla.org/rhino, in addition to
bsf.jar and commons-logging-1.1.jar.
Read now
Unlock full access