XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition (155 page)

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
13.98Mb size Format: txt, pdf, ePub

Usage

The

element is used in conjunction with the
format-number()
function to output numeric information. It is designed primarily to provide localization of the format for display to human readers, but it can also be useful when you need to produce an output data file using, for example, a fixed number of leading zeroes. It is typically used for numbers in the source data or computed from the source data, whereas the

element, which has its own formatting capabilities, is generally used to generate sequence numbers.

Each

element defines a style of localized numbering, catering for the variations that occur in different countries and languages, and for other local preferences such as the convention in the accountancy profession whereby parentheses are used to indicate negative numbers.

Examples

The tables in the following examples illustrate some of the effects achievable using the

element in conjunction with a different picture string.

Example 1: Comma as a Decimal Separator

This decimal format is used in many Western European countries; it uses a comma as a decimal point and a period (full stop) as a thousands separator, the reverse of the custom in Britain and North America.

The left-hand column shows the number as it would be written in XSLT. The middle column shows the picture string supplied as the second argument to the
format-number()
function. The right-hand column shows the string value returned by the
format-number()
function.

The patterns used in this example use the following symbols:

  • .
    , which I have defined as my thousands separator
  • ,
    , which I have defined as my decimal point
  • #
    , which is a position where a digit can occur, but where the digit is omitted if it is an insignificant zero
  • 0
    , which is a position where a digit will always occur, even if it is an insignificant zero
  • %
    , which indicates that the number should be expressed as a percentage
  • ;
    , which separates the subpicture used for positive numbers from the subpicture used for negative numbers


Number
Picture String
Result
1234.5
#.##0,00
1.234,50
123.456
#.##0,00
123,46
1000000
#.##0,00
1.000.000,00
−59
#.##0,00
59,00
1e0 div 0
#.##0,00
Infinity
1234
###0,0###
1234,0
1234.5
###0,0###
1234,5
.00035
###0,0###
0,0004
0.25
#00%
25%
0.736
#00%
74%
1
#00%
100%
42
#00%
4200%
−3.12
#,00;(#,00)
(3,12)
−3.12
#,00;#,00CR
3,12CR

Other books

Owned by the Vikings by Isabel Dare
The Cortés Enigma by John Paul Davis
The Faceless One by Mark Onspaugh
Flinch Factor, The by Michael Kahn
Things That Go Bump in the Night IV by Raine, Ashleigh, Wilder, J. C., O'Clare, Lorie
Marrying Harriet by Beaton, M.C.
Mad for Love by Elizabeth Essex
Bared to Him by Cartwright, Sierra
I Thee Wed by Celeste Bradley