Scripting Extension Function Using Inline Script Code

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xslt"
xmlns:trig="http://www.acmeX.com/extend/trig">
  
<xalan:component prefix="trig" functions="sin cons tan atan">
  <xalan:script lang="javascript">
    function sin (arg){ return Math.sin(arg);} 
    function cos (arg){ return Math.cos(arg);} 
    function tan (arg){ return Math.tan(arg);} 
    function atan (arg){ return Math.atan(arg);} 
  </xalan:script>
</xalan:component>
   
<xsl:variable name="PI" select="4.0 * trig:atan(1.0)"/>
   
<!-- ... -->
   
</xsl:stylesheet>

Saxon currently supports JavaScript, NetRexx, BML, JPython, Jacl, JScript, VBScript, and PerlScript, but appropriate extensions need to be obtained from third parties supporting the respective languages. See http://xml.apache.org/xalan-j/extensions.html#supported-lang for details.

Get XSLT Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.