[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

xslt test decimal length

Posted on 2013-05-26
2
Medium Priority
?
418 Views
Last Modified: 2013-05-28
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
0
Comment
Question by:alcani
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 total points
ID: 39198539
you can use string-length(substring-after(string(//vpreven), '.')) in the test

but I think
format-number(//vpreven,'#,###,###,###,###.#')
will do exactly what you want, without testing
0
 

Author Comment

by:alcani
ID: 39202987
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>
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question