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.
Copyright © 2006 O'Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from "XSLT Kochbuch" is subject to the same terms as the printed edition: the work and all its parts are protected by copyright. All rights are reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O'Reilly Verlag GmbH & Co. KG, Balthasarstraße 81, 50670 Köln, kommentar(at)oreilly.de
back to top