Re: [xsl] Convert dollars

Subject: Re: [xsl] Convert dollars
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Sat, 16 Jan 2010 20:39:20 -0800
At 2010-01-16 21:26 -0700, Karl Stubsjoen wrote:
Besides a recursive template which strips obvious dollar syntax from a
string, is there a better way to achieve a number from items like:
$ 330.01
$ 1,100.32
- 234
1
$5
-16.23
Notice the negative, this should be preserved.
I'm interested in a 1.0 solution.

When you know the characters to remove, use this:


translate(.,'$ ,','')

When you don't know the characters to remove, use the double-translate idiom:

translate(.,translate(.,'-0123456789.',''),'')

I hope this helps.

. . . . . . . . . . . . Ken


-- UBL and Code List training: Copenhagen, Denmark 2010-02-08/10 XSLT/XQuery/XPath training after http://XMLPrague.cz 2010-03-15/19 XSLT/XQuery/XPath training: San Carlos, California 2010-04-26/30 Vote for your XML training: http://www.CraneSoftwrights.com/s/i/ Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18 Video overview: http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18 G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal

Current Thread