Miguel Oz
asked on
XSLT: Is it possible to assign number format from a variable?
I am converting XML to Excel via XSLT
If it is not possible what is the best practice to do that. The xml contains the numbers already formatted but they could be 123.45 or 123.00
By default Excel ignores the .00.
<xsl:variable name="numberFormat" select="###,##0.00" />
<Styles>
<Style ss:ID="ShowAsNumber1">
<NumberFormat ss:Format=numberFormat/> <= Assign the format here.
</Style>
</Styles>
If it is not possible what is the best practice to do that. The xml contains the numbers already formatted but they could be 123.45 or 123.00
By default Excel ignores the .00.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Your xslt comments do not seem to work for me. IT gives me "HTTP Error 503. The service is unavailable." (typically means that XSL can not be processed in the Ecrion server)
Note:PFA the detail error If I run XF designer against my XML.
It is weird because if I use the same format string directly in XSLT it works OK.
2016-10-31-XFDesigner-Error.png
Note:PFA the detail error If I run XF designer against my XML.
It is weird because if I use the same format string directly in XSLT it works OK.
2016-10-31-XFDesigner-Error.png
Ah well,
<xsl:variable name="numberFormat" select="###,##0.00" />
should be
<xsl:variable name="numberFormat" select="'###,##0.00'" />
(extra single quotes added inside)
the @select does not have a valid XPath, it is looking for an element ###,##0.00, not the string value
<xsl:variable name="numberFormat" select="###,##0.00" />
should be
<xsl:variable name="numberFormat" select="'###,##0.00'" />
(extra single quotes added inside)
the @select does not have a valid XPath, it is looking for an element ###,##0.00, not the string value
ASKER
Thanks for your help your comment guided me in the right direction.
For anyone looking for the correct answer, my value comes from xml node:
[code]<xsl:variable name="user:numberFormat" select="MyRootNode/NumberF ormat/text ()"/>[/cod e]
The code that works is shown below:
[code]
<Style ss:ID="ShowAsNumber">
<NumberFormat>
<xsl:attribute name="ss:Format">
<xsl:value-of select="$user:numberFormat " disable-output-escaping="y es"/>
</xsl:attribute>
</NumberFormat>
</Style>[/code]
For anyone looking for the correct answer, my value comes from xml node:
[code]<xsl:variable name="user:numberFormat" select="MyRootNode/NumberF
The code that works is shown below:
[code]
<Style ss:ID="ShowAsNumber">
<NumberFormat>
<xsl:attribute name="ss:Format">
<xsl:value-of select="$user:numberFormat
</xsl:attribute>
</NumberFormat>
</Style>[/code]
<Style ss:ID="ShowAsNumber1">
<NumberFormat ss:Format="{$numberFormat}
</Style>