[XSL-FO] RE: $ and Commas - How do we parse these out of data
- To apply formatting to numbers there is the format-number function
format-number(value, format, [name]) => number
Value is the input
Format is the format pattern: almost equal to formatting in Java
fe . 22000.3 using pattern #,##0.00 is translated into 22,000.30
Name (Optional) of the decimal format, If in your XSL is
<xsl:decimal-format> which declares the source format for the numbers in
your document, you should use the same name.
I Hope this brief explanation helps.
Van: sg_goli@... [mailto:sg_goli@...]
Verzonden: donderdag 6 september 2001 17:06
Onderwerp: [XSL-FO] $ and Commas - How do we parse these out of data
I have an XML file which has the following data.
How do i check these elements and parse out the punctuation in the
XML and apply my own formatting and display using XSL.
To unsubscribe from this group, send an email to:
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
As a matter of design, having the dollar signs within the XML is less
than ideal. This is because those numbers (i.e., "TOTAL" and the
second "LIMIT") are no longer numbers, they're strings. As such,
format-number won't work. Furthermore, dollar signs are for display
only and not really part of the "data." That's what something like
format-number is for. This same kind of problem is evident when
calculations (you can't do math with a string) come into play.
That said, I would first try and modify the XML to get rid of the
dollar signs. If you can, then you're in good shape. Change the XML
and use format-number.
If not, and I suspect this is probably the case, then you'll first
need to use string manipulation to get rid of the dollar sign (that
should be pretty simple). In other words, get rid of the dollar sign
(you can keep the commas). Then, use format-number *after* you've
converted the string (i.e., your numbers with dollar signs) to a
Here's an example that does it both ways.
<!-- Easy way -->
<xsl:value-of select="format-number(./First, '$##,###.##')"/>
<!-- Less easy way -->
The "Easy way" simply takes the "First" element and formats it.
The "Less easy way" first converts the "Second" element by stripping
off the dollar sign, then apply the formatting. If you're not 100%
sure if there will be a dollar sign, then you'll need to check using
something like "starts-with" in a conditional.
Hope this helps.
--- In XSL-FO@y..., sg_goli@y... wrote:
> I have an XML file which has the following data.
> How do i check these elements and parse out the punctuation in
> XML and apply my own formatting and display using XSL.