Home arrow XML arrow 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
(Page 1 of 8 )

Find support files for this article here.

Why Use Scripting in XSLT?

Extensible Stylesheet Language Transformations (XSLT) is an ideal language for building transformations that convert a group of XML elements into another structure. However, when it comes to transforming element values, it may be more appropriate to use different scripting languages. For example, letís say we want to transform the following document:


into this one:


where the commission element value is calculated as follows:

if plan is silver then commission = 50% of sales
else if plan is gold then commission = 75% of sales

The XSLT author may choose to implement this rather simple transformation algorithm in JavaScript as:

if (bonusplan.equals('silver'))
 return actual * 0.50;
else if (bonusplan.equals('gold'))
 return actual * 0.75;
else return 0;

rather than in XSLT as:

 <xsl:when test="bonusplan = 'silver'">
  <xsl:value-of select="actual * 0.50"/>
 <xsl:when test="bonusplan = 'gold'">
  <xsl:value-of select="actual * 0.75"/>
  <xsl:value-of select="0"/>

Switching from XSLT to another scripting language makes sense when:

  • The other scripting language is easier to write than XSLT. For example, if the scripting language supports facilities that XSLT does not such as native regular expressions or easy database access features.
  • The script exists already - there is no need to port the transformation to XSLT!
  • The programmer is already very proficient in that scripting language.

This article explores how programmers can fully exploit XSLT scripting extension support in Xalan-Java. 

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