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