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> </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>