Subject: RE: Calculations in XSL using multiple XML data fileds From: "Phil Davies" <phildavies@xxxxxxxxxxxxxxxxxx> Date: Wed, 1 Nov 2000 11:33:18 -0400 (EST) |
Jeni, Thanks for that but I'm still a little unclear, I am calling the data in a table using the template: <xsl:apply-templates select="last"/> and then applying the template using: <xsl:template match="last"> <xsl:eval>format-number(q1/quotes/quote/last - (q2/quotes/quote/last div 7.45),'#,##0.00')</xsl:eval> </xsl:template> I have also seen the same function written as formatNumber() - which is correct (maybe both?) Would using the <xsl:apply-templates select="last"/> be correct as I am referring to multiple instances of the field "last" i.e. q1/quotes/quote/last and q2/quotes/quote/last : As this is not actually working (I am getting an ASP error) can I assume that the syntax is correct but that my XSLT processor is not current/up-to-date. Thanks Phil -----Original Message----- From: Jeni Tennison [mailto:mail@xxxxxxxxxxxxxxxx] Sent: 01 November 2000 10:43 To: Phil Davies Cc: XSL-List@xxxxxxxxxxxxxxxx Subject: Re: Calculations in XSL using multiple XML data fileds Phil, >These fields will always contain numeric data and need to return a result to >2 decimal places > >I want the XSL to perform the following calculation > > (q1/quotes/quote/last) - ((q2/quotes/quote/last)/7.45) > >I am hoping that this can be done in XSL but cannot find out how this can be >done. The only thing you're lacking is knowing how to divide in XSLT (well, actually in XPath). The '/' can't be used because it's used in XPath to separate steps, so instead 'div' is used instead: q1/quotes/quote/last - (q2/quotes/quote/last div 7.45) To give the result to two decimal places, you need the format-number() XSLT function: format-number(q1/quotes/quote/last - (q2/quotes/quote/last div 7.45), '#,##0.00') >I am using IIS5, the XML is generated from an HTTP request made to a >proprietry XML database via an ASP page. How the XML is generated won't matter in terms of how you solve this problem, but what XSLT processor you're using will: if you're using MSXML, make sure it's the latest version. >If it cannot be done in XSL, can anyone suggest how else (script?) this can >be done If you're using MSXML, then you can use an extension function called msxsl:script to write functions in JScript or VBScript that can then be used within XPath as XPath functions. XSLT is enough to handle simple calculations, but if you get anything complicated (e.g. sin/cos) then you need something more, which msxsl:script provides. The details are given in the MSXML SDK. I hope that this helps, Jeni Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: Calculations in XSL using multi, Jeni Tennison | Thread | RE: Calculations in XSL using multi, Jeni Tennison |
Re: [newbie] in xslt-file, Larry_Mason | Date | Re: [newbie] in xslt-file, David Carlisle |
Month |