[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Re: Format Number and Empy Elements

Subject: Re: Re: Format Number and Empy Elements
From: "Abel Braaksma (online)" <abel.online@xxxxxxxxx>
Date: Wed, 8 Aug 2007 21:49:32 +0200 (CEST)
Re:  Re: Format Number and Empy Elements
> Hi Guys
>
> I still have a few problems with this. Here's my sample XML
>
>
> RESULTS
>
> concat('0', value) works brilliantly, except when there are negative
> numbers (as I get '0-100'). There's always a catch

make it concat('0 ', value) and it will work.

>
> Strangely, sum(value[.]) still gave NaN for Element A
>

Yes, I was not correct. If a node does not exist, sum(value[.]) will not raise
an error, it will return zero. If a node exists, but has no value, you can do
sum(value[number(.)]). That also works if the node has non-numeric values
(meaning: it will give a sum of zero if the values are non-numeric).

> 	<xsl:for-each select="number">

Just out of curiosity, but why do you use for-each here? Using apply-templates
would work as well and is more adaptive to changes.

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

It's a matter of design of course, but if you want this less nested and
(again) more adaptive to change, you can also code it like:

<td>
   <xsl:apply-templates select="number" />
</td>

and:
<xsl:template match="number">
   <xsl:value-of select="..." />
</xsl:template>

or, if you prefer (and that removes the whole issue of NaN):
<xsl:template match="number" priority="0">0.00</xsl:template>
<xsl:template match="number[number(.)]">
    <xsl:value-of select="format-number(., '#,.00')" />
</xsl:template>



but to design it like that is of course largely a matter of taste ;)

Cheers,
-- Abel Braaksma

PS: not tested ;)

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.