xsl-list
[Top] [All Lists]

Re: [xsl] output file for xsl:message

2015-08-20 04:48:51
By default Saxon writes xsl:message output to the java System.err destination 
(the stderr output stream on most operating systems). The simplest way of 
redirecting it to a file is using shell redirection, typically 2>error.txt to 
overwrite error.txt, or 2>>error.txt to append to error.txt. But it depends on 
the shell you are using and this doesn’t always work for me. This also has the 
problem that xsl:message output will be mixed with other output sent to 
System.err, e.g. the output of -t messages.

If you want something more sophisticated, you can implement the MessageListener 
interface in the s9api XsltTransformer class. This allows you full control over 
both the formatting of messages and their destination. You need to be aware if 
you are using Saxon-EE that the message listener needs to be thread-safe, 
because a transformation can execute in multiple threads. But the content of 
each call of xsl:message will be passed in a single call to the 
MessageListener, as an XML node.

If you’re using the JAXP API, and you only want to change the destination of 
the message output, not its formatting, then you can do:

final Writer messageOut = new FileWriter(. . .);
Transformer transformer = templates.newTransformer();
((net.sf.saxon.jaxp.TransformerImpl)transformer).getUnderlyingController().setMessageEmitter(
    new MessageEmitter() {
        @Override
        public void open() throws XPathException {
            setWriter(messageOut);
            super.open();
        }
    }
);
At this level things can get messy if multiple threads are writing messages 
simultaneously.

Michael Kay
Saxonica


On 20 Aug 2015, at 10:15, VISH RAJPUT 
svishnu(_dot_)singh4(_at_)gmail(_dot_)com 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

Hi,

I am using xslt2.0 with saxon9 and want to store the <xsl:message> output in 
a result document. There are multiple <xsl:message> in different 
<xsl:templates> and I want to store the output of all <xsl:message> in a 
single result txt file.

-- 
Vishnu Singh | http://marklogicgd.blogspot.in/ 
<http://marklogicgd.blogspot.in/>
XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <-list/293509> (by email <>)
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>