xsl-list
[Top] [All Lists]

Re: Maths functions in a stylesheet?

2005-02-25 10:14:34
Derek Hohls wrote:

If any XSLT gurus could help with  this...

I have a "maths functions" stylesheet, adapted from another source -

<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";;
xmlns:xalan="http://xml.apache.org/xalan";;
xmlns:maths="http://www.mydomain.com/maths";;
extension-element-prefixes="maths"
version="1.0">
<xalan:component prefix="maths" elements="rules" functions="sine cosine
abs pi">
<xalan:script lang="javascript"> function sine(thisValue) {
    return Math.sin(thisValue);
  }
  function cosine(thisValue) {
    return Math.cos(thisValue);
  }
  function abs(thisValue) {
    return Math.abs(thisValue);
} function pi() {
    return 3.141592653589790;
} </xalan:script>
</xalan:component>
</xsl:stylesheet>

Called like this:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";;
xmlns:xalan="http://xml.apache.org/xalan";;
xmlns:maths="http://www.mydomain.com/maths";;
extension-element-prefixes="maths"> > <xsl:include href="functions.xsl"/> <xsl:template match="/">
<xsl:variable name="foo" select="maths:pi()" />
</xsl:template>
</xsl:stylesheet>

I get :

An Error Occurred
java.lang.RuntimeException: Unknown error in XPath.
cause: java.lang.RuntimeException: Unknown error in XPath.

when running this with Cocoon 2.1.5 (withe default build with Xalan).

Thanks
Derek

Hi Derek,

could you just use http://www.exslt.org/math/, these are supported by the xalan processor
http://xml.apache.org/xalan-j/apidocs/org/apache/xalan/lib/ExsltMath.html

and include the constant PI.

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

 xmlns:math="http://exslt.org/math";

>

<xsl:template match="value">
   <xsl:value-of select="math:cos(.)"/>
</xsl:template>
</xsl:stylesheet>

Norman

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>