I am having some difficulties understanding how to use comma in format-number in XML.
For example,
<xsl:value-of select="format-number(123456,'####,##')"/>
gives me 12,34,56
But from what I read, the comma is a group separator, so I thought it should have been 1234,56. Clearly, I am understanding it wrong. Can someone explain it to me please?
I can see why you would expect 1234,56, and that’s what I expected too, until I went and looked carefully at the spec. It takes your picture ####,## and calculates the “integer-part-grouping positions” as the list of positions containing a grouping separator in your picture: this list is simply (2). It then says “if these integer-part-grouping-positions are at regular intervals (that is, if they form a sequence N, 2N, 3N, … for some integer value N, including the case where there is only one number in the list), then the sequence [of grouping positions] contains all integer multiples of N as far as necessary to accommodate the largest possible number.”
So the sequence of grouping positions here ends up being (2,4,6,8,…). The fact that your picture doesn’t have a grouping separator at position 4 doesn’t enter into the rules – it probably should, but it doesn’t. You would have to use a picture like #,################,## to achieve this formatting.
This is from XSLT 2.0, by the way. The XSLT 1.0 specification defines format-number by reference to the JDK 1.1.8 specification of DecimalFormat, which is extremely difficult to get hold of nowadays; and if memory serves me correctly, it leaves many detailed questions unanswered.