Solved

Preventing exponential representation of numeric data from SP using XML/XSLT

Posted on 2004-04-14
4
787 Views
Last Modified: 2010-05-18
Below is my format specification but on occasion, a large balance will be represented exponentially (1,259,951,501.00 is displayed as 1.259951501E9). I know the SP doesn't return the value this way. How can I capture the value and prevent the XSL from representing the value this way?

Thanks, Nefertiti_IT

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text" omit-xml-declaration="yes"/>

<xsl:template match="/">
        <xsl:apply-templates select="/dML/row/"/>
</xsl:template>

<xsl:template match="row">    
        <xsl:value-of select="Name"/><xsl:text>|</xsl:text>
        <xsl:value-of select="Acct"/><xsl:text>|</xsl:text>
        <xsl:value-of select="CheckingAcctBalance"/><xsl:text>|</xsl:text>    
        <xsl:value-of select="SavingsAcctBalance"/><xsl:text>|</xsl:text>
        <!-- End of row -->
        <xsl:text>&#010;</xsl:text>
</xsl:template>

</xsl:stylesheet>
0
Comment
Question by:Nefertiti_IT
  • 2
  • 2
4 Comments
 
LVL 26

Expert Comment

by:rdcpro
ID: 10826808
It can't be the XSLT...the XSLT doesn't know anything about data types, unless there's something about your XML/XSLT that you're not showing.  As far as

<xsl:value-of select="SavingsAcctBalance"/>

goes, this is just a string, and the XSLT will display whatever is in the SavingsAcctBalance element.

I'd double check the XML that's being transformed...you'll find the number is already in that form.

It's possible, though this may not work, that you can fix this in the XSLT using the format-number function.  But I rather doubt it will work:

<xsl:value-of select="format-number(SavingsAcctBalance, '#0.00')"/>

Regards,
Mike Sharp
0
 

Author Comment

by:Nefertiti_IT
ID: 10826893
Hi Mike,

Thanks for responding...there are a few other files involved in this and I would guess the problem might be here with the below declaration. Is it the attribute setting (or lack thereof) that could be causing this?

Thanks again,
Nefertiti_IT

<xsl:template match="row-set">
        <xsl:for-each select="row">
                <row>
                        <xsl:apply-templates select="col"/>
                </row>
        </xsl:for-each>
</xsl:template>



<xsl:template match="col">
        <xsl:element name="{@column-label}">
                <xsl:value-of select="normalize-space(text())"/>
         </xsl:element>
</xsl:template>
0
 
LVL 26

Accepted Solution

by:
rdcpro earned 50 total points
ID: 10827346
If it's actually an XSLT *number* datatype (which is not evident from what you've shown) there is a limitation on the maximum *precision*.  But if it's a string, there's no way the XSLT you posted could do this.  For example:

This XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
      <xsl:template match="/">
            <xsl:variable name="vNum" select="123456789012345678901234567890.00"/>
            <xsl:variable name="vNumString" select=" '123456789012345678901234567890.00' "/>
            <xsl:value-of select="$vNum"/><br/>
            <xsl:value-of select="$vNumString"/>
      </xsl:template>
</xsl:stylesheet>


Produces this:

123456789012345670000000000000
123456789012345678901234567890.00

So you can see that the max precision 17 sig figs.  But the string gets it all. Neither one produces 1.2345678901234567E29

It must be happening before the XSLT gets it.  If you use this XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
      <xsl:template match="/">
            <xsl:copy-of select="*"/>
      </xsl:template>
</xsl:stylesheet>


It will show you that the value is already in the other format.  I'll bet either your SP *does* produce the number in the exp format, or else some other intermediate step strongly types the number and does it.  

Regards,
Mike Sharp
0
 

Author Comment

by:Nefertiti_IT
ID: 10828110
Mike,

You are right! Running the SP in the database produced the values I expected but the data does reach my xml format doc. in exponential format. I converted the large values to "numeric" in the SP and the problem is solved. Thank you very much for your help!!!!

Nefertiti
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now