×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

XSLT not constantly getting decimal values

XSLT not constantly getting decimal values

XSLT not constantly getting decimal values

(OP)
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?

RE: XSLT not constantly getting decimal values

Show the two input nodes, please.

Tom Morrison
Micro Focus

RE: XSLT not constantly getting decimal values

(OP)
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?

RE: XSLT not constantly getting decimal values

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

RE: XSLT not constantly getting decimal values

(OP)
I'm using .net to process the XSLT into XML

RE: XSLT not constantly getting decimal values

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close