This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Number formatting: <xsl:number> vs. format-number()



Ragnar Schierholz asks what could be a FAQ:
>For some reason I get both the newly formatted and the original number
>when I use the "format-number" function but only the newly formatted
>number when I use <xsl:number>. Is this behaviour correct?

You should be using xsl:number only to generate numbering on outputted
items. Yes, <xsl:number value="number-expression" ...> is capable of
applying some limited formatting to the expression IF that expression
is a positive integer, but format-number() gives much better control.
You can use xsl:number to format number-expressions into Roman
numerals if you wish, and that might have been your intent in the
example you gave, but as a general rule xsl:number is not the tool to
format values stored in variables.

You said format-number($combinationIndex,'I') in your example, but
format-number uses formatting strings (second argument) that are more
pictorial than the limited xsl:number vocabulary. One thing that both
do is pass through non-magic strings, like so:
format-number(12,'(##)') gives '(12)'
<xsl:number value="12" format="(1)"/> gives '(12)'
In both cases, the parentheses are non-magic and thus just come out
as-is. But I is non-magic in format-number, so you were asking for
return of a constant 'I' with nothing representing the value to be
formatted! When using format-number(), plan on explicitly marking
every decimal place, the decimal point, all commas, etc.

Furthermore, notice that format-number() is a function that
returns a string, so additional processing like use of other
string functions can be applied. OTOH, xsl:number is an output
instruction, just like xsl:value-of.
.................David Marston


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]