Project

Profile

Help

No output with XSLT 3 stylesheet and SaxonCS for stylesheet that does only create xsl:messages

Added by Martin Honnen over 2 years ago

On Slack Syd Bauman posted an XSLT stylesheet trying to work out some problems with document-uri(/) and Saxon 11 (Java). I tried the code with SaxonCS (11.3) on Windows and find that it outputs nothing but an empty line, the xsl:message output it should produce is somehow swallowed.

Code is

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

  <xsl:output method="text"/>
  
  <xsl:template match="/">
    <!-- Use concat() (instead of ||) so I can try this with XSLT 2.0, too. -->
    <xsl:message select="concat(
			 'My input is ',
			 document-uri(/),
			 '. At least that is what the ',
			 count( document-uri(/) ),
			 ' thing returned by document-uri() says.'
			 )"/>
    <xsl:message select="concat(
      'My input is ',
      base-uri(/),
      '. At least that is what the ',
      count( base-uri(/) ),
      ' thing returned by base-uri() says.'
      )"/>
  </xsl:template>

</xsl:stylesheet>

Run against itself with e.g. "C:\Program Files\Saxonica\SaxonCS-11.3\SaxonCS.exe" transform -xsl:sheet1.xsl -s:sheet1.xsl it does only output an empty line for me on Windows, both with a command line as well as with Powershell.


Replies (4)

Please register to reply

RE: No output with XSLT 3 stylesheet and SaxonCS for stylesheet that does only create xsl:messages - Added by Martin Honnen over 2 years ago

I change the stylesheet to also output a result element, SaxonCS does output it but the xsl:messages are still swallowed:

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

  <xsl:output method="text"/>
  
  <xsl:template match="/">
    <!-- Use concat() (instead of ||) so I can try this with XSLT 2.0, too. -->
    <xsl:message select="concat(
			 'My input is ',
			 document-uri(/),
			 '. At least that is what the ',
			 count( document-uri(/) ),
			 ' thing returned by document-uri() says.'
			 )"/>
    <xsl:message select="concat(
      'My input is ',
      base-uri(/),
      '. At least that is what the ',
      count( base-uri(/) ),
      ' thing returned by base-uri() says.'
      )"/>
      <root xsl:expand-text="yes">document-uri(/): {document-uri(/)}</root>
  </xsl:template>

</xsl:stylesheet>
"C:\Program Files\Saxonica\SaxonCS-11.3\SaxonCS.exe" transform -xsl:sheet2.xsl -s:sheet2.xsl
document-uri(/):

RE: No output with XSLT 3 stylesheet and SaxonCS for stylesheet that does only create xsl:messages - Added by Martin Honnen over 2 years ago

Now tried SaxonCS from the terminal window on a Mac but even there, where is has been developed, it seems to fail to output xsl:messages to the terminal window.

RE: No output with XSLT 3 stylesheet and SaxonCS for stylesheet that does only create xsl:messages - Added by Martin Honnen over 2 years ago

Also running SaxonCS from a .NET console application does not output any xsl:messages to the console window e.g.

using Saxon.Api;

var processor = new Processor();

var xsltCompiler = processor.NewXsltCompiler();
xsltCompiler.BaseUri = new Uri("urn:from-string");

var xsltExecutable = xsltCompiler.Compile(new StringReader(@"<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='3.0' expand-text='yes' xmlns:saxon='http://saxon.sf.net/' exclude-result-prefixes='#all'>
  <xsl:output indent='yes'/>
  <xsl:template match='/' name='xsl:initial-template'>
    <test>Run with {system-property('xsl:product-version')} at {saxon:timestamp()}</test>
    <xsl:message>Message test at {saxon:timestamp()}</xsl:message>
  </xsl:template>
</xsl:stylesheet>"));

var transformer = xsltExecutable.Load30();

transformer.CallTemplate(null, processor.NewSerializer(Console.Out));

only outputs e,g,

<?xml version="1.0" encoding="UTF-8"?>
<test>Run with EE 11.3 at 2022-05-31T08:53:17.769+02:00</test>

The documentation says about https://www.saxonica.com/html/documentation11/dotnetdoc/Saxon/Api/Xslt30Transformer.html#MessageListener: "If no message handler is supplied by the caller, message information will be written to the standard error stream." so I suppose the xsl:message should show in the console as Console.Err.

RE: No output with XSLT 3 stylesheet and SaxonCS for stylesheet that does only create xsl:messages - Added by Michael Kay over 2 years ago

Indeed, it seems that when running from the command line xsl:message output is lost.

(This shows the drawbacks of automated testing. Our test environment captures the xsl:message output and checks that it is correct. It's only missing when you send it somewhere to be seen by human eyeballs.)

Raised as a bug here:

https://saxonica.plan.io/issues/5553

    (1-4/4)

    Please register to reply