xsl-list
[Top] [All Lists]

RE: appending to result-document

2005-08-03 04:17:06
net.sf.saxon.event.Emitter is the Saxon 8.x class
com.icl.saxon.output.Emitter is the corresponding Saxon 6.x class

Of course there have been many changes in the meantime.

The only thing wrong with your code is that you have to modify the writer
for the message emitter *before* doing the transformation: if you do this
after calling transform(), it's too late.

Michael Kay
http://www.saxonica.com/ 


-----Original Message-----
From: Rahil [mailto:qamar_rahil(_at_)yahoo(_dot_)co(_dot_)uk] 
Sent: 03 August 2005 11:20
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] appending to result-document

Hi Michael

When trying to debug my program I realised that the package that was 
imported to recognise the Emitter class was 
'net.sf.saxon.event.Emitter'. However when looking up more 
information 
on the net I noticed that there was a post from you in which you'd 
mentioned the package 'com.icl.saxon.output.Emitter'. Are they 
essentially the same classes as I cant find a  corresponding 
jar file to 
include in my claspath ?

My Java code with the Emitter class looks as such so far :
----
import net.sf.saxon.Controller;
import net.sf.saxon.event.Emitter;

TransformerFactory transMapFact = TransformerFactory.newInstance(  );
Transformer transMap = transMapFact.newTransformer(mapXsltSource);
transMap.transform(mapXmlSource, mapResult);

        try{
        Controller control = (Controller)transMap;
        Emitter msg = control.getMessageEmitter();
        System.out.println("msg = " + msg);
        if(msg!=null)
            msg.setWriter(new 
FileWriter("D:\\Coding\\Log\\sample.xml"));
        }catch(IOException e){
            e.printStackTrace();
        }
----

My XSL file has a simple <xsl:message> embedded in an 
<xsl:template> block
---
<xsl:message><xsl:value-of select="$clsNm"/></xsl:message>
---

Am I using the wrong Emitter class due to which I am not getting any 
results?

Thanks
Rahil


Rahil wrote:

Thanks a lot Michael for the very helpful response.

Ive already taken the first shot at using the Controller 
class. At the 
moment my MessageEmitter class is getting no messages and returns a 
'null'. Ive declared an <xsl:message> in the .xsl file however.

But Ill try a few more approaches and do some debugging as well. Im 
sure it'll work and will resolve my query.

Much appreciate all your help.

Thanks again
Rahil

Michael Kay wrote:

I have used xsl:message several times to debug my files or test 
intermediary output. But I wasnt aware that I could 
actually store 
these messages in some file. Could you either tell me how 
to do it 
or point me to some web page where I can read some more ?
  


The simplest answer is to redirect standard error output from the 
command
line, using

  2>messages.xml

However, this will divert all error output, including real error 
messages,
warnings, etc. A better solution is to redirect the message output
selectively. You can do this from Java but not from the 
command line.

You probably have to dive into the Saxon Javadoc for documentation.

If you use JAXP with Saxon, you can cast the Transformer 
object to a
net.sf.saxon.Controller.

http://www.saxonica.com/documentation/javadoc/net/sf/saxon/Con
troller.html 

The Controller has a method setMessageEmitter() which you 
can use to 
capture
all xsl:message output if you want to go that far. More 
simply, you 
can call
getMessageEmitter() which will return a 
net.sf.saxon.event.MessageEmitter


http://www.saxonica.com/documentation/javadoc/net/sf/saxon/eve
nt/MessageEmit 

ter.html

which has a setWriter() method that you can use to set the output
destination to a Writer of your own choosing (or perhaps 
more simply, a
setStreamResult() method.)

(Note, recent versions of JAXP specify that message output 
should be 
sent to
the ErrorListener, which I believe is the Xalan convention. Saxon 
doesn't
follow this convention. In general, the content of an 
xsl:message is XML
rather than merely text, and the ErrorListener is only 
able to handle 
text.
The MessageEmitter receives the message as XML, in event form.)

Michael Kay
http://www.saxonica.com/




--~------------------------------------------------------------------
XSL-List info and archive:  
http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



 




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>