Re: XslTransform, XslCompiledTransform Sum Large Number Rounding Probl - XML SOAP

This is a discussion on Re: XslTransform, XslCompiledTransform Sum Large Number Rounding Probl - XML SOAP ; Numbers in XSLT are of type double and the operations with them follow the laws of floating point arithmetics. In XSLT2.0/XPath 2.0 one will choose the xs:decimal type and avoid such a problem. In XSLT 1.0 one can use a ...

+ Reply to Thread
Results 1 to 3 of 3

Re: XslTransform, XslCompiledTransform Sum Large Number Rounding Probl

  1. Default Re: XslTransform, XslCompiledTransform Sum Large Number Rounding Probl

    Numbers in XSLT are of type double and the operations with them follow the
    laws of floating point arithmetics. In XSLT2.0/XPath 2.0 one will choose the
    xs:decimal type and avoid such a problem.

    In XSLT 1.0 one can use a workaround as the following:

    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xslutput method="text"/>

    <xsl:template match="/">
    <xsl:variable name="vSumm100Times">
    <xsl:call-template name="sumPrecise">
    <xsl:with-param name="pList" select="//a"/>
    </xsl:call-template>
    </xsl:variable>

    <xsl:value-of select="$vSumm100Times div 100"/>
    </xsl:template>

    <xsl:template name="sumPrecise">
    <xslaram name="pList" select="/.."/>
    <xslaram name="pAccum" select="0"/>
    <xslaram name="pPrec" select="100"/>

    <xsl:choose>
    <xsl:when test="$pList">
    <xsl:call-template name="sumPrecise">
    <xsl:with-param name="pList"
    select="$pList[position() > 1]"/>
    <xsl:with-param name="pAccum"
    select="$pAccum + $pList[1] * 100"/>
    </xsl:call-template>
    </xsl:when>
    <xsltherwise>
    <xsl:value-of select="$pAccum"/>
    </xsltherwise>
    </xsl:choose>
    </xsl:template>
    </xsl:stylesheet>


    When the above transformation is applied on your xml document, the result
    is:


    75556694820929.97


    Cheers,
    Dimitre Novatchev
    "Feiry" <Feiry@discussions.microsoft.com> wrote in message
    news:F43EC524-7461-4F80-A8BF-4A0217F128F4@microsoft.com...
    > I'm trying to sum nodes that have number with minimum 16 digit.
    > when I try using XslTransform to do the transformation I've got a rounding
    > but when I use browser transformation by opening the xml directly through
    > web browser, the sum result is OK.
    > It's looks like XslTransform use double as the sum buffer.
    > I try use XslCompiledTransform but still get the same rounding problem.
    > Is there any body know how to solve this ?
    > I try to search everywhere but seems that no one get the same problem.
    > I use this for large rupiah currency banking transaction reporting, all
    > sample below is just for simplification.
    >
    > thanks for any suggestion in advance.
    >
    > sum result using xsltransform: 75,556,694,820,930.00
    > sum result using browser: 75,556,694,820,929.97
    >
    > transform code .netframework 1.1:
    > XslTransform xslTrans = new XslTransform();
    > xslTrans.Load("sum.xsl");
    > xslTrans.Transform("a.xml","a.txt");
    >
    > transform code .netframework 2.0:
    > XslCompiledTransform xslt = new XslCompiledTransform();
    > xslt.Load("a.xsl");
    > xslt.Transform("a.xml", "a.html");
    >
    > xml example (a.xml):
    > <?xml version='1.0'?>
    > <?xml-stylesheet type="text/xsl" href="sum.xsl"?>
    > <root>
    > <a>6574705.82</a>
    > <a>5350503889475.60</a>
    > <a>13788014503961.10</a>
    > <a>4637582864105.00</a>
    > <a>12291887216661.00</a>
    > <a>11231072464569.00</a>
    > <a>26701607763086.00</a>
    > <a>166575342465.75</a>
    > <a>1343750794520.54</a>
    > <a>45693407380.16</a>
    > </root>
    >
    > xsl sample (sum.xsl):
    > <xsl:stylesheet version="1.0"
    > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    > <xsl:template match="/">
    > <xsl:value-of select="format-number(sum(//a),'###,###.00')"/>
    > </xsl:template>
    > </xsl:stylesheet>
    >




  2. Default Re: XslTransform, XslCompiledTransform Sum Large Number Rounding P

    Thanks for the advice dimitre.

    I already try your suggestion to use the workaroud below on 1.0.
    But it is only work in a browser or using XslCompledTransform class.
    If I use XslTransform the result is still: 75,556,694,820,930.00

    When I use msxsl.exe as the transformation engine the result is correct
    without changing my xsl template file.

    So currently I use msxsl.exe as the transformation, but it is not to elegant,
    because I have to do transformation process with files, I can't use in
    memory process.

    thanks in advance.

    "Dimitre Novatchev" wrote:

    > Numbers in XSLT are of type double and the operations with them follow the
    > laws of floating point arithmetics. In XSLT2.0/XPath 2.0 one will choose the
    > xs:decimal type and avoid such a problem.
    >
    > In XSLT 1.0 one can use a workaround as the following:
    >
    > <xsl:stylesheet version="1.0"
    > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    > <xslutput method="text"/>
    >
    > <xsl:template match="/">
    > <xsl:variable name="vSumm100Times">
    > <xsl:call-template name="sumPrecise">
    > <xsl:with-param name="pList" select="//a"/>
    > </xsl:call-template>
    > </xsl:variable>
    >
    > <xsl:value-of select="$vSumm100Times div 100"/>
    > </xsl:template>
    >
    > <xsl:template name="sumPrecise">
    > <xslaram name="pList" select="/.."/>
    > <xslaram name="pAccum" select="0"/>
    > <xslaram name="pPrec" select="100"/>
    >
    > <xsl:choose>
    > <xsl:when test="$pList">
    > <xsl:call-template name="sumPrecise">
    > <xsl:with-param name="pList"
    > select="$pList[position() > 1]"/>
    > <xsl:with-param name="pAccum"
    > select="$pAccum + $pList[1] * 100"/>
    > </xsl:call-template>
    > </xsl:when>
    > <xsltherwise>
    > <xsl:value-of select="$pAccum"/>
    > </xsltherwise>
    > </xsl:choose>
    > </xsl:template>
    > </xsl:stylesheet>
    >
    >
    > When the above transformation is applied on your xml document, the result
    > is:
    >
    >
    > 75556694820929.97
    >
    >
    > Cheers,
    > Dimitre Novatchev
    > "Feiry" <Feiry@discussions.microsoft.com> wrote in message
    > news:F43EC524-7461-4F80-A8BF-4A0217F128F4@microsoft.com...
    > > I'm trying to sum nodes that have number with minimum 16 digit.
    > > when I try using XslTransform to do the transformation I've got a rounding
    > > but when I use browser transformation by opening the xml directly through
    > > web browser, the sum result is OK.
    > > It's looks like XslTransform use double as the sum buffer.
    > > I try use XslCompiledTransform but still get the same rounding problem.
    > > Is there any body know how to solve this ?
    > > I try to search everywhere but seems that no one get the same problem.
    > > I use this for large rupiah currency banking transaction reporting, all
    > > sample below is just for simplification.
    > >
    > > thanks for any suggestion in advance.
    > >
    > > sum result using xsltransform: 75,556,694,820,930.00
    > > sum result using browser: 75,556,694,820,929.97
    > >
    > > transform code .netframework 1.1:
    > > XslTransform xslTrans = new XslTransform();
    > > xslTrans.Load("sum.xsl");
    > > xslTrans.Transform("a.xml","a.txt");
    > >
    > > transform code .netframework 2.0:
    > > XslCompiledTransform xslt = new XslCompiledTransform();
    > > xslt.Load("a.xsl");
    > > xslt.Transform("a.xml", "a.html");
    > >
    > > xml example (a.xml):
    > > <?xml version='1.0'?>
    > > <?xml-stylesheet type="text/xsl" href="sum.xsl"?>
    > > <root>
    > > <a>6574705.82</a>
    > > <a>5350503889475.60</a>
    > > <a>13788014503961.10</a>
    > > <a>4637582864105.00</a>
    > > <a>12291887216661.00</a>
    > > <a>11231072464569.00</a>
    > > <a>26701607763086.00</a>
    > > <a>166575342465.75</a>
    > > <a>1343750794520.54</a>
    > > <a>45693407380.16</a>
    > > </root>
    > >
    > > xsl sample (sum.xsl):
    > > <xsl:stylesheet version="1.0"
    > > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    > > <xsl:template match="/">
    > > <xsl:value-of select="format-number(sum(//a),'###,###.00')"/>
    > > </xsl:template>
    > > </xsl:stylesheet>
    > >

    >
    >
    >


  3. Default Re: XslTransform, XslCompiledTransform Sum Large Number Rounding P

    Dear Feiry,

    Could you, please, explain more clearly the contents of your last message?

    Sorry, but I didn't understand anything from it. What is really the problem?


    My results are:

    MSXML3: 75556694820929.97
    MSXML4: 75556694820929.97

    .Net 1.1 XslTransform: 75556694820929.969
    .Net 2.0 XslCompiledTransform: 75556694820929.97


    MSXML3 is what IE uses internally to do a transformation as directed by a
    xml-stylesheet processing-instruction.

    The versions of .NET (for the XslTransform and XslCompiledTransform,
    respectively) used are:

    ..NET 1.1.4322.2032
    ..NET 2.0.50727.42

    Cheers,
    Dimitre Novatchev


    "Feiry" <Feiry@discussions.microsoft.com> wrote in message
    news:BB49A13D-8BB2-4937-B238-AD71DCB06BE1@microsoft.com...
    > Thanks for the advice dimitre.
    >
    > I already try your suggestion to use the workaroud below on 1.0.
    > But it is only work in a browser or using XslCompledTransform class.
    > If I use XslTransform the result is still: 75,556,694,820,930.00
    >
    > When I use msxsl.exe as the transformation engine the result is correct
    > without changing my xsl template file.
    >
    > So currently I use msxsl.exe as the transformation, but it is not to
    > elegant,
    > because I have to do transformation process with files, I can't use in
    > memory process.
    >
    > thanks in advance.
    >
    > "Dimitre Novatchev" wrote:
    >
    >> Numbers in XSLT are of type double and the operations with them follow
    >> the
    >> laws of floating point arithmetics. In XSLT2.0/XPath 2.0 one will choose
    >> the
    >> xs:decimal type and avoid such a problem.
    >>
    >> In XSLT 1.0 one can use a workaround as the following:
    >>
    >> <xsl:stylesheet version="1.0"
    >> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    >> <xslutput method="text"/>
    >>
    >> <xsl:template match="/">
    >> <xsl:variable name="vSumm100Times">
    >> <xsl:call-template name="sumPrecise">
    >> <xsl:with-param name="pList" select="//a"/>
    >> </xsl:call-template>
    >> </xsl:variable>
    >>
    >> <xsl:value-of select="$vSumm100Times div 100"/>
    >> </xsl:template>
    >>
    >> <xsl:template name="sumPrecise">
    >> <xslaram name="pList" select="/.."/>
    >> <xslaram name="pAccum" select="0"/>
    >> <xslaram name="pPrec" select="100"/>
    >>
    >> <xsl:choose>
    >> <xsl:when test="$pList">
    >> <xsl:call-template name="sumPrecise">
    >> <xsl:with-param name="pList"
    >> select="$pList[position() > 1]"/>
    >> <xsl:with-param name="pAccum"
    >> select="$pAccum + $pList[1] * 100"/>
    >> </xsl:call-template>
    >> </xsl:when>
    >> <xsltherwise>
    >> <xsl:value-of select="$pAccum"/>
    >> </xsltherwise>
    >> </xsl:choose>
    >> </xsl:template>
    >> </xsl:stylesheet>
    >>
    >>
    >> When the above transformation is applied on your xml document, the result
    >> is:
    >>
    >>
    >> 75556694820929.97
    >>
    >>
    >> Cheers,
    >> Dimitre Novatchev
    >> "Feiry" <Feiry@discussions.microsoft.com> wrote in message
    >> news:F43EC524-7461-4F80-A8BF-4A0217F128F4@microsoft.com...
    >> > I'm trying to sum nodes that have number with minimum 16 digit.
    >> > when I try using XslTransform to do the transformation I've got a
    >> > rounding
    >> > but when I use browser transformation by opening the xml directly
    >> > through
    >> > web browser, the sum result is OK.
    >> > It's looks like XslTransform use double as the sum buffer.
    >> > I try use XslCompiledTransform but still get the same rounding problem.
    >> > Is there any body know how to solve this ?
    >> > I try to search everywhere but seems that no one get the same problem.
    >> > I use this for large rupiah currency banking transaction reporting, all
    >> > sample below is just for simplification.
    >> >
    >> > thanks for any suggestion in advance.
    >> >
    >> > sum result using xsltransform: 75,556,694,820,930.00
    >> > sum result using browser: 75,556,694,820,929.97
    >> >
    >> > transform code .netframework 1.1:
    >> > XslTransform xslTrans = new XslTransform();
    >> > xslTrans.Load("sum.xsl");
    >> > xslTrans.Transform("a.xml","a.txt");
    >> >
    >> > transform code .netframework 2.0:
    >> > XslCompiledTransform xslt = new XslCompiledTransform();
    >> > xslt.Load("a.xsl");
    >> > xslt.Transform("a.xml", "a.html");
    >> >
    >> > xml example (a.xml):
    >> > <?xml version='1.0'?>
    >> > <?xml-stylesheet type="text/xsl" href="sum.xsl"?>
    >> > <root>
    >> > <a>6574705.82</a>
    >> > <a>5350503889475.60</a>
    >> > <a>13788014503961.10</a>
    >> > <a>4637582864105.00</a>
    >> > <a>12291887216661.00</a>
    >> > <a>11231072464569.00</a>
    >> > <a>26701607763086.00</a>
    >> > <a>166575342465.75</a>
    >> > <a>1343750794520.54</a>
    >> > <a>45693407380.16</a>
    >> > </root>
    >> >
    >> > xsl sample (sum.xsl):
    >> > <xsl:stylesheet version="1.0"
    >> > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    >> > <xsl:template match="/">
    >> > <xsl:value-of select="format-number(sum(//a),'###,###.00')"/>
    >> > </xsl:template>
    >> > </xsl:stylesheet>
    >> >

    >>
    >>
    >>




+ Reply to Thread

Similar Threads

  1. Re: GUI with Large number of IO/labels
    By Application Development in forum labview
    Replies: 2
    Last Post: 10-09-2007, 07:40 AM
  2. Re: GUI with Large number of IO/labels
    By Application Development in forum labview
    Replies: 1
    Last Post: 10-09-2007, 04:40 AM
  3. Re: GUI with Large number of IO/labels
    By Application Development in forum labview
    Replies: 2
    Last Post: 10-08-2007, 10:24 AM
  4. How to make XslCompiledTransform transform &amps; as XslTransform does
    By Application Development in forum XML SOAP
    Replies: 12
    Last Post: 11-07-2006, 02:55 AM
  5. Large number of recipient
    By Application Development in forum Mutt
    Replies: 7
    Last Post: 01-20-2005, 08:22 AM