Writing Extensions in Other Languages

One of the nice features of Xalan-J’s extension mechanism is that it supports the Bean Scripting Framework (BSF), an open source library from the Apache Software Foundation that allows you to execute code written in a variety of scripting languages. We’ll take the SVG stylesheet we just discussed and implement it again, writing the extension functions in a variety of other languages. For our first example, we’ll look at all the details of defining and invoking BSF extension functions; for the subsequent examples, we’ll simply highlight the differences.

The Bean Scripting Framework supports many languages, including JRuby, Jython, Groovy, Jacl, NetRexx, PerlScript, Tcl, and VBScript. If you’re using a Microsoft platform, BSF also supports Windows Script Technologies, so you may have even more choices if you’re running some flavor of Windows.

Using the BSF requires two files on your CLASSPATHbsf.jar, which is available at http://jakarta.apache.org/bsf/index.html, and commons-logging-1.1.jar, which is available at http://jakarta.apache.org/commons/logging/—in addition to the JAR files for the language you’re using. We’ll point out those requirements as we go. Also be aware that system requirements can change; earlier versions of the BSF did not require the logging component.

Get XSLT, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.