Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xslt:message in Saxon - where is the message?

I use Saxon XSLT version 9.6.0.1. A stylesheet contains this code:

...
<xsl:message terminate="yes">errormessage</xsl:message>
...

My application terminates as expected with this exception:

net.sf.saxon.expr.instruct.TerminationException: Processing terminated by xsl:message at line 45 in 
    at net.sf.saxon.expr.instruct.Message.processLeavingTail(Message.java:253)  at net.sf.saxon.expr.instruct.Message.processLeavingTail(Message.java:253)
    at net.sf.saxon.expr.instruct.Choose.processLeavingTail(Choose.java:822)

Now I am wondering where the "errormessage" text actually goes. I can see it on stderr but need to display it to the user or put it into the logfile.

How can I programmatically access the message text?

like image 809
Hiran Chaudhuri Avatar asked Dec 17 '14 10:12

Hiran Chaudhuri


People also ask

What does XSLT stand for?

Extensible Stylesheet Language Transformations (XSLT) is an XML-based language used, in conjunction with specialized processing software, for the transformation of XML documents.

How does it work XSLT?

XSLT Processor takes the XSLT stylesheet and applies the transformation rules on the target XML document and then it generates a formatted document in the form of XML, HTML, or text format. This formatted document is then utilized by XSLT formatter to generate the actual output which is to be displayed to the end-user.

What is an XSLT document?

XSLT (Extensible Stylesheet Language Transformations) is a language originally designed for transforming XML documents into other XML documents, or other formats such as HTML for web pages, plain text or XSL Formatting Objects, which may subsequently be converted to other formats, such as PDF, PostScript and PNG.

What is XSLT mapping?

Use. Interface descriptions are in the form of XML documents. XSL Transformation (XSLT) is a member of the XML family of languages. It describes how one XML structure is transformed into another XML structure.


1 Answers

If you use the Saxon s9api then see the sample file S9APIExamples in the saxon resources (available at http://saxonica.com/download/download_page.xml), it has an example setting a MessageListener:

        Processor proc = new Processor(false);
        XsltCompiler comp = proc.newXsltCompiler();
        String stylesheet =
                "<xsl:transform version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>\n" +
                        "  <xsl:template name='main'>\n" +
                        "    <xsl:message><msg>Reading http://www.w3.org/TR/xslt20/ ...</msg></xsl:message>/>\n" +
                        "    <exists>\n" +
                        "      <xsl:value-of select=\"doc-available('http://www.w3.org/TR/xslt20/')\"/>\n" +
                        "    </exists>\n" +
                        "    <xsl:message><msg>finishing</msg></xsl:message>\n" +
                        "  </xsl:template>\n" +
                        "</xsl:transform>";
        StringReader reader = new StringReader(stylesheet);
        StreamSource styleSource = new StreamSource(reader, "http://localhost/string");
        XsltExecutable templates = comp.compile(styleSource);
        XsltTransformer transformer = templates.load();
        transformer.setInitialTemplate(new QName("main"));
        transformer.setMessageListener(
                new MessageListener() {
                    public void message(XdmNode content, boolean terminate, SourceLocator locator) {
                        System.err.println("MESSAGE terminate=" + (terminate ? "yes" : "no") + " at " + new Date());
                        System.err.println("From instruction at line " + locator.getLineNumber() +
                                " of " + locator.getSystemId());
                        System.err.println(">>" + content.getStringValue());
                    }
                }
        );
        Serializer out = proc.newSerializer(System.out);
        transformer.setDestination(out);
        transformer.transform();
like image 107
Martin Honnen Avatar answered Sep 19 '22 18:09

Martin Honnen