Microsoft KB Archive/832757

= FIX: A System.Xml.Xsl.XsltException exception occurs when you try to perform an XSLT transformation by using an XSLT style sheet that uses the format-number function =

Article ID: 832757

Article Last Modified on 5/21/2007

-

APPLIES TO


 * Microsoft .NET Framework 1.1

-





SUMMARY
''You create an Extensible Stylesheet Language Transformation (XSLT) style sheet that uses the format-number function. In Microsoft Visual Studio .NET, when you perform an XSLT transformation that uses this style sheet to try to convert positive numbers to strings, a System.Xml.Xsl.XsltException exception occurs. To resolve the problem, download and install a hotfix. To obtain the hotfix, contact Microsoft Product Support Services.

''



SYMPTOMS
You can create an Extensible Stylesheet Language Transformation (XSLT) style sheet that uses the format-number function. In Microsoft Visual Studio .NET, when you try to perform an XSLT transformation by using this style sheet to convert positive numbers to strings, you receive the following error message:

An unhandled exception of type 'System.Xml.Xsl.XsltException' occurred in system.xml.dll

If you handle the exception to display the inner exception and the exception message, you receive the following output:

System.ArgumentException: NumberGroupSizes

Parameter name: Every element in the value array should be between one and nine, except for the last element, which can be zero.

at System.Globalization.NumberFormatInfo.CheckGroupSize(String propName, Int32[] groupSize)

at System.Xml.Xsl.XsltCompileContext.FormatNumber(Double value, String formatPattern, String formatName)

at System.Xml.Xsl.FuncFormatNumber.Invoke(XsltContext xsltContext, Object[] args, XPathNavigator docContext)

at System.Xml.XPath.XsltFunction.InvokeFunction(XPathNavigator qy, XPathNodeIterator iterator)

Function 'format-number' has failed.



RESOLUTION
A supported hotfix is now available from Microsoft, but it is only intended to correct the problem that is described in this article. Only apply it to systems that are experiencing this specific problem. This hotfix may receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next service pack that contains this hotfix.

To resolve this problem immediately, contact Microsoft Product Support Services to obtain the hotfix. For a complete list of Microsoft Product Support Services telephone numbers and information about support costs, visit the following Microsoft Web site:

http://support.microsoft.com/contactus/?ws=support

Note In special cases, charges that are ordinarily incurred for support calls may be canceled if a Microsoft Support Professional determines that a specific update will resolve your problem. The usual support costs will apply to additional support questions and issues that do not qualify for the specific update in question. The English version of this hotfix has the file attributes (or later) that are listed in the following table. The dates and times for these files are listed in coordinated universal time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time tool in Control Panel.   Date         Time   Version            Size    File name --  03-Dec-2003  19:43  1.1.4322.978    1,339,392  System.xml.dll



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the &quot;Applies to&quot; section.



Steps to reproduce the behavior
 ==== Create a Console Application project ====

 Start Microsoft Visual Studio .NET 2003. On the File menu, point to New, and then click Project. Under Project Types, click Visual C# Projects, and then click Console Application under Templates. In the Name box, type FormatNumConsole .</li> Click OK. By default, the Class1.cs Code window opens.</li></ol> </li> ==== Create an XSLT style sheet that uses the format-number function ====

<ol style="list-style-type: lower-alpha;"> In Solution Explorer, right-click FormatNumConsole, point to Add, and then click Add New Item. The Add New Item - FormatNumConsole dialog box appears.</li> Under Categories, click Local Project Items.</li> Under Templates, click XSLT File.</li> In the Name box, type format-number.xslt, and then click Open. The format-number.xslt Code window opens.</li>  Replace the existing XML code with the following XML code to create a template for the presentation of XML data: <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> <xsl:output method=&quot;xml&quot; version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; indent=&quot;yes&quot;/> <xsl:template match=&quot;/&quot;> </xsl:template> <xsl:template match=&quot;number&quot;> <xsl:value-of select=&quot;format-number(.,'#,##0;(#,##0)')&quot;/> </xsl:template> </xsl:stylesheet> </li></ol> </li> ==== Create an XML file that provides XML data ====

<ol style="list-style-type: lower-alpha;"> In Solution Explorer, right-click FormatNumConsole, point to Add, and then click Add New Item. The Add New Item - FormatNumConsole dialog box appears.</li> Under Templates, click XML File.</li> In the Name box, type format-number.xml, and then click Open. The format-number.xml Code window opens.</li>  Replace the existing XML code with the following XML code to provide XML data: <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> 1000 </li></ol> </li> ==== Try to perform an XSLT transformation by using the XSLT style sheet and the XML file ====

<ol style="list-style-type: lower-alpha;"> Switch to the Class1.cs Code window.</li>  Replace the existing code with the following code to use the XslTransform class to transform the XML data by using the XSLT style sheet.

Note In the following code, use the appropriate file paths in the calls to the XPathDocument constructor and the xsltProcessor.Load method: using System; using System.Xml; using System.Xml.XPath; using System.Xml.Xsl; using System.IO; using System.Text;

namespace FormatNumConsole {   class Class1 {       [STAThread] static void Main(string[] args) {           try {               StringBuilder sb = new StringBuilder; StringWriter sw = new StringWriter(sb);

// Load the XML data that you want to transform. XPathDocument xmlDoc = new XPathDocument(&quot;C:\\FormatNumConsole\\format-number.xml&quot;);

// Load the XSLT style sheet that uses the format-number function. XslTransform xsltProcessor = new XslTransform; xsltProcessor.Load(&quot;C:\\FormatNumConsole\\format-number.xslt&quot;);

// Transform the XML data, and then send the output to the console. xsltProcessor.Transform(xmlDoc,null,sw,null); }           catch(Exception ex) {               // Display the inner exception and the exception message. Console.WriteLine(ex.InnerException.ToString); Console.WriteLine; Console.WriteLine(ex.Message); Console.ReadLine; }       }    } } </li> <li>Build the application, and then run the application. The output that is mentioned in the &quot;Symptoms&quot; section appears in a console window.</li></ol> </li></ol>

<div class="references_section">