firefox xslt math

S

shaun roe

Hi,
I am using an XSLT to generate an SVG client-side in Firefox. The user
opens an XML file in Firefox and sees a display.

In doing so, I have to convert from cartesian to polar coordinates, so I
need the sine and cosine functions. Firefox does not seem to recognize
the math: extensions (not too surprising) so I am using a series
expansion of the sin(x) function on the interval 0-90 degrees and
mapping any other value, and the cos function, into this interval with
simple arithmetic to calculate on the full 360 deg range. I use four
terms to get the accuracy I need.

Is there a faster/simpler way, given the constraints of having to use
xslt 1.0 with no extensions, which seems to be the case? or... is there
some way of generating some scripting code in the xslt which would
allow me to access javascript (for example) and still achieve the
'automagic' effect of opening an xml and seeing an svg display?

cheers

shaun
 
S

shaun roe

"Chris Chiasson said:
why not use MathML for math?

Maybe I'm wrong, but as I understand it, MathML provides a way for
capturing the meaning of a math expression in a standard way so it can
be represented in a browser, but provides no engine for the evaluation
of a math expression..?
 
C

Chris Chiasson

whoops, I thought you were using SVG to draw equations and stuff

:-]

Doesn't SVG itself have ways to represent (and animate) things like
arcs and circles?

I know that Firefox is capable of making javascript manipulate SVG
images, but I don't know how to do it myself.
 
M

Martin Honnen

shaun said:
is there
some way of generating some scripting code in the xslt which would
allow me to access javascript (for example) and still achieve the
'automagic' effect of opening an xml and seeing an svg display?

No, Firefox does not support extension functions for XSLT that are
written with script.
 
J

Joe Kesselman

shaun said:
Maybe I'm wrong, but as I understand it, MathML provides a way for
capturing the meaning of a math expression in a standard way so it can
be represented in a browser, but provides no engine for the evaluation
of a math expression..?

I believe that's correct. MathML is just a way of representing a
formula; while one could certainly write an evaluator (or solver),
that's a separate feature from MathML rendering.
 
J

Joe Kesselman

Is there a faster/simpler way, given the constraints of having to use
xslt 1.0 with no extensions, which seems to be the case?

This just isn't the kind of task XSLT is optimized for, and support for
extensions (and the details of them) are always optional/nonportable...
I suspect your series-expansion solution is in fact the fastest portable
solution you're going to come up with in XSLT itself.

I suppose you could the XSLT generate Javascript into the HTML it's
producing, and then let the browser execute that as a second pass. Feels
ugly/fragile to me, but then again Javascript always strikes me that way.
 
D

Dimitre Novatchev

You could use the sin() and cos() implementations in FXSL -- however FXSL
uses a lot the xxx:node-set() function, which AFAIR Firefox XSLT hasn't
implemented.

At least, you could have a look at the code of the XSLT implementations and
read the following article, describing it:

An XSL Calculator: The Math Modules of FXSL

at:
http://fxsl.sourceforge.net/articles/xslCalculator/The FXSL Calculator.html



Now the efficiency question -- a few days ago I performed an experiment
compairing FXSL sin() and cos() implementation to that of Math.Sin() and
Math.Cos() in .NET

Surprisingly and very contrary to the existing beliefs, FXSL's timings were
about the same and not greater than the timings for the .Net
implementations.

I was running the FXSL test code with Saxon J 8.7.3

Another conclusion that statements such as:

"This just isn't the kind of task XSLT is optimized for"

are very often wrong!


Cheers,
Dimitre Novatchev
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top