• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 868
  • Last Modified:

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

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
Nefertiti_IT
Asked:
Nefertiti_IT
  • 2
  • 2
1 Solution
 
rdcproCommented:
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
 
Nefertiti_ITAuthor Commented:
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
 
rdcproCommented:
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
 
Nefertiti_ITAuthor Commented:
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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now