[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

XSLT Decimal Places

Posted on 2007-08-10
4
Medium Priority
?
1,552 Views
Last Modified: 2013-11-18
Hi Experts

I have an xslt page that is doing some division, how do I limit the output to say 2 decimal places, or even not show anything after the DP at all.

I'm currently playing with this I found on the web, but cant no joy yet.

  <xs:restriction base="xs:decimal">
  <xs:fractionDigits value="2"/>
  </xs:restriction>

Andy
0
Comment
Question by:Andy Green
  • 3
4 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 1000 total points
ID: 19669813
use format number
        <xsl:value-of select="format-number(a div b, '0.00')"/>

<test>
    <a>5</a>
    <b>3</b>
</test>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="test">
        <xsl:value-of select="format-number(a div b, '0.00')"/>
    </xsl:template>
</xsl:stylesheet>

will yield 1.67

cheers

geert


0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 19669831
note that you posted a part of an xml schema, not an xslt
xml-schema is for validation only
0
 
LVL 3

Author Comment

by:Andy Green
ID: 19669973
Got it working thanks.

Andy
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 19670205
welcome
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

829 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