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"
<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>
</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>
</xsl:text>
<xsl:value-of select="@ScheduleDate"/><![CDATA[<EP>]]>
<xsl:text>
</xsl:text>
<xsl:apply-templates select="GROUP1"/>
</xsl:template>
<!--************************************************** **********************
********************************-->
<xsl:template name="Groupings" match="GROUP1">
<xsl:if test="string-length(@GroupName)>0">
<xsl:text>
</xsl:text><![CDATA[<bold>]]>
<xsl:value-of
select="string(@GroupName)"/><![CDATA[</bold>]]><![CDATA[<EP>]]>
<xsl:text>
</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>
</xsl:text><![CDATA[<bold>]]>
<xsl:value-of select="'Non-League'"/><![CDATA[</bold>]]><![CDATA[<EP>]]>
<xsl:text>
</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>
</xsl:text><![CDATA[<bold>]]>
<xsl:value-of
select="string(@GroupName)"/><![CDATA[</bold>]]><![CDATA[<EP>]]>
<xsl:text>
</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>
</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> - </xsl:text>
<xsl:value-of select="."/><xsl:text>
</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>
<QUARTER2SUMMARY>SG--Herrera 4 yd run SG--Pulido Kick xpt.(GOOD)
</QUARTER2SUMMARY>
<QUARTER3SUMMARY>SG--Vasquez 8 yd run SG--Pulido Kick (NO
GOOD)</QUARTER3SUMMARY>
<QUARTER4SUMMARY>SG--Kozasky 1 yd run SG--Vasquez Run xpt.
(GOOD)</QUARTER4SUMMARY>
<OVERTIMESUMMARY>
</OVERTIMESUMMARY>
</CONTEST>
</GROUP3>
<GROUP3 GroupName="Marine">
<CONTEST ContestName="Gardena 50, Franklin (Los Angeles) 12"
IsConferenceGame="0"/>
<CONTEST ContestName="Narbonne 14, Garfield 6" IsConferenceGame="0"/>
</GROUP3>
<GROUP3 GroupName="Northern">
<CONTEST ContestName="Eagle Rock 34, Hollywood 0"
IsConferenceGame="0"/>
<CONTEST ContestName="L.A. Marshall 29, Sun Valley Poly 10"
IsConferenceGame="0"/>
<CONTEST ContestName="L.A. Wilson 33, Alhambra (Alhambra) 19"
IsConferenceGame="0"/>
<CONTEST ContestName="Los Angeles 25, Palisades (Pacific Palisades)
18" IsConferenceGame="0"/>
<CONTEST ContestName="Roosevelt (Los Angeles) 44, Belmont 24"
IsConferenceGame="0">
<QUARTER1SUMMARY>Belmont--Field Goal </QUARTER1SUMMARY>
<QUARTER2SUMMARY>Belmont--50 yd. TD RUN. (conversion failed)
Roosevelt--(3:03)--Hurtado 25yd. TD RUN Roosevelt--(2:20)--Fredericks 25yd.
TD RUN</QUARTER2SUMMARY>
<QUARTER3SUMMARY>Roosevelt--(2:25)--Hurtado 4yd. TD
RUN</QUARTER3SUMMARY>
<QUARTER4SUMMARY>Roosevelt--(10:37)--Hurtado 1yd. TD RUN Belmont--TD
RUN. EXTRA POINT KICK Roosevelt--(6:16)--Padron 50yd. TD PASS from Holloway
Belmont--TD PASS. 2 PT. CONVERSION QB RUN. Roosevelt--(00:13)--Hurtado 9yd.
TD RUN</QUARTER4SUMMARY>
<OVERTIMESUMMARY>
</OVERTIMESUMMARY>
</CONTEST>
</GROUP3>
<GROUP3 GroupName="Valley Mission">
<CONTEST ContestName="North Hollywood 23, Van Nuys 6"
IsConferenceGame="0"/>
</GROUP3>
<GROUP3 GroupName="West Valley">
<CONTEST ContestName="Granada Hills 34, San Fernando 6"
IsConferenceGame="0">
<QUARTER1SUMMARY>
</QUARTER1SUMMARY>
<QUARTER2SUMMARY>
</QUARTER2SUMMARY>
<QUARTER3SUMMARY>
</QUARTER3SUMMARY>
<QUARTER4SUMMARY>
</QUARTER4SUMMARY>
<OVERTIMESUMMARY>
</OVERTIMESUMMARY>
</CONTEST>
<CONTEST ContestName="Taft (Woodland Hills) 28, Jefferson (Los Angeles)
19" IsConferenceGame="0"/>
</GROUP3>
<GROUP3 GroupName="Western">
<CONTEST ContestName="Fremont (Los Angeles) 12, L.A. University 12"
IsConferenceGame="0"/>
<CONTEST ContestName="L.A. University 12, Fremont (Los Angeles) 12"
IsConferenceGame="0"/>
<CONTEST ContestName="San Pedro 31, Westchester 0"
IsConferenceGame="0"/>
</GROUP3>
</GROUP2>
</GROUP1>
</SCHEDULE>
</SPORT>