Tuesday, 15 September 2020

Scientific Notation to Number form in XLST

I was facing a issue as one of my service was returning the number in scientific format like 1E4 for 40. 

If you are not aware of scientific format then please read the wiki page to get more clarity. 

 

If in your source schema has some problem like this, you can change it by having  following XLST custom function.


To add this in your xlst, add xmlns:cnf="http://oracle.com/customfunction" and then add this function in your xlst before the template. 


 <!– changes numbers in Scientific Notation e.g. 4E+10 to number format –>     

    <xsl:function name="cfn:changeSciToNumber"> 

        <xsl:param name="param" /> 

        <xsl:choose> 

            <xsl:when test="matches($param, '^\-?[\d\.,]*[Ee][+\-]*\d*$')"> 

                <xsl:value-of 

                    select="format-number(number($param), '#0.#############')"> 

                </xsl:value-of> 

            </xsl:when> 

            <xsl:otherwise> 

                <xsl:value-of select="$param"></xsl:value-of> 

            </xsl:otherwise> 

        </xsl:choose> 

    </xsl:function>



Now in your xlst user cfn:changeSciToNumber('xpath of variable') and it will change and provide the number in the format. 

No comments:

Post a Comment

Feature Selection in AI

In artifical intelegance/machine learning, everything start and end with data and in current world everyday by using facebook, insta we all ...