Re: [xsl] How to generate an XML log using xsl:message?

Subject: Re: [xsl] How to generate an XML log using xsl:message?
From: George Cristian Bina <george@xxxxxxx>
Date: Mon, 27 Dec 2004 12:58:21 +0200
Hi Stefan,

I think the solution depends on how you get the messages. For instance if you register a MessageEmitter for Saxon or an ErrorListener for Xalan to collect the messages then you can emit the root element when you serialize them. If you rely on the default message processing (that is on the fact that they are written to stderr then you can write the start tag before the transformation to stderr and after the transformation write the end tag.
If you are looking for a solution inside the stylesheet and all you want to do is to collect the stderr content then I cannot think (at least right now :) ) at a different solution than to use the disable-output-escaping attribute. Something like below:


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>


    <xsl:template match="/">
        <xsl:message>
            <xsl:text disable-output-escaping="yes">&lt;log></xsl:text>
        </xsl:message>

        <xsl:message>
            <test>sample</test>
        </xsl:message>

        <xsl:message>
            <xsl:text disable-output-escaping="yes">&lt;/log></xsl:text>
        </xsl:message>
    </xsl:template>
</xsl:stylesheet>

should give you:

<log>
<test>sample</test>
</log>

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com


Stefan Wachter wrote:
Hi all,

I would like to generate an XML log using xsl:message instructions. The problem is that I am not able to generate well formed XML. Each xsl:message instruction can generate an element in the output. Yet, I am not able to enclose the output of the various xsl:message instructions inside a document root element.

Does anyone have a solution for this problem? At the moment I can only think about concatenating the output with a starting "<root>" and ending "</root>".

Thanks for your attention,
Stefan Wachter

Current Thread