Domanda

I have a number such as: 457342137 but i want to display it as a 457 342 137.

I have something like this:

<xsl:template match="klient/@numer_telefonu">
        <xsl:variable name="numer" select="." />
        <xsl:value-of select="format-number($numer, '###&nbsp;###&nbsp;###')" />
    </xsl:template>

but it does not work.

È stato utile?

Soluzione 2

A telephone number is a string, not a number and you shouldn't try formatting it as one. Technically, you could do:

<xsl:value-of select="translate(format-number(., '#,###'), ',', ' ' )" />

to achieve the desired result in your example. However, given a "number" such as "057342137" the result will be "57 342 137" (leading zeros stripped). You should be using string functions to manipulate a string.

Altri suggerimenti

If you want to use a non-standard 'grouping' separator, you first need define the symbols you are going to use in your format command as follows:

<xsl:decimal-format name="spaces" grouping-separator=" " />

Then, you can reference this format in the command itself as follows:

<xsl:value-of select="format-number($numer, '# ###', 'spaces')" />

Further information about decimal-format can be found at http://www.w3.org/TR/xslt#format-number

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top