[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] output file for xsl:message


Subject: Re: [xsl] output file for xsl:message
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 20 Aug 2015 09:48:45 -0000

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 doesnbt 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 youbre 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().se
tMessageEmitter(
    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.singh4@xxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> 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 <>)


Current Thread
Keywords
xml