I want to do some calculation within the xslt file and need to do some squre root in the formula. can someone please point out if it is possible and how please?
Thanks a mill
I want to do some calculation within the xslt file and need to do some squre root in the formula. can someone please point out if it is possible and how please?
Thanks a mill
One can use the
sqrt
template/function of FXSL:I. In XSLT 1.0:
When this transformation is applied on any XML document (not used), the wanted correct result is produced:
II. Using FXSL 2.x for XSLT 2.0:
When this transformation is applied on any XML document (not used), the wanted, correct result is produced:
If you are using XSLT 2.0, then problem sorted -- See Dimitre's answer. If you are using XSLT 1.0, in practice in a production environment, I would still go with Dimitre's answer. Commercially, it is better to use a tested libary than re-invent the wheel.
However I thought your question might be fun to implement a stand-alone solution for. And it was!
Given this bunch of values to find the roots of...
...when input to this XSLT 1.0 style-sheet...
...yields approximate solutions...
Notes
The technique uses Divide-And-Conquer to find the root of the equation f(y) = y*y - x, which occurs at the square root of x. The technique is probably only reasonably efficient for XSLT processors which implement optimized tail-end recursion.