This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Beginner's question: Mathematical Calculations in XSL Template
- From: "Thomas B. Passin" <tpassin at mitretek dot org>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Wed, 21 Nov 2001 13:24:11 -0500
- Subject: Re: [xsl] Beginner's question: Mathematical Calculations in XSL Template
- References: <000001c172a0$ddff1460$2c00a8c0@amiy>
- Reply-to: xsl-list at lists dot mulberrytech dot com
[Ami D. Yanero]
> I'm attempting to do multiplication and additon calculations in my XSL
> template. I've seen several posts to various newsgroups about this same
> scenario, and I've tested my calculations using the examples and
> corrected answers posted.
>
> However, I'm getting the same error when I do the calculations with the
> examples as I'm getting when I use my 'live' documents. Everything that
> I've read says that what I've got should work. Please help!
>
First of all, you need to use an actual xslt processor as others have said.
Then your example works fine (after you use the correct namespace for xslt).
Here's a slightly modified version of your example and stylesheet:
<?xml version = "1.0" encoding = "UTF-8"?>
<numbers>
<one>2</one>
<two>3</two>
<three>5</three>
</numbers>
Here is a working stylesheet and the results:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<results>
<xsl:apply-templates select='numbers'/>
</results>
</xsl:template>
<xsl:template match='numbers'>
Addition:<xsl:value-of select='number(one)+number(two)+number(three)'/>
Multiplication:<xsl:value-of
select='number(one)*number(two)*number(three)'/>
</xsl:template>
</xsl:stylesheet>
============= results =============
<results>
Addition:10
Multiplication:30</results>
Cheers,
Tom P
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list