Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSLT format-number - locales

Status
Not open for further replies.

MrPeds

Programmer
Jan 7, 2003
219
GB
Hi,

I have an xslt file that carries out a simply transformation on an xml file. One of the transformations i am carrying out is the display of some readonly decimal values (2 decimal places).

I am carrying out the transformation client-side in the browser. e.g.

select="format-number( $var1 * $var2, '0.00' )

The results displayed are currently something like 0.25, 0.10 etc. Is there any way that I can change the format string to display a comma for locales that use the comma?

Thanks,

MrPeds
 
Such as adding a top-level element xsl:decimal-format to the stylesheet,
[tt] <xsl:decimal-format name="continental" decimal-separator="," grouping-separator="." />
[/tt]
and then according to need, change the decimal-format.
[tt] select="format-number( $var1 * $var2,'0.00'[blue],'continental'[/blue])[/tt]
 
Hi,

Thanks for the response.

Any suggestions on how I would detect the users number format in client-side javascript?

I could then use this to set the stylesheet separator dynamically in client side javascript.

Thanks,

MrPeds

PS: I know it isnt strictly an XML follow up question but applicable to this thread. thanks.
 
You can use the following regular expression pattern (for "british" formatting, otherwise, for continental style, just swap the comma and dot) of mine, scripted on toilet paper, to test if the input result in true:

[tt] ^\s*([1-9][0-9]{0,2}(,[0-9]{3})+|(0|[1-9][0-9]{0,2}))(\.\d+)?\s*$[/tt]

The idea is that if they use thousand grouping input, they must be more serious in observing some additonal discipline such as rejecting "123.", "00.123" etc. If you allow some of those border cases, relax the pattern a bit to accommodate them.

For some number, sure, both would be validated, such as an integer number of 2 digits. Both that won't create a difficulty for the xslt.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top