How to retrieve a non-terminating xsl:message in M

2019-06-07 04:47发布

问题:

I am using the MSXML 6.0 parser for XSL transformation and want to fetch <xsl:message terminate="no"> debug messages. From what I found on the net this seems to be possible in .NET.

Is there a way to get the message output when using the COM interface (C++ or Delphi example code would be great)?

Update:

This is the code I use to do the XSL transformation (pretty straight forward):

uses ActiveX, {...} MSXML2_TLB;

function TransformMsXmlDocument( XmlDoc, XslDoc: iXmlDomDocument2 ) : UnicodeString;
var
   XslDoc2 : iXmlDomDocument;
   XslTemplate : iXslTemplate;
   XslProcessor : iXslProcessor;
begin
   XslDoc2 := CoFreeThreadedDomDocument60.Create();
   XslDoc2.Async := FALSE;
   XslDoc2.Load(XslDoc);

   XslTemplate := CoXslTemplate60.Create();
   XslTemplate.Stylesheet := XslDoc2;
   XslProcessor := XslTemplate.CreateProcessor();
   XslProcessor.Input := XmlDoc;

   XslProcessor.Transform();
   result := XslProcessor.Output;
end;

回答1:

I doubt you can do this with MS XML 6.0.

Like you, I generated the MSXML2_Tlb.Pas import file and tested with code v. similar to yours. The first problem is that the OnReadyStateChange and OnDataAvailable events of the Delphi wrapper components TDomDocument60 and TFreeThreadedDomDocument60 are never called.

So, then I wrote a OleVariant wrapper for an event sink which connects at run-time to the DomDocument60 via its ConnectionPointContainer interface to get an IConnectionPoint and calling .Advise() on that. I found that this event sink is called, four times, as the XML document loads, each time with a DispID of -609, which is the DispID of onreadystatechange (of XMLDOMDocumentEvents). But a) the Params (PDispParams ) passed to my wrapper's Invoke are empty, and b) its Invoke is not called for ondataavailable nor anything else, in particular ontransformnode (whose DispID I don't know).

So it seems to me firstly that the events of the objects in MSXML2_Tlb aren't working properly and secondly that there is no obvious way of catching the ontransformnode event of the XML document being transformed.

Fwiw, the VB example on the page you linked,

https://msdn.microsoft.com/en-us/library/system.xml.xsl.xsltmessageencounteredeventargs%28v=vs.110%29.aspx

seems to imply that there's a way of getting at XsltMessageEncounteredEventArgs from VB, but I'm not familiar enough with importing the Net libraries into a Delphi project to know what I would need to import to be able to access it. If someone could tell me that, I'd be happy to have a go.