all groups > dotnet xml > september 2003 >
You're in the

dotnet xml

group:

Possible Bug: ArgumentOutOfRangeException when using xsl:sort and xsl:strip-space has been declared



Possible Bug: ArgumentOutOfRangeException when using xsl:sort and xsl:strip-space has been declared Mark Miller
9/30/2003 12:26:13 PM
dotnet xml: I have a scheduled job that uses different XSL templates to transform XML
and save it to disk. I am having problems with the code below. The problem
shows up on both my development machine (Windows XP Pro SP 1, .Net Framework
1.1) and on our production server (Windows 2K SP 4, .Net Framework 1.1). I
have simplified the code and data to isolate the problem. When I use the
xsl:strip-space (Line 12) declaration in conjunction with the xsl:sort
element located on Line 80 I get an ArgumentOutOfRangeException thrown. If I
comment out either line everything works fine. The extra twist is that there
are two xsl:sort elements in the XSL document but only one which causes the
problem. Can anyone tell me what the problem is? Or could someone else
confirm that this is a problem. I would appreciate the help. Thank you.

Regards,
Mark Miller


//------------------Code---------------------------------

class Export
{
[STAThread]
static void Main(string[] args){
try{
TextReader xmlBox =
(TextReader)File.OpenText(@"C:\Projects\XML-XSLT\SHStylesheets\Input.txt");
XPathDocument xDoc = new XPathDocument(xmlBox);
XPathNavigator xPath = xDoc.CreateNavigator();

XslTransform Xslt = new XslTransform();
Xslt.Load(@"C:\Projects\XML-XSLT\SHStylesheets\BoxScores.xsl");

StringBuilder sbXML = new StringBuilder();
StringWriter txtOutput = new StringWriter(sbXML);
try{
Xslt.Transform(xPath, null, txtOutput, null); //<---Exception is
raised here
}finally{
txtOutput.Close();
}

StreamWriter swOutput =
File.CreateText(@"C:\Projects\XML-XSLT\SHStylesheets\Output.txt");
try{
swOutput.WriteLine(sbXML.ToString());
}finally{
swOutput.Close();
}
Console.WriteLine("Success");
}catch(Exception ex){
Console.WriteLine(ex.Message + "\r\n" + ex.StackTrace);
}
Console.ReadLine();
}

}

//------------------BoxScores.xsl--------------------------------------
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns="urn:schemas-microsoft-com:xml-data"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dt="urn:schemas-microsoft-com:datatypes"
[quoted text, click to view]

<xsl:output method="text" indent="yes" omit-xml-declaration="yes"/>

<!--THIS IS THE LINE THAT WHEN COMBINED WITH THE xsl:sort BELOW CAUSES THE
PROBLEM - IF I COMMENT OUT ONE OR THE OTHER
THERE IS NO ERROR-->
<!--<xsl:strip-space elements="QUARTER1SUMMARY QUARTER2SUMMARY
QUARTER3SUMMARY QUARTER4SUMMARY OVERTIMESUMMARY"/>-->

<!--************************************************************************
********************************-->

<xsl:template match="/">

<xsl:value-of
select="//SPORT/@SportName"/><![CDATA[<EP>]]><xsl:text>&#13;&#10;</xsl:text>
<xsl:apply-templates select="//SCHEDULE">
<xsl:with-param name="Sport" select="//SPORT/@SportName"/>
</xsl:apply-templates>

</xsl:template>

<!--************************************************************************
********************************-->

<xsl:template match="SCHEDULE">
<xsl:param name="Sport"/>

<xsl:text>&#13;&#10;</xsl:text>
<xsl:value-of select="@ScheduleDate"/><![CDATA[<EP>]]>
<xsl:text>&#13;&#10;</xsl:text>

<xsl:apply-templates select="GROUP1"/>
</xsl:template>

<!--************************************************************************
********************************-->

<xsl:template name="Groupings" match="GROUP1">

<xsl:if test="string-length(@GroupName)>0">
<xsl:text>&#13;&#10;</xsl:text><![CDATA[<bold>]]>
<xsl:value-of
select="string(@GroupName)"/><![CDATA[</bold>]]><![CDATA[<EP>]]>
<xsl:text>&#13;&#10;</xsl:text>
</xsl:if>

<!--Section name-->
<!--League Name-->
<!--League Games-->
<!--"NonConference" Heading-->
<!--Non League Games-->

<xsl:apply-templates select="GROUP2/GROUP3"/>

<xsl:if test="GROUP2/GROUP3/CONTEST[@IsConferenceGame=0]">
<xsl:text>&#13;&#10;</xsl:text><![CDATA[<bold>]]>
<xsl:value-of select="'Non-League'"/><![CDATA[</bold>]]><![CDATA[<EP>]]>
<xsl:text>&#13;&#10;</xsl:text>
<xsl:apply-templates select="GROUP2/GROUP3/CONTEST[@IsConferenceGame=0]"
mode="Football">
<xsl:sort select="@ContestName" data-type="text" order="ascending"/>
</xsl:apply-templates>
</xsl:if>
</xsl:template>

<!--************************************************************************
********************************-->

<xsl:template name="Leagues" match="GROUP3">

<xsl:if test="string-length(@GroupName)>0 and
CONTEST[@IsConferenceGame=1]">
<xsl:text>&#13;&#10;</xsl:text><![CDATA[<bold>]]>
<xsl:value-of
select="string(@GroupName)"/><![CDATA[</bold>]]><![CDATA[<EP>]]>
<xsl:text>&#13;&#10;</xsl:text>
</xsl:if>

<xsl:choose>
<xsl:when test="//SPORT/@SportName='Football' or
//SPORT/@SportName='football'">
<xsl:apply-templates select="CONTEST[@IsConferenceGame=1]"
mode="Football">
<!--THIS IS THE LINE THAT WHEN COMBINED WITH THE xsl:strip-space ABOVE
CAUSES THE PROBLEM - IF I COMMENT OUT ONE OR THE OTHER
THERE IS NO ERROR-->
<xsl:sort select="@ContestName" data-type="text" order="ascending"/>
</xsl:apply-templates>
</xsl:when>
<!-- xsl:apply-templates FOR OTHER SPORTS -->
</xsl:choose>
</xsl:template>

<!--************************************************************************
********************************-->

<xsl:template match="CONTEST" mode="Football">
<xsl:value-of select="@ContestName"/><![CDATA[<EP>]]>
<xsl:text>&#13;&#10;</xsl:text>

<!--
<xsl:apply-templates select="QUARTER1SUMMARY | QUARTER2SUMMARY |
QUARTER3SUMMARY | QUARTER4SUMMARY | OVERTIMESUMMARY"/>
-->
</xsl:template>

<!--************************************************************************
********************************-->

<xsl:template match="QUARTER1SUMMARY | QUARTER2SUMMARY | QUARTER3SUMMARY |
QUARTER4SUMMARY | OVERTIMESUMMARY" mode="Football">
<xsl:if test="string-length(.)>0">
<xsl:value-of select="name(.)"/><xsl:text>&#09; - </xsl:text>
<xsl:value-of select="."/><xsl:text>&#13;&#10;</xsl:text>
</xsl:if>
</xsl:template>

<!--************************************************************************
********************************-->

</xsl:stylesheet>


//------------------Input.txt-------------------------------------
<SPORT SportName="football">
<SCHEDULE ScheduleDate="09-26-20">
<GROUP1 GroupName="LA City Section">
<GROUP2 GroupName="LA City Division">
<GROUP3 GroupName="Coliseum">
<CONTEST ContestName="Crenshaw 34, Hawthorne 0" IsConferenceGame="0"/>
</GROUP3>
<GROUP3 GroupName="Eastern">
<CONTEST ContestName="Bell 49, Lincoln (Los Angeles) 20"
IsConferenceGame="0"/>
<CONTEST ContestName="L. A. Jordan 21, Washington (Los Angeles) 12"
IsConferenceGame="0"/>
<CONTEST ContestName="Locke 24, South Gate 21" IsConferenceGame="0">
<QUARTER1SUMMARY>No Scoring</QUARTER1SUMMARY>
Re: Possible Bug: ArgumentOutOfRangeException when using xsl:sort and xsl:strip-space has been declared Mark Miller
9/30/2003 2:46:00 PM
I appreciate the response. I'll check to see if the same will work on my
system. However, I need to be able to use Transform from a class because I
am getting the XML from Sql server, so is there any way you could tell me
what is wrong with my code then? I am calling this from a compiled exe
(project type console application).

Regards,
Mark


[quoted text, click to view]
<!--************************************************************************
Re: Possible Bug: ArgumentOutOfRangeException when using xsl:sort and xsl:strip-space has been declared Mark Miller
9/30/2003 2:55:38 PM
I have run the stylesheet w/ nXslt.exe and confirmed that yes it does work
fine. However, I still am getting the following when I run it with my code
from a console app:

Index was out of range. Must be non-negative and less than the size of the
collection.
Parameter name: index
at System.Collections.ArrayList.get_Item(Int32 index)
at System.Xml.Xsl.XPathSortArrayIterator.get_Current()
at System.Xml.Xsl.ActionFrame.NewNextNode(Processor proc)
at System.Xml.Xsl.ApplyTemplatesAction.Execute(Processor processor,
ActionFrame frame)
at System.Xml.Xsl.ActionFrame.Execute(Processor processor)
at System.Xml.Xsl.Processor.Execute()
at System.Xml.Xsl.XslTransform.Transform(XPathNavigator input,
XsltArgumentList args, TextWriter output, XmlResolver resolver)
at Sporsthuddle.Components.SH_XMLAutoExport.Export.Main(String[] args) in
c:\projects\components\sportshuddle\sh_xmlautoexport\export.cs:line 40

Could someone PLEASE let me know what I am doing wrong?

Regards,
Mark

[quoted text, click to view]
Re: Possible Bug: ArgumentOutOfRangeException when using xsl:sort and xsl:strip-space has been declared Dimitre Novatchev
9/30/2003 10:33:29 PM
I am sorry, I uncommented the xsl:strip line but I cannot reproduce your
problem.

I am invoking .Net xsltTransform using the nXSLT.exe command-line utility.

My configuration: W2K (latest SP), .Net Framework 1.1


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL


[quoted text, click to view]
Re: Possible Bug: ArgumentOutOfRangeException when using xsl:sort and xsl:strip-space has been declared SQL Server Development Team [MSFT]
10/1/2003 11:40:02 AM
Yes, this is a bug in .Net 1.1. It will be fixed in SP1.

-Helena Kupkova, MS

--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.
[quoted text, click to view]

Re: Possible Bug: ArgumentOutOfRangeException when using xsl:sort and xsl:strip-space has been declared Oleg Tkachenko
10/1/2003 12:47:58 PM
[quoted text, click to view]

Yeah, I get the same exception. It only appears under .NET 1.1. Works fine in
..NET 1.0 and nxslt.exe (hmmm, apparently it uses .NET 1.0).
There is something wrong with sorting when apply-templates selects empty nodeset.

<xsl:apply-templates select="CONTEST[@IsConferenceGame=1]"
mode="Football">
<xsl:sort select="@ContestName" data-type="text" order="ascending"/>
</xsl:apply-templates>

Here CONTEST[@IsConferenceGame=1] is empty nodeset, because there is no such
elements in XML. That stimulate the bug to appear.

You can use simple workaround, which should work:
<xsl:if test="CONTEST[@IsConferenceGame=1]">
<xsl:apply-templates select="CONTEST[@IsConferenceGame=1]"
mode="Football">
<xsl:sort select="@ContestName" data-type="text" order="ascending"/>
</xsl:apply-templates>
</xsl:if>
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel
Re: Possible Bug: ArgumentOutOfRangeException when using xsl:sort and xsl:strip-space has been declared Mark Miller
10/1/2003 6:05:37 PM
Is there a release date for SP 1?


[quoted text, click to view]

AddThis Social Bookmark Button