Microsoft KB Archive/318360

= FIX: The xsl:number Element Generates an Exception Error When the Format Pattern Is Set to &quot;A.1&quot; =

Article ID: 318360

Article Last Modified on 9/16/2003

-

APPLIES TO


 * Microsoft .NET Framework 1.0

-



This article was previously published under Q318360



SYMPTOMS
When the format pattern is set to &quot;A.1&quot;, xsl:number generates the following exception error message:

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll

Additional information: Index was out of range. Must be non-negative and less than the size of the collection.



STATUS
This bug was corrected in Microsoft .NET Framework Class Libraries 1.1.



MORE INFORMATION
The xsl:number element inserts a formatted number in the result tree. The number to be inserted is specified by an expression that is contained in the value attribute. The expression is evaluated and the resulting object is converted to a number. The number is rounded to an integer, converted to a string, and then inserted in the result tree.

A format is a sequence of tokens that specifies the format that is to be used for each number in the list. If no format tokens exist, the default value of 1 is used. This value generates a sequence (for example, 1 2 ... 10 11 12 ...). Each number after the first is separated from the preceding number by the separator token that precedes the format token that is used to format that number. If no separator tokens exist, a period (.) is used.

Steps to Reproduce the Behavior
 In Microsoft Visual C# .NET, create a new Console Application project.  Paste the following XML in a text file, and then save the file as C:\Test.xml:    1953-09-22    Book 1  Joe Bob Trenton Literary Review Honorable Mention <book style=&quot;textbook&quot;> 1999-01-01        Book 2 <author id = &quot;2&quot;> Mary</first-name> Bob</last-name> Publication 1 Mary</first-name> Bob</last-name> <author id = &quot;3&quot;> Second</first-name> Author</last-name> <magazine style=&quot;glossy&quot; frequency=&quot;monthly&quot;> Road and Track <subscription price=&quot;24&quot; per=&quot;year&quot;/> <special_edition per_year=&quot;1&quot;>Yes</special_edition>

</li>  Paste the following XSLT in a text file, and then save the file as C:\Test.xsl: <xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot; xmlns:my=&quot;http://my.com&quot;>

<xsl:output encoding=&quot;UTF-8&quot; indent=&quot;yes&quot; omit-xml-declaration=&quot;yes&quot;/>

<xsl:template match=&quot;/&quot;> <xsl:apply-templates select=&quot;//last-name&quot; mode=&quot;formatting-tests&quot;/> </xsl:template>

<xsl:template match=&quot;last-name&quot; mode=&quot;formatting-tests&quot;>

<xsl:number level=&quot;multiple&quot; count=&quot;last-name | publication | author | book&quot; format=&quot;A.1&quot;/><xsl:text>, </xsl:text>

<xsl:value-of select=&quot;concat(../first-name, ' ', .)&quot;/>

</xsl:template>

</xsl:stylesheet> </li>  Use the following namespaces: using System; using System.Xml; using System.Xml.XPath; using System.Xml.Xsl; using System.IO; </li>  Paste the following code in static void Main(string[] args): XmlDocument xmldoc = new XmlDocument ; //Load the XML document. xmldoc.Load(&quot;c:\\test.xml&quot;);

XPathNavigator xpathdoc; xpathdoc = xmldoc.CreateNavigator;

XslTransform xsltdoc = new XslTransform; xsltdoc.Load(&quot;c:\\test.xsl&quot;); //Create a FileStream to store the XSL output. FileStream fs = new FileStream(&quot;test2.xml&quot;, FileMode.Create); //Transform the XML document. xsltdoc.Transform(xpathdoc,null,fs); </li>  Build and run the project. Note that the error occurs on the Transform method of the XslTransform object. You expect the following output: <pre class="fixed_text">A.1.1, Joe BobB.1.1, Mary BobB.1.2.1, Mary BobB.2.1, Second Author </li></ol>

<div class="references_section">