?
Solved

xslt test decimal length

Posted on 2013-05-26
2
Medium Priority
?
421 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
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

840 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