XML
  Home arrow XML arrow Page 6 - 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  
Moblin 
JMSL Numerical Library 
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 - VBScript


    (Page 6 of 8 )

    VBScript is based on ActiveScript support on Windows platforms. For more information, see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vbswhat.asp.

    Configuration

    The VBScript interpreter is implemented in extension DLLs. The required DLLs are shipped with the BSF 2.2 binary installation in the <BSF 2.2 home dir>libwin32 directory.

    Ensure that the following JVM parameter is set on the XSLT processor JVM:

    -Djava.library.path=<BSF 2.2 home dir>/lib/win32

    Unlike the two previous examples (JavaScript and Jython), the patched bsf.jar file (see the appendix for details) is required to use VBScript (or any other ActiveScript, such as JScript or PerlScript). The patched bsf.jar file (not the bsf.jar file that is shipped with Xalan) must be placed in the XSLT processor classpath.

    Simple Function without a JavaBean Parameter

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

    Function calculate_surname( Name )
     Dim Tokens 
       Tokens = Split( Name )
       calculate_surname = RTrim(Tokens(1))
    End Function

    The XSLT function call is:

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

    Even though VBScript is a loosely typed scripting language, it is still very important to coerce script function parameters to the appropriate XSLT type. The BSF ActiveScript engine will pass simple types directly to the VBScript by invoking toString() operations on the parameter type (strings are a special case, because they are also enclosed in quotes). Any type which is not a simple type or a string is treated as a bean and dealt with differently (as discussed below).

    Function with JavaBean Processing

    The function below shows how VBScript is used to calculate the bonus value. Note that VBScript treats the JavaBean parameter differently from Python or JavaScript. Because the ActiveScript engine is not implemented in Java, it is not possible to pass the JavaBean parameter directly to the script. Instead the patched bsf.jar file declares the bean parameter to the Bean Scripting Framework (BSF). The JavaBean parameter is then substituted with the declared bean name. The script must then retrieve the JavaBean from the BSF using this name. This layer of indirection introduces a slight complication, but without this mechanism, it would not be possible to pass the JavaBean parameter as is.

    Function calculate_bonus(Quota, Actual, Bonusplan, Bonus_Table_Name)
     ' retrieve the bean from bsf
     Set Bonus_Table = bsf.lookupBean( CStr(Bonus_Table_Name) )
         
     ' find base bonus from lookup table
     Bonus_Base = Bonus_Table.lookUp(Bonusplan,1)
                                   
     ' calculate multiple, bonus multiple is zero if they underperform                
    If Actual > Quota Then
         Multiple = Actual / Quota
          calculate_bonus = Bonus_Base * Multiple
       Else
         calculate_bonus = 0.0
       End If
    End Function

    Because VBScript 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="vbscript:calculate_bonus( number(quota), number(actual), string(bonusplan), $bonus_table )"/>

    Again, there is no difference in the XSLT function call except for the namespace. The bonus_table variable is passed as is; however, the corresponding parameter in the function declaration for this parameter will be the BSF-declared bean name, as opposed to the bean itself (as explained above).

    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