XML
  Home arrow XML arrow Page 3 - 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 - The Scripting Scenario


    (Page 3 of 8 )

    In this example, we want to convert the following sales report document:

    <ns0:File xmlns:ns0='http://www.your-company.com/Untitled.xsd'>
      <record>
        <name>Billybob Sellemfast</name>
        <quota>3000</quota>
        <actual>7000</actual>
        <bonusplan>gold</bonusplan>
      </record>
      <record>
        <name>Rick Sellemslow</name>
        <quota>1000</quota>
        <actual>1200</actual>
        <bonusplan>silver</bonusplan>
      </record>
      <record>
        <name>Chad Selemnever</name>
        <quota>2000</quota>
        <actual>1000</actual>
        <bonusplan>gold</bonusplan>
      </record>
    </ns0:File>

    to the sales bonus report document shown below:

    <ns0:File xmlns:ns0='http://www.your-company.com/Untitled.xsd'>
      <record>
        <surname>Sellemfast</surname>
        <firstname>Bob</firstname>
        <bonus>1245</bonus>
      </record>
      <record>
        <surname>Sellemslow</surname>
        <firstname>Bob</firstname>
        <bonus>123</bonus>
      </record>
      <record>
        <surname>Selemnever</surname>
        <firstname>Bob</firstname>
        <bonus>0</bonus>
      </record>
    </ns0:File>

    For each record in the input document, a record is created in the output document. The surname and firstname element values in the output document are created from the name element in the input document. The bonus element value in the output document is created using the quota, actual, and bonusplan element values in the input document, as well as a special bonus plan lookup table. In each case, the value of the output document elements surname, firstname, and bonus are all calculated using scripts. These scripts are discussed in detail in subsequent sections.

    The lookup table is implemented as a Java Class instance. In the XSLT file, it is specified as a global bonus_table variable, instantiated in the XSLT fragment shown below:

    <xsl:variable name="bonus_table" select="cc-xslt-extensions:LookupTable.new( 'bonus_plan_table.txt','{0}%{1}',0)"/>

    This LookupTable constructor takes three parameters: the table data file name, the file format specified as a Java format string, and the primary key column number. The contents of the data file used in this example are shown below:

    gold%10000
    silver%5000
    bronze%2000

    Once this Java instance is created, the table is parsed using the Java format string, loaded into a hashed map, and hashed by the first column value (the bonus plan name). Where a script requires table lookups as part of a calculation, the Java instance is passed to the script as an additional parameter. The BSF ensures that this Java Class instance is accessible from the script. In later examples we will show how various scripts use Java Class instances passed as parameters to the script function.

    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 1 hosted by Hostway
    Stay green...Green IT