 |
| 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
|
|
|
|

May 30th, 2014, 12:52 PM
|
|
Registered User
|
|
Join Date: May 2014
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

May 30th, 2014, 12:59 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
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
|
|

May 30th, 2014, 02:12 PM
|
|
Registered User
|
|
Join Date: May 2014
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Is it possible to do this with XSLT 1.0? If not, I'll have to look into getting a 2.0 processor.
|
|

June 16th, 2014, 03:27 AM
|
|
Registered User
|
|
Join Date: Jun 2014
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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,'$',''))"/>]
|
|

June 16th, 2014, 03:30 AM
|
|
Registered User
|
|
Join Date: Jun 2014
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

June 16th, 2014, 04:44 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
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
|
|

June 16th, 2014, 08:49 PM
|
|
Registered User
|
|
Join Date: Jun 2014
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Sorry forgot to mention, i did try that as well,
it comes
the value comes out as NAN.
|
|

June 19th, 2014, 01:33 AM
|
|
Registered User
|
|
Join Date: Jun 2014
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
mm..Any answers ...to the above query..
|
|

June 19th, 2014, 02:29 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|
 |