XML technologies / XSLT / XSLT Kochbuch / Extending and embedding XSLT / Writing an extension function with inline script code

(Excerpt from "XSLT Kochbuch" by Sal Mangano)

<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 the extensions for these languages must be obtained from third parties. For details, see Xalan-Java-Extensions.

  

 

 

 

back to top