sinus or cosinus in xslt?

Hi!

is it possible to use sinus or cosinus in my stylesheet?
As an example I have the following variable:

 <xsl:variable name="x" select="60"/> </pre> <BR><BR>Now I want to create a second variable which is the sinus of x. It must be something like this:<BR><BR> <pre class="ip-ubbcode-code-pre"> <xsl:variable name="sinx" select="SIN($x)"/> 



How can I do this???
Thanks for answering
tam

Hello there,

The sin implementation is not provided as is into the XSLT 1.0 standard. However you might use the EXSLT implementation to perform a sin computation.

Have a look at : EXSL > Math page

… provided your XSLT engine supports EXSLT (eg Xalan).

Or, alternatively, you could use an extension function (call Java/PHP/DCOM code from your XSL).

Feel free to ask for more if you need enhanced help.

Cheers.

Bertrand Martel
Software AG France

Hi Bertrand.

thanks for your help. Can you show me an example how to call Java from my xsl. would be nice :slight_smile:

tam

Hi tam,

First of all, could you please tell me which XSLT engine are you using ? Calling java from an XSLT is vendor specific (ie not standard).

Besides, calling EXSLT is the best option, IMHO.

I can be of any help only under Xalan (Apache XSLT engine) or MSXML.

Bertrand Martel
Software AG France

Hi Bertrand,

I use the Xalan-J Processor for my project.

tam

Here comes a snippet to compute sin() under an EXSLT compliant XSLT engine (eg Xalan) :

XML :

============================
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="C:\Temp\sin\doc.xsl"?>

90

============================

XSL :

============================
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version=“1.0”
xmlns:xsl=“XSLT Namespace
xmlns:math=“EXSLT - Math
extension-element-prefixes=“math”>

<xsl:template match=“/”>
<xsl:value-of select=“math:sin(/Root/Angle)” />
</xsl:template>

</xsl:stylesheet>
============================

Output :

============================
0.8939966636005579
============================

Here you go.

Cheers.

Bertrand Martel
Software AG France

Hi Bertrand,

thanks for your example. Now it works!

Greetings
tam