[Home] [By Thread] [By Date] [Recent Entries]


As Michael pointed out, please post XSLT related questions at the
xsl-list hosted by www.mulberrytech.com.

To answer your present question, I would like to suggest a simple way
to implement abs() functionality in XSLT 1.0 (XSLT 2.0 has it
built-in, so no need to worry with XSLT 2.0).

Write a named template for this..

Here is the code:

<xsl:template name="abs">
   <xsl:param name="n" />

   <xsl:choose>
      <xsl:when test="$n &gt;= 0">
        <xsl:value-of select="$n" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="0 - $n" />
      </xsl:otherwise>
   </xsl:choose>
</xsl:template>

Call this as:

1)
<xsl:call-template name="abs">
    <xsl:with-param name="n" select="3" />
</xsl:call-template>

Will produce output: 3

2)
<xsl:call-template name="abs">
   <xsl:with-param name="n" select="-10" />
</xsl:call-template>

Will produce output: 10

Regards,
Mukul

On 7/6/06, Webmaster <Webmaster@c...> wrote:
> Hello. I'm using Saxon 6.5.3 and am trying to get the abs function to work.
> I tried math: and fn: but I'm getting the error: "unknown system function".
> I've tried several name spaces, with out any success.
>
> It seems to me that maybe saxon doesn't with it? my xsl namespace is:
> http://www.w3.org/1999/XSL/Transform
>
> At this point I'm kinda lost and not really knowing what I need. So how do I
> find a libary of math functions? do I have to download some files? do I have
> to update the xsl namespace?
>
> Thanks!
> LN

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member