XML
  Home arrow XML arrow Using Script Extensions in Xalan-Java
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
VeriSign Whitepapers 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML

Using Script Extensions in Xalan-Java
By: Seamus Donohue
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 9
    2004-06-16

    Table of Contents:
  • Using Script Extensions in Xalan-Java
  • Xalan-Java Scripting Extensions, Resources, Requirements
  • The Scripting Scenario
  • Plugging the Scripts into the XSLT Stylesheet
  • Python
  • VBScript
  • PerlScript
  • Running the Stylesheet

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
    Iron Speed
     
    ADVERTISEMENT

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Using Script Extensions in Xalan-Java


    (Page 1 of 8 )

    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.


    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:

    <report>
    <sales>100</sales>
    <plan>gold</plan>
    </report>

    into this one:

    <commission>75</commission>

    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:choose>
     <xsl:when test="bonusplan = 'silver'">
      <xsl:value-of select="actual * 0.50"/>
     </xsl:when>
     <xsl:when test="bonusplan = 'gold'">
      <xsl:value-of select="actual * 0.75"/>
     </xsl:when>
     <xsl:otherwise>                   
      <xsl:value-of select="0"/>
     </xsl:otherwise>
    </xsl:choose>

    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. 

    More XML Articles
    More By Seamus Donohue


     

    XML ARTICLES

    - Path, Predicates, and XQuery
    - Using Predicates with XQuery
    - Navigating Input Documents Using Paths
    - XML Basics
    - Introduction to XPath
    - Simple Web Syndication with RSS 2.0
    - Java UI Design with an IDE
    - UI Design with Java and XML Toolkits
    - Displaying ADO Retrieved Data with XML Islan...
    - Widget Walkthrough
    - Introduction to Widgets
    - The Why and How of XML Data Islands
    - Creating an XUL App Installer
    - Overlays in XUL
    - Skinning Your Custom XUL Applications


    Iron Speed





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway