Mork0075
Mork0075

Reputation: 5945

Convert scientific notation into double with XSLT(FO)

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.

Upvotes: 1

Views: 3324

Answers (3)

Ludek Vodicka
Ludek Vodicka

Reputation: 1730

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

Upvotes: 0

Mads Hansen
Mads Hansen

Reputation: 66714

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

Upvotes: 1

mpez0
mpez0

Reputation: 2883

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.

Upvotes: 0

Related Questions