Link to home
Start Free TrialLog in
Avatar of alcani
alcani

asked on

xslt test decimal length

Hi experts,

I would like to test a numeric value coming from an XML node.

I have this field in a xsl form

<input name="vpreven" type="text" id="vpreven" size="15" maxlength="{//vpreven
/@length}" style="text-align:right" > 
 <xsl:if test="(//vpreven!=0)">        
 <xsl:attribute name="value">
    <xsl:value-of select="format-number(//vpreven,'#,###,###,###,###.000000')"/>   </xsl:attribute>
  </xsl:if>
  </input>

I get as result 6 decimal numbers e.g. 10.234567
 
I would like to test the decimal length in order to put the right format
e.g
10.543 -> <xsl:value-of select="format-number(//vpreven,'#,###,###,###,###.000')"/>
10.2 -> <xsl:value-of select="format-number(//vpreven,'#,###,###,###,###.0')"/>
10.87655 -> <xsl:value-of select="format-number(//vpreven,'#,###,###,###,###.00000')"/>

Thank you for you comments,

Regards
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of alcani
alcani

ASKER

Thanks! I do it like this,

<xsl:choose>
        <xsl:when test="(string-length(substring-after(string(//vpreven), '.')) = 3 )">
        <xsl:attribute name="value">
        <xsl:value-of select="format-number(//vpreven,'#,###,###,###,###.000')"/>
        </xsl:attribute>
        </xsl:when>
        <xsl:when test="(string-length(substring-after(string(//vpreven), '.')) = 4 )">
        <xsl:attribute name="value">
        <xsl:value-of select="format-number(//vpreven,'#,###,###,###,###.0000')"/>
        </xsl:attribute>
        </xsl:when>
        <xsl:when test="(string-length(substring-after(string(//vpreven), '.')) = 5 )">
        <xsl:attribute name="value">
        <xsl:value-of select="format-number(//vpreven,'#,###,###,###,###.00000')"/>
        </xsl:attribute>
        </xsl:when>
        <xsl:when test="(string-length(substring-after(string(//vpreven), '.')) = 6 )">
        <xsl:attribute name="value">
        <xsl:value-of select="format-number(//vpreven,'#,###,###,###,###.000000')"/>  
        </xsl:attribute>
        </xsl:when>
        <xsl:otherwise>
        <xsl:attribute name="value">
        <xsl:value-of select="format-number(//vpreven,'#,###,###,###,###.00')"/>
        </xsl:attribute>
        </xsl:otherwise>
 </xsl:choose>