XML
  Home arrow XML arrow Page 5 - 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 
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 - Python


    (Page 5 of 8 )

    Python support is based on the Java Python Interpreter Jython version 2.1 from http://www.jython.org.

    Configuration

    Ensure that the jython.jar file is in the classpath used by the XSLT processor.

    Simple Function without a JavaBean Parameter

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

    def calculate_surname( name ) :                       
     return name.split(" " )[1]

    The XSLT function call is

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

    Note that for the in-line Python script, the def statement must start in column 0, otherwise a fault occurs during the Python script compilation.

    Function with JavaBean Processing

    The function below shows how a Python script is used to calculate the bonus value, in a similar fashion as described above in the JavaScript section. 

    def calculate_bonus( quota, actual, bonusplan, bonus_table ) :               
     """ find base bonus from lookup table """
     bonus_base = long ( bonus_table.lookUp(bonusplan,1), 10 )
                   
     """ calculate multiple, bonus multiple is zero if they underperform """
     if actual > quota :
            multiple = actual / quota
                 return multiple * bonus_base
        else :
            return 0.0
     

    Again, the def keyword must start in column 0. Also, in Jython, blocks are determined by indentation and therefore must be preserved in the stylesheet. JavaBean handling is exactly the same for both Jython and JavaScript.

    The XSLT function call is:

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

    More XML Articles
    More By Seamus Donohue


     

    XML ARTICLES

    - 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
    - Simple Web Syndication with RSS 2.0
    - Java UI Design with an IDE







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek