XSL Formatting
-
Monday, February 27, 2012 12:28 PM
Hi,
I am trying to format a decimal value, Say I have 123.1234567, all I want to do is, if the value that I am reading has more than 12 digits after the decimal point, I need to take only 12 digits, eg: 12.12345678012345, from this get only 12.123456780123.
If the value is less than 12 digits do not do any formatting.
I tried format-number, but when the value is less, it converts to NaN automatically. I do not want this to happen. Is there a way I can do this? Please help. Thanks.
Rpaul
All Replies
-
Monday, February 27, 2012 12:46 PM
format-number(num, '0.############')
Use 12 signs #. -
Monday, February 27, 2012 1:01 PM
Can you post a sample of the XML input and the XSLT code that produces NaN? Which XSLT processor do you use? I don't see any immediate relationship between format-number and a NaN result.
MVP Data Platform Development My blog
-
Monday, February 27, 2012 6:15 PM
Hi,
You can use <xsl:decimal-format> element as follow:
XML input:
<?xml version="1.0" encoding="utf-8"?> <root> <number>12.12345678012345612345456623</number> <number>12.123456780125566788999</number> <number>12.123456780125</number> <number>12.12345678</number> </root>
XSLT:
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> <xsl:template match="number"> <xsl:value-of select="format-number(., '#.############')"/> </xsl:template> </xsl:stylesheet>XML output:
<?xml version="1.0" encoding="utf-8"?> <root> 12.123456780124 12.123456780126 12.123456780125 12.12345678 </root>
Kind regards,My blog
Whether you’re a construction worker, a forum moderator, or just someone that likes helping people. I think these guidelines can be helpful in keeping you helpful when being helpful.- Marked As Answer by Alan_chenModerator Tuesday, March 06, 2012 9:19 AM
-
Friday, March 02, 2012 9:03 AMModerator
Hi,
I am writing to check the status of the issue on your side. Would you mind letting us know the result of the suggestions?
If you need further assistance, please feel free to let me know. I will be more than happy to be of assistance.Have a nice day.
Alan Chen[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.


