Possible bug in the XsltCompileException and XslTransform classes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Greetings

When checking for an Xslt Compile Exception, I found the message property did not contain the complete message. Instead there was an inner exception of type XsltException that contained the correct message, but zero for the line and postion properties. Here is the output from my debug statements

XsltCompileException Message Contents: (5,2)

XsltCompileException Message Length:
XsltCompileException Line Number:
XsltCompileException Line Position:

XsltCompileException InnerException Message Contents: './Exception' is an invalid XPath expression
XsltCompileException InnerException Message Length: 4
XsltCompileException InnerException Line Number:
XsltCompileException InnerException Line Position:

Below I have included the XSL style sheet and the code I was using.

Question:

Is this a bug in the framwork, or did I miss something when I was reading the SDK documentation?

Cheers

John
-----------------------------------------------------------------------------------------------------------------------------------------------------
Here is the style sheet I was using

<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"><xsl:output method="text" /><xsl:template match="./Exception"
using System

namespace DMH.Framework.Dat

/// &lt;summary
/// The exception that is thrown when <xsl:value-of select="Description" /
/// &lt;/summary
public class <xsl:value-of select="Name" />Exception : GeneralExceptio

public <xsl:value-of select="Name" />Exception():base(){
public <xsl:value-of select="Name" />Exception(string message):base(message){}
public <xsl:value-of select="Name" />Exception(string message, Exception ex):base(message, ex){}

public static string FormatMessage(<xsl:apply-templates select="Parms" mode="MethodArgs" />

return String.Format(" <xsl:value-of select="MessageString" />", <xsl:apply-templates select="Parms" mode="MessageArgs" />);


public override int ErrorNumbe

get {return <xsl:value-of select="ErrorNumber" />;



</xsl:template><xsl:template match="Parms" mode="MethodArgs" ><xsl:apply-templates select="Parm" mode="MethodArgs" /></xsl:template><xsl:template match="Parm" mode="MethodArgs"><xsl:text>string </xsl:text><xsl:value-of select="." /><xsl:if test="position()!=last()">, </xsl:if></xsl:template><xsl:template match="Parms" mode="MessageArgs" ><xsl:apply-templates select="Parm" mode="MessageArgs" /></xsl:template><xsl:template match="Parm" mode="MessageArgs"><xsl:value-of select="." /><xsl:if test="position()!=last()">, </xsl:if></xsl:template></xsl:stylesheet

----------------------------------------------------------------------------------------------------------------------------------------------------------
Here is the code snip

StringReader sReader = new StringReader(this.XSLText.Text);
XmlTextReader xReader = new XmlTextReader(sReader)
//Load the stylesheet

//Create a new XslTransform object
XslTransform xslt = new XslTransform()

tr

xslt.Load(xReader);

catch(XsltCompileException ex


Debug.WriteLine(ex.Message, "XsltCompileException Message Contents");
Debug.WriteLine(ex.Message.Length, "XsltCompileException Message Length")
Debug.WriteLine(ex.LineNumber, "XsltCompileException Line Number");
Debug.WriteLine(ex.LinePosition, "XsltCompileException Line Position")

if(ex.InnerException != null && ex.InnerException is XsltException

XsltException iex = (XsltException)ex.InnerException;
Debug.WriteLine(iex.Message, "XsltCompileException InnerException Message Contents");
Debug.WriteLine(iex.Message.Length, "XsltCompileException InnerException Message Length")
Debug.WriteLine(iex.LineNumber, "XsltCompileException InnerException Line Number");
Debug.WriteLine(iex.LinePosition, "XsltCompileException InnerException Line Position")
 
Well,

You have <xsl:template match="./Exception">

in the stylesheet and I don't think it is valid. I don't understand what
else you mean, but it should be just "Exception" and you should control the
flow of transformation by first matching to "/" (root) and from there using
<xsl:apply:templates...> and so on to get it to the correct track with the
elements to be processed.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

John Morrill said:
Greetings!

When checking for an Xslt Compile Exception, I found the message property
did not contain the complete message. Instead there was an inner exception
of type XsltException that contained the correct message, but zero for the
line and postion properties. Here is the output from my debug statements:
XsltCompileException Message Contents: (5,2) :

XsltCompileException Message Length: 8
XsltCompileException Line Number: 5
XsltCompileException Line Position: 2

XsltCompileException InnerException Message Contents: './Exception' is an invalid XPath expression.
XsltCompileException InnerException Message Length: 45
XsltCompileException InnerException Line Number: 0
XsltCompileException InnerException Line Position: 0


Below I have included the XSL style sheet and the code I was using.

Question:

Is this a bug in the framwork, or did I miss something when I was reading the SDK documentation?

Cheers!

John
-------------------------------------------------------------------------- ----------------------------------------------------------------------------
Here is the style sheet I was using:

<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"><xsl:output method="text"
/> said:
using System;

namespace DMH.Framework.Data
{
/// &lt;summary>
/// The exception that is thrown when <xsl:value-of select="Description" />
/// &lt;/summary>
public class <xsl:value-of select="Name" />Exception : GeneralException
{
public <xsl:value-of select="Name" />Exception():base(){}
public <xsl:value-of select="Name" />Exception(string message):base(message){}
public <xsl:value-of select="Name" />Exception(string message, Exception ex):base(message, ex){}

public static string FormatMessage(<xsl:apply-templates select="Parms" mode="MethodArgs" />)
{
return String.Format(" <xsl:value-of select="MessageString" />",
}

public override int ErrorNumber
{
get {return <xsl:value-of select="ErrorNumber" />;}
}
}
}
</xsl:template><xsl:template match="Parms" mode="MethodArgs"
<xsl:apply-templates select="Parm" mode="MethodArgs"
/></xsl:template><xsl:template match="Parm"
mode="MethodArgs"><xsl:text>string </xsl:text><xsl:value-of select="."
/><xsl:if test="position()!=last()">, </xsl:if></xsl:template><xsl:template
match="Parms" mode="MessageArgs" ><xsl:apply-templates select="Parm"
mode="MessageArgs" /></xsl:template><xsl:template match="Parm"
 
Greetings Teemu

You are right, the stylesheet is invalid. I excepted the XslTransform load method to throw an exception

I was writing the error handling routines. I expected a XsltCompileException with the message property containing a description of the problem, with the Line Numbr and Line Position properties giving the location of the problem. Also, becasue the XsltCompileException class inherts from the XsltException class, the XsltCompileException class should contain a super set of the information in the XsltException class.

If you look at my debug output, you will see that the XsltCompileException message contains the text "(5,2) :" and then a new line. Thats all, not even a brief description of why the exception was thrown.

Next you will see, there is an inner exception of XsltException. This does contain a message about what the problem is, but not the Line Number or Line Position.

This is not the behavior I was expecting. So far, all the other framework classes I have worked with will throw a exception with at least a brief statment about why the error was thrown. This is the first one where I has to use but the outter exception and the inner exception to create a complete error handling routine.

So is this a bug or a feature? I have search the knowleage base and I can not found any refference to this behavior.

Cheers

John


----- Teemu Keiski wrote: ----

Well

You have <xsl:template match="./Exception"

in the stylesheet and I don't think it is valid. I don't understand wha
else you mean, but it should be just "Exception" and you should control th
flow of transformation by first matching to "/" (root) and from there usin
<xsl:apply:templates...> and so on to get it to the correct track with th
elements to be processed
 
Back
Top