I want to use the format-number function to output
a number with a specific number of decimals, based on the content of a node... Is there any smart way to generate differnet strings based on a node-value?
if decimals = 0, I want "###,###"
decimals = 1, I want "###,###.0"
decimals = 2, I want "###,###.00"
decimals = n, I want "###,###.000..n"
Today I'm using <xsl:choose>, but that is limited to
hand-coding the alternatives.
I have the following xml:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="Transform.xslt"?> <root> <valuedef> <value>7</value> <decimals>2</decimals> </valuedef> <valuedef> <value>42</value> <decimals>3</decimals> </valuedef> </root>
And I transform it like this:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl
utput method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="/root/valuedef" />
</xsl:template>
<xsl:template match="valuedef">
<value>
<xsl:variable name="tall" select="value"/>
<xsl:variable name="maske">
<xsl:choose>
<xsl:when test="decimals[.='0']"> ###,### </xsl:when> <xsl:when test="decimals[.='1']"> ###,###.0</xsl:when> <xsl:when test="decimals[.='2']"> ###,###.00</xsl:when> <xsl:when test="decimals[.='3']"> ###,###.000</xsl:when> <xsl
therwise> ###,### </xsl
therwise> </xsl:choose> </xsl:variable> <xsl:value-of select='format-number($tall, $maske)' /> </value> </xsl:template> </xsl:stylesheet>
TIA...
a number with a specific number of decimals, based on the content of a node... Is there any smart way to generate differnet strings based on a node-value?
if decimals = 0, I want "###,###"
decimals = 1, I want "###,###.0"
decimals = 2, I want "###,###.00"
decimals = n, I want "###,###.000..n"
Today I'm using <xsl:choose>, but that is limited to
hand-coding the alternatives.
I have the following xml:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="Transform.xslt"?> <root> <valuedef> <value>7</value> <decimals>2</decimals> </valuedef> <valuedef> <value>42</value> <decimals>3</decimals> </valuedef> </root>
And I transform it like this:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl
<xsl:template match="/">
<xsl:apply-templates select="/root/valuedef" />
</xsl:template>
<xsl:template match="valuedef">
<value>
<xsl:variable name="tall" select="value"/>
<xsl:variable name="maske">
<xsl:choose>
<xsl:when test="decimals[.='0']"> ###,### </xsl:when> <xsl:when test="decimals[.='1']"> ###,###.0</xsl:when> <xsl:when test="decimals[.='2']"> ###,###.00</xsl:when> <xsl:when test="decimals[.='3']"> ###,###.000</xsl:when> <xsl
TIA...