Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 30th, 2014, 12:52 PM
Registered User
 
Join Date: May 2014
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm finally getting back to this. Here's the error

Quote:
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
---------------------------------------------------------------------
NodeTest expected here. sum(/Results/Recordset/Record/-->translate<--(Pre-assessed-total, '$', '')))
when using this line in the XSL file:

Code:
<xsl:value-of select="sum(/Results/Recordset/Record/translate(Pre-assessed-total, '$', '')))"/>
instead of this:

Code:
<xsl:value-of select="sum(row/col[@name = 'price' and node()/self::text() != 'null'])"/>

I know I'm over my head, but if someone can point me in the right direction, I can do some research on my own. I've searched for terms such as "NodeTest expected here" and "xslt number() function", but I haven't solved this yet.

TIA,
John
 
Old May 30th, 2014, 12:59 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

The expression you have with the translate call in the last step of a path is possible and supported with XSLT/XPath 2.0. The error you get suggests you are using an XSLT 1.0 processor to execute the stylesheet. If you want to use XSLT 2.0 you need to use an XSLT 2.0 processor like Saxon 9, XmlPrime, AltovaXML or AltovaRaptor or Saxon CE.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old May 30th, 2014, 02:12 PM
Registered User
 
Join Date: May 2014
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Is it possible to do this with XSLT 1.0? If not, I'll have to look into getting a 2.0 processor.
 
Old June 16th, 2014, 03:27 AM
Registered User
 
Join Date: Jun 2014
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just out of curiosity, i tried the ablove xml and xsl in XSLT2.0

but i get the following error

Severity: fatal
Description: FORG0006: Input to sum() contains a value of type xs:string which is neither numeric, nor a duration
Start location: 6:0
URL: http://www.w3.org/TR/2005/WD-xpath-f...1/#ERRFORG0006

[<xsl:template match="/">
<xsl:text>Grand Total: </xsl:text>
<xsl:value-of select="sum(/Results/Recordset/Record/translate(Pre-assessed-total,'$',''))"/>]
 
Old June 16th, 2014, 03:30 AM
Registered User
 
Join Date: Jun 2014
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I tried doing this
[<xsl:value-of select="sum(number(/Results/Recordset/Record/translate(Pre-assessed-total,'$','')))"/>]

i get the following error, i can understand why it is throwing this, but what is right code.


Severity: fatal
Description: XPTY0004: A sequence of more than one item is not allowed as the first argument of number() ("3,693.02", "2,245.86")
Start location: 5:0
URL: http://www.w3.org/TR/xpath20/#ERRXPTY0004
 
Old June 16th, 2014, 04:44 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Use
Code:
<xsl:value-of select="sum(/Results/Recordset/Record/(number(translate(Pre-assessed-total,'$','')))"/>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old June 16th, 2014, 08:49 PM
Registered User
 
Join Date: Jun 2014
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry forgot to mention, i did try that as well,
it comes

the value comes out as NAN.
 
Old June 19th, 2014, 01:33 AM
Registered User
 
Join Date: Jun 2014
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

mm..Any answers ...to the above query..
 
Old June 19th, 2014, 02:29 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

NaN means Not a Number. Your input to the sum() function includes something that is not a number.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
sum function pcase XSLT 2 January 2nd, 2008 05:51 PM
sum() function felixm_jr Reporting Services 1 April 22nd, 2007 01:59 AM
Reg Sum() function suri_1811 XSLT 2 December 7th, 2006 03:17 PM
SUM Function jmss66 Classic ASP Basics 17 July 29th, 2003 08:00 AM
Need Help with the Sum Function athanatos XSLT 1 July 22nd, 2003 10:06 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.