Project

Profile

Help

<xsl:message> and Saxon9api

Added by Anonymous almost 17 years ago

Legacy ID: #4731729 Legacy Poster: pvallone (pvallone)

Hi, Sorry for all the questions, but this API is really nice. When running a transformation from the .NET commandline, I use <xsl:message> to display messages that let the user know some info e.g. CREATING XML INDEX... PLEASE WAIT AND by default any errors are displayed. How do I do this with the API? I want to see any messages and errors. I tried the following Dim p As New Process() Dim processor As Processor = New Processor() ' This sets Saxon to use the standard (Java) CollectionURIResolver processor.Implementation.setCollectionURIResolver(New net.sf.saxon.functions.StandardCollectionURIResolver()) ' Load the source document Dim input As XdmNode = processor.NewDocumentBuilder().Build(New Uri("c:/temp/myxml.xml")) ' Create a transformer for the stylesheet. Dim transformer As XsltTransformer = processor.NewXsltCompiler().Compile(New Uri(txtXSLTfile.Text)).Load() ' Set the root node of the source document to be the initial context node transformer.InitialContextNode = input Dim results1 As XdmDestination = New XdmDestination() transformer.Run(results1) ' Error is from this line System.Console.Write(results1.XdmNode.ToString()) But received this error: "Unable to cast object of type 'Saxon.Api.XdmEmptySequence' to type 'Saxon.Api.XdmNode'."


Replies (2)

RE: &lt;xsl:message&gt; and Saxon9api - Added by Anonymous almost 17 years ago

Legacy ID: #4732031 Legacy Poster: Michael Kay (mhkay)

If a transformation fails at runtime, an exception will be thrown, and you can catch this exception. It's possible for a transformation to run successfully but to produce no principal output, and that seems to be the most likely explanation for the cast error you are seeing - the code that implements the XdmNode property in XdmDestination should be checking for that condition (and should probably return null as the property value) rather than failing with a cast error. There are mechanisms at the Java level to intercept the xsl:message output, but there's no packaged way of doing this in the .NET API. I think the right mechanism is probably along the lines of the ErrorList property in the XsltCompiler: a MessageList to which the messages are written, and if you want to output something immediately you can always subclass List and implement your own add() method. The messages are written as text to the standard error output, and I suspect there is something you can do in .NET to redirect that to a stream of your choosing - that's probably the best approach to use for the moment.

RE: &lt;xsl:message&gt; and Saxon9api - Added by Anonymous almost 17 years ago

Legacy ID: #4732253 Legacy Poster: pvallone (pvallone)

Hi, Thank you for the help. I was able to compile the Errors in an array as you suggested. This is based on some of the CS examples you have provide in the documentation. e.g. Catch ex As Exception Dim Errorprocessor As Processor = New Processor() Dim compiler As XsltCompiler = Errorprocessor.NewXsltCompiler() ' Create a list to hold the error information compiler.ErrorList = New ArrayList() compiler.ErrorList.Add(Err.Description) Dim Errorcount = compiler.ErrorList.Count Dim i = 0 Me.ListBox1.Items.Add("found " & Errorcount & " errors: ") For i = 0 To Errorcount Me.ListBox1.Items.Add("found: " & compiler.ErrorList(i).ToString) i = i + 1 Next End Try As for your suggestion about the Message list, this will work. However there is a compromise. <xsl:message> in my stylesheet will display messages each step of the way. As XSLT is a functional language rather than a procedural one I am not sure I have this luxury in vb.net. Nevertheless, the API is great. Thanks again for the help. pvallone

    (1-2/2)

    Please register to reply