Solved

XSLT: What's wrong with <xsl:value-of select="format-number(Amount, "##.##")" />

Posted on 2004-11-01
398 Views
Last Modified: 2008-02-01
I have the following data:

<Amount>40.0</Amount>

I want to display it as:

40.00

Using something along the lines of:

<xsl:value-of select="format-number(Amount, "##.##")" />

I get "XML Parsing Error: not well-formed" in Firefox. I can find examples where it shows the value of an attribute in this way or for a fixed value, but not the contents of a tag.
0
Question by:tjrobinson
    6 Comments
     
    LVL 52

    Assisted Solution

    by:Carl Tawn
    Try:

    <xsl:value-of select="format-number(Amount, '##.##')" />
    0
     

    Author Comment

    by:tjrobinson
    That stops the error but I get an output of:

    40

    Probably something to do with the format parameter, I need to force the decimal places.
    0
     
    LVL 21

    Accepted Solution

    by:
    Try:

    <xsl:value-of select="format-number(Amount, '#0.00')" />

    0
     

    Author Comment

    by:tjrobinson
    Thanks that works well. I've split the points between you, but before you go is there any way of stopping it displaying if it's non a number (NaN)?
    0
     
    LVL 21

    Expert Comment

    by:MogalManic
    <xsl:choose>
      <xsl:when test='String(Number(Amount))="NaN"'>
              0.00
      </xsl:when>
      <xsl:otherwise>
         <xsl:value-of select="format-number(Amount, '#0.00')" />
      </xsl:otherwise>
    </xsl:choose
    0
     

    Author Comment

    by:tjrobinson
    Thanks, that looks just the job.
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    884 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now