[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] trig functions in XSL?


Subject: Re: [xsl] trig functions in XSL?
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Sun, 11 Jan 2009 14:21:20 -0800

On Sun, Jan 11, 2009 at 1:06 PM, Stuart A. Yeates <syeates@xxxxxxxxx> wrote:
> Hello
>
> I'm wanting to use trig functions (cos, sin and tan) for  generating
> some SVG. There seem to be lots of libraries and templates around to
> do these, does someone have advice on which is the best to use?
>
> My priorities are:
> (a) XSL 1.0
> (b) Cross platform
>
> I'm not all that concerned about efficiency.

Hi Stuart,

This is exactly when you can use FXSL 1.x (for XSLT 1.0):

Here is a test example from the library:

testTrig.xsl
========


<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

 <xsl:import href="trignm.xsl"/>
 <!-- To be applied on any xml file -->

 <xsl:output method="text"/>

  <xsl:template match="/">
	 <xsl:call-template name="cos">
	    <xsl:with-param name="pX" select="240"/>
        <xsl:with-param name="pUnit" select="'deg'"/>
	 </xsl:call-template>

  </xsl:template>
</xsl:stylesheet>

The result is:

-0.5000000000079126


All trig functions and there inverese functions are ready for you to use.

Regarding your priorities:


> My priorities are:
> (a) XSL 1.0

   Yes.

> (b) Cross platform

Yes. FXSL 1.x is written in XSLT 1.0.  The only extension function
used is xxx:node-set(). I would recommend to use the edition of FXSL
1.x, which uses the EXSLT function ext:node-set(), as most XSLT 1.0
processors, including the .NET CompiledXslTransform class, do support
this ext:node-set() extension function.

>
> I'm not all that concerned about efficiency.

The FXSL implementation uses good algorithms (fast converging Taylor
series and the Newton - Raphston method for the inverse functions) so
its time complexity is not too bad :)


Whenever you upgrade to XSLT 2.0 you may prefer to use FXSL 2, which
does not use any extension functions at all.




-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play




>
> cheers
> stuart
>
>



-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play


Current Thread
Keywords