Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSLT not constantly getting decimal values

Status
Not open for further replies.

Sniipe

Programmer
Oct 9, 2006
115
0
0
IE
I have the following xslt code
<xsl:attribute name="DiscountPerc1"> <xsl:value-of select=". * 100"/> </xsl:attribute>

It is trying to translate from an XML file (origionally an excel sheet where the cell would be formatted for percent) values like this:
10.01
It then translates the above correctly to 10.01
<IndividualCode itemnum="abc" DiscountPerc1="10.01" DiscountPerc2="0" />

However with the following I get "NaN"
In this case the value in excel is 0.01
<IndividualCode itemnum="def" DiscountPerc1="NaN" DiscountPerc2="0" />

Any idea why it likes one but not the other?
 
Show the two input nodes, please.

Tom Morrison
Micro Focus
 
Hi Tom,

I see an issue now with the inputs in excel. they are coming up as:

the 10.01 answer is coming up as:
<Cell id="DiscountPerc1 div 100"><Data ss:Type="Number">0.10009999999999999</Data></Cell>

the 0.01 answer is coming up as:
<Cell><Data ss:Type="Number">1E-4</Data></Cell>

So 2 things I notice; the number isn't as it appears in the excel document and also the second number has no id on it.

Any idea how I fix the number being wrong?
 
The number is not wrong. That is a correct lexical representation of a floating point number the value of which is 0.01.

What XSLT processor are you using?

Tom Morrison
Micro Focus
 
I'm using .net to process the XSLT into XML
 
First, a correction on my previous post: the value represented is .0001, not .01.

All I can suggest is some debugging. If you have an XSLT debugger, you can step through the transformation. While you cannot use <xsl:comment> directly at the point where you are using <xsl:attribute> (because you are in the middle of generating an output element), you can place an xsl:comment before or after element generation to display the values you are actually getting. Or, for one run, you could simply change the select=". * 100" to select="." to avoid the numeric translation and make sure it really is 1E-4.

Tom Morrison
Micro Focus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top