Using Script Extensions in Xalan-Java - Xalan-Java Scripting Extensions, Resources, Requirements
(Page 2 of 8 )
Xalan-Java (Xalan-J) supports extension elements and functions written in scripting languages supported by the Bean Scripting Framework (BSF). A complete explanation of this support is available in the Xalan-Java documentation at http://xml.apache.org/xalan-j/extensions.html.
This article looks only at function extensions, that is, calling script functions from XSLT. We will look at scripting languages that are not covered in the Xalan documentation, in particular, Python, VBScript, and PerlScript. In addition, we will show how Java Object instances, created in XSLT as part of the Java language extensions mechanism, are passed to these scripts and utilized by them. These samples will provide a solid foundation on which to build more complicated script-based extensions.
Resources Provided with this Article
The resources listed in the following table are provided with this article:
| Resource | Description |
| build.xml | Ant build script used to build and run the sample XSLT script. |
| build.properties | Properties used by the Ant script. |
| xml/bonus_plan_table.txt | The data used by the Java lookup bean used in the XSLT script. |
| xml/sample_in.xml | Sample input XML file. |
| xml/sample_in.xsd | Input XML document schema. |
| xml/sample_out.xsd | Output document schema. |
| xml/sample_rules.xslt | The XSLT stylesheet used in this article. |
| src/../LookupTable.java | The LookupTable Bean class used in the stylesheet. |
| src/../ActiveScriptEngine.java | The patched BSF Java code required to support ActiveScripts. |
Software Requirements to Run the Example Provided with this Article
The script extensions described in this article are based on Xalan-J version 2.6.0, which is available from http://xml.apache.org/xalan-j. You will also need a recent version of Ant to run the sample XSLT provided. The sample XSLT uses JavaScript, Jython, PerlScript, and VBScript. The requirements for each scripting language are listed in the following table:
| Script | Requirements |
| JavaScript | Require js.jar, which is available from ftp://ftp.mozilla.org/pub/js/rhino15R4.zip. |
| Python | Requires jython.jar, which is available from http://www.jython.org/download.html. |
| VBScript (Win32 only) | Requires bsfactivescriptengine.dll, bsfactivescriptengine_g.dll, and msvcp60.dll, which are available in the BSF 2.2 download from http://oss.software.ibm.com/developerworks/projects/bsf. |
| PerlScript (Win32 only) | Requires the same DLLs as above for VBScript and the installation of PerlScript from http://www.activestate.com/. |
The required JAR files must be in the classpath used by the Xalan processor. The active script DLL libraries directory must be added to the PATH environment variable. The directory containing the DLL may also be specified as a property passed to the JVM java.library.path property, for example:
java -Djava.library.path=D:/apps/bsf-2_2/lib/win32 etc.
BSF Requirements
BSF version 2.2 is supplied with Xalan-J (see http://oss.software.ibm.com/developerworks/projects/bsf). This code is now superseded by BSF 2.3 (see http://jakarta.apache.org/bsf/index.html); however, Xalan continues to integrate with the BSF 2.2 code base. It is not possible to replace the BSF 2.2 JAR file with the BSF 2.3 JAR file, because package names and APIs have changed. The BSF 2.2 jar is sufficient to run JavaScript and Python scripts; however, it will not correctly run the Win32 ActiveScripts (VBScript, PerlScript, and so on). To run these scripts correctly, it is necessary to patch the BSF 2.2 JAR file supplied with Xalan. The patch procedure is described in the appendix at the end of this article.
Next: The Scripting Scenario >>
More XML Articles
More By Seamus Donohue