tags:

views:

205

answers:

3

Hello,

the XML i would like to transform contains something like 7.3248378E7, which is not supported natively by the XSL-FO processor (ends up in NaN in the PDF file). Is there a nice way (which is the opposite of a dirty hack) to convert this number format?

Thanks a lot.

A: 

Is the item designated xs:float or xs:double, as opposed to xs:decimal? If that doesn't work, then I think you will have to go with the "dirty hack" approach. See "Requirement 29" in the XSLT page.

mpez0
A: 

I found this post: XSL Transform for converting from scientific notation to decimal number that provides an XSLT 1.0 stylesheet.

After including/importing the stylesheet, call the convertSciToNumString template to convert:

<xsl:call-template name="convertSciToNumString">
    <xsl:with-param name="myval" select="'7.3248378E7'"/>
</xsl:call-template>

Produces: 73248378

This can be evaluated as a number and should get around your NaN issue:

<xsl:variable name="num">
    <xsl:call-template name="convertSciToNumString">
      <xsl:with-param name="myval" select="'7.3248378E7'"/>
    </xsl:call-template>
</xsl:variable>

<xsl:value-of select="$num"/> + 1 = <xsl:value-of select="$num + 1" />

Produces: 73248378 + 1 = 73248379

Mads Hansen
A: 

Today I had to solve a similar problem with scientific conversion. Finally I had to write my own XSLT conversion template, because original "convertSciToNumString" from Michael Case mentioned here in some other answer have some bugs.

Here is an article about this implementation and conversion tests. http://www.orm-designer.com/article/xslt-convert-scientific-notation-to-decimal-number

Ludek Vodicka