0

I am using ant's xslt-task plus a suitable XSLT script to remove certain nodes from XML documents that we are generating. To get some feedback during processing I added a few message-statements to the script. These work all fine, except that ALL emitted messages have a ": Warning!" prefix. Since the messages are informative only I want/need to get rid of these Warning-prefix to prevent alerting the user who might otherwise think that something is not OK. How can I avoid that prefix? The XSLT message function seems to have no other option than 'terminate="yes"|"no". Can one somehow control that message prefix? And if so: how?

I am using the default xslt task built into ant, i.e. my target reads:

    <xslt in="${source.xml}" out="${output.xml}" style="${stylesheet.xsl}" processor="trax">
</xslt>

with the misc. properties set to point to the appropriate locations. I found that command in some other stack-overflow append.

My ant version reads:

C:\Users\mmo>ant -version
Apache Ant(TM) version 1.8.2 compiled on December 20 2010
mmo
  • 3,897
  • 11
  • 42
  • 63
  • Haven't seen that for `xsl:message` text coming from the ant `xslt` task using Saxon's XSLT processor. Please add a [mcve] that shows the problem, and state what XSLT processor, version of ant, etc that you're using. Thanks. – kjhughes Nov 29 '16 at 16:31
  • I added the ant snippet and ant version I am using. – mmo Dec 27 '16 at 23:11

1 Answers1

1

I think you're probably using the default Xalan processor, and I'm afraid I can't advise you whether/how its xsl:message processing can be customized.

If you were to switch to using Saxon you would not only get the benefit of doubled productivity by use of XSLT 2.0 instead of 1.0, but you would also get (a) an interface for customising xsl:message output, and (b) membership of an active user community that can answer questions like this.

(Actually, now I think about it, I seem to recall that with Xalan, xsl:message output is sent to the warning() method of the registered ErrorListener, so if you don't want to switch you could try and write an ErrorListener.)

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • Thanks. Your comment that Xalan by default sends out to the warning method seems correct. I don't quite see how I could write and add/register(?) a different error listener with the default xslt task. Any pointers? – mmo Dec 27 '16 at 23:04
  • What would I need to do to switch to using Saxon as you suggest? Use a different ant version? Or install some additional .jar? Where to? – mmo Dec 27 '16 at 23:16
  • To make Ant invoke Saxon, see http://stackoverflow.com/questions/919692/how-to-execute-xslt-2-0-with-ant Another useful technique is to write your own TransformerFactory (in Java) that invokes Xalan (or Saxon) after performing any desired configuration, e.g. a customised ErrorListener; you can then invoke your TransformerFactory from Ant in the same way. – Michael Kay Dec 28 '16 at 16:56