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 translations Article translations
Article ID: 832757 - View products that this article applies to.
Expand all | Collapse all

On This Page

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 "Applies to" section.

MORE INFORMATION

Steps to reproduce the behavior

  1. Create a Console Application project

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

    1. In Solution Explorer, right-click FormatNumConsole, point to Add, and then click Add New Item. The Add New Item - FormatNumConsole dialog box appears.
    2. Under Categories, click Local Project Items.
    3. Under Templates, click XSLT File.
    4. In the Name box, type format-number.xslt, and then click Open. The format-number.xslt Code window opens.
    5. Replace the existing XML code with the following XML code to create a template for the presentation of XML data:
      <?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" version="1.0" encoding="UTF-8" indent="yes"/>
          <xsl:template match="/">
              <table>
                  <xsl:apply-templates />
              </table>
          </xsl:template>
          <xsl:template match="number">
              <tr><td><xsl:value-of select="format-number(.,'#,##0;(#,##0)')"/></td></tr>
          </xsl:template>
      </xsl:stylesheet>
  3. Create an XML file that provides XML data

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

    1. Switch to the Class1.cs Code window.
    2. 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("C:\\FormatNumConsole\\format-number.xml");
      
                      // Load the XSLT style sheet that uses the format-number function.
                      XslTransform xsltProcessor = new XslTransform();
                      xsltProcessor.Load("C:\\FormatNumConsole\\format-number.xslt");
      
                      // 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();
                  }
              }
          }
      }
    3. Build the application, and then run the application. The output that is mentioned in the "Symptoms" section appears in a console window.

REFERENCES

For additional information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
824684 Description of the standard terminology that is used to describe Microsoft software updates
307494 How to apply an XSL Transformation to XML for streaming by using Visual C# .NET
For more information, visit the following Microsoft Developer Network (MSDN) Web sites:
XsltException class
http://msdn2.microsoft.com/en-us/library/system.xml.xsl.xsltexception(vs.71).aspx
format-number function
http://msdn2.microsoft.com/en-us/library/ws343esk.aspx
XslTransform class
http://msdn2.microsoft.com/en-us/library/system.xml.xsl.xsltransform(vs.71).aspx

Properties

Article ID: 832757 - Last Review: May 21, 2007 - Revision: 2.4
APPLIES TO
  • Microsoft .NET Framework 1.1
Keywords: 
kbqfe kbhotfixserver kbbug kbformat kbstyle kbxml kbsample kberrmsg kbcode kbfix KB832757

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com