Home arrow XML arrow Page 2 - Using Script Extensions in Xalan-Java
XML

Using Script Extensions in Xalan-Java


This article 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.

Author Info:
By: Seamus Donohue
Rating: 5 stars5 stars5 stars5 stars5 stars / 14
June 16, 2004
TABLE OF CONTENTS:
  1. · Using Script Extensions in Xalan-Java
  2. · Xalan-Java Scripting Extensions, Resources, Requirements
  3. · The Scripting Scenario
  4. · Plugging the Scripts into the XSLT Stylesheet
  5. · Python
  6. · VBScript
  7. · PerlScript
  8. · Running the Stylesheet

print this article
SEARCH DEVARTICLES

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.xmlAnt build script used to build and run the sample XSLT script.
build.propertiesProperties used by the Ant script.
xml/bonus_plan_table.txtThe data used by the Java lookup bean used in the XSLT script.
xml/sample_in.xmlSample input XML file.
xml/sample_in.xsdInput XML document schema.
xml/sample_out.xsdOutput document schema.
xml/sample_rules.xsltThe XSLT stylesheet used in this article.
src/../LookupTable.javaThe LookupTable Bean class used in the stylesheet.
src/../ActiveScriptEngine.javaThe 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:

ScriptRequirements
JavaScriptRequire js.jar, which is available from
ftp://ftp.mozilla.org/pub/js/rhino15R4.zip.
PythonRequires 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.


blog comments powered by Disqus
XML ARTICLES

- Open XML Finally Supported by MS Office
- XML Features Added to Two Systems
- Using Regions with XSL Formatting Objects
- Using XSL Formatting Objects
- More Schematron Features
- Schematron Patterns and Validation
- Using Schematron
- Datatypes and More in RELAX NG
- Providing Options in RELAX NG
- An Introduction to RELAX NG
- Path, Predicates, and XQuery
- Using Predicates with XQuery
- Navigating Input Documents Using Paths
- XML Basics
- Introduction to XPath

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials