Re: [xsl] math

Subject: Re: [xsl] math
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 30 May 2001 11:32:31 +0100
Hi Ronald,

> How can I do this with XSLT, for all I seem to get for output is the
> string: "500 div 50 * 10" in stead of 100.

You can't dynamically evaluate an expression in pure XSLT 1.0.
However, some processors, such as Saxon, have an evaluate() extension
function that will allow you to do so.  If you're using Saxon, you can

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
<xsl:output method = "html" encoding="Windows-1252" />

<xsl:template match="/">
   <xsl:variable name="expr">
      <xsl:apply-templates select="math"/>
      <body><xsl:value-of select="saxon:evaluate($expr)"/></body>


Xalan has a similar evaluate() extension function. If you're using
MSXML, I'm afraid that I don't know of any similar extension function
for full XPath expressions (although you can use it to evaluate
location paths with a user-defined function through msxsl:script).

I hope that helps,


Jeni Tennison

 XSL-List info and archive:

Current Thread