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

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
  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

Using Script Extensions in Xalan-Java - The Scripting Scenario
(Page 3 of 8 )

In this example, we want to convert the following sales report document:

<ns0:File xmlns:ns0='http://www.your-company.com/Untitled.xsd'>
    <name>Billybob Sellemfast</name>
    <name>Rick Sellemslow</name>
    <name>Chad Selemnever</name>

to the sales bonus report document shown below:

<ns0:File xmlns:ns0='http://www.your-company.com/Untitled.xsd'>

For each record in the input document, a record is created in the output document. The surname and firstname element values in the output document are created from the name element in the input document. The bonus element value in the output document is created using the quota, actual, and bonusplan element values in the input document, as well as a special bonus plan lookup table. In each case, the value of the output document elements surname, firstname, and bonus are all calculated using scripts. These scripts are discussed in detail in subsequent sections.

The lookup table is implemented as a Java Class instance. In the XSLT file, it is specified as a global bonus_table variable, instantiated in the XSLT fragment shown below:

<xsl:variable name="bonus_table" select="cc-xslt-extensions:LookupTable.new( 'bonus_plan_table.txt','{0}%{1}',0)"/>

This LookupTable constructor takes three parameters: the table data file name, the file format specified as a Java format string, and the primary key column number. The contents of the data file used in this example are shown below:


Once this Java instance is created, the table is parsed using the Java format string, loaded into a hashed map, and hashed by the first column value (the bonus plan name). Where a script requires table lookups as part of a calculation, the Java instance is passed to the script as an additional parameter. The BSF ensures that this Java Class instance is accessible from the script. In later examples we will show how various scripts use Java Class instances passed as parameters to the script function.

blog comments powered by Disqus

- 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 

Developer Shed Affiliates


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