2010-02-26 62 views
1

我想要轉換的XML包含類似7.3248378E7的內容,XSL-FO處理器不支持本機(以PDF文件中的NaN結尾)。有沒有一種很好的方式(這是一個骯髒的黑客相反)來轉換這種數字格式?使用XSLT(FO)將科學記數法轉換爲雙精度型

非常感謝。

+0

[格式化科學數字表示形式在xsl]的完全重複(http://stackoverflow.com/questions/4367737/formatting-scientific-number-representation-in-xsl) – 2010-12-29 23:38:41

回答

0

該項目是否指定爲xs:float或xs:double,而不是xs:decimal?如果這不起作用,那麼我認爲你將不得不採用「骯髒的黑客」方法。請參閱XSLT page中的「要求29」。

1

我發現此文章:XSL Transform for converting from scientific notation to decimal number提供了一個XSLT 1.0樣式表。

包括/導入樣式表後,調用convertSciToNumString模板轉換:

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

產地:73248378

這可以作爲一個數量進行評估,並應該得到解決您的NaN的問題:

<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" /> 

產品:73248378 + 1 = 73248379