XML
  Home arrow XML arrow Page 7 - 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  
Mobile Linux 
App Generation ROI 
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
     
     
    ADVERTISEMENT


    Using Script Extensions in Xalan-Java - PerlScript


    (Page 7 of 8 )

    PerlScript is based on the PerlScript interpreter provided by http://www.activestate.com.

    Configuration

    This requires the exact same configuration as that required for VBScript. In addition, the ActiveState Perl interpreter must be installed on the same machine as the stylesheet processor.

    Simple Function without a JavaBean Parameter

    The function below shows how PerlScript is used to calculate the surname output element using the name input element value.

    sub calculate_surname
    {
     my ( $name ) = @_;               
           @tokens = split(" ",$name);
           return @tokens[1];
    }

    The first line is not strictly necessary, but copying the parameters from the standard @_ parameters array into a list of named parameters makes the script more readable.

    The XSLT function call is:

    <xsl:value-of select="perlscript:calculate_surname( string(name) )"/>

    Function with JavaBean Processing

    The function below shows how VBScript is used to calculate the bonus value. Again, as this is an ActiveScript, it requires the same workaround as before when passing JavaBean instances.


     sub calculate_bonus
    {
     my ( $quota, $actual, $bonusplan, $bonus_table_bean_name ) = @_;                    
          
     # set up lookup table variables
           $bonus_table = $bsf->lookupBean( $bonus_table_bean_name );
          
     # find base bonus from lookup table
     $bonus_base = $bonus_table->lookUp($bonusplan,1) ;
                   
           # calculate multiple, bonus multiple is zero if they underperform                   
           $multiple = $actual > $quota ? $actual / $quota : 0.0 ;
                   
           return $bonus_base * $multiple;               
    }
                        
     

    Because PerlScript is loosely typed, it is not necessary to convert the string retrieved from the lookup table into a float.

    The XSLT function call is:

    <xsl:value-of select="perlscript:calculate_bonus( number(quota), number(actual), string(bonusplan), $bonus_table )"/>

    More XML Articles
    More By Seamus Donohue


     

    XML ARTICLES

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






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT