Project

Profile

Help

Bug #3906

closed

Sample of XSL streaming work in Saxon EE does not work at all

Added by Ig Savin about 6 years ago. Updated almost 6 years ago.

Status:
Closed
Priority:
Normal
Category:
Build and release
Sprint/Milestone:
-
Start date:
2018-09-17
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
9.8, 9.9
Fix Committed on Branch:
9.9
Fixed in Maintenance Release:
Platforms:

Description

Hi,

I am using an evaluation version of your product (Saxon EE) and faced with the following issue. When I run the sample devoted for XSLT streaming, I get the following error during run-time:

        String s = "<xsl:transform version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:saxon='http://saxon.sf.net/'>\n" +
            " <xsl:template name='main'> " +
            " <xsl:value-of select=\"count(saxon:stream(doc('" + new Uri(samplesDir, "data/othello.xml").ToString() + "')//LINE[count(tokenize(.,'/s')) &gt; 0] ))\" />" +
            " </xsl:template></xsl:transform>";


        // Create a transformer for the stylesheet.
        XsltTransformer transformer = processor.NewXsltCompiler().Compile(new StringReader(s)).Load();

===== XsltStreamDoc =======

Test failed unexpectedly (net.sf.saxon.trans.XPathException): Errors were reported during stylesheet compilation bei net.sf.saxon.style.Compilation.compileSingletonPackage(Configuration config, CompilerInfo compilerInfo, Source source) bei Saxon.Api.XsltCompiler.Compile(TextReader input) bei ConsoleApplication1.XsltStreamDoc.run(Uri samplesDir) in C:\prj\for Tests\Saxon\ConsoleApplication1\ConsoleApplication1\Program.cs:Zeile 2559. bei ConsoleApplication1.Program.Main(String[] argv) in C:\prj\for Tests\Saxon\ConsoleApplication1\ConsoleApplication1\Program.cs:Zeile 185.

What I am doing wrong with your product? The underlying "data/othello.xml" is from your official samples.

Actions #1

Updated by Michael Kay about 6 years ago

First of all, you haven't configured an ErrorListener on your XsltCompiler, which means the errors are going to System.err, which unless you're running from the console, is probably going into some black hole somewhere. The exception only tells you that there was a compilation failure, but the details of the errors are being written elsewhere. Either set an ErrorListener, or redirect System.err to some well-known location like a log file.

Actually, I've just noticed, you use NewXsltCompiler with a capital N, which means this must be on .NET, but the principle is the same. On .NET the XsltCompiler writes errors to a supplied ErrorList object.

I'm afraid the sample code is very ancient; it really shouldn't be necessary to use saxon:stream() when doing streaming any more. And when I run this stylesheet (from Java, I don't have a .NET machine with me today), the error I get is

Static error at char 23 in xsl:value-of/@select on line 2 column 164 XTSE3430: The body of the xsl:source-document instruction is not streamable

  • Predicate [fn:exists(...)] at line 2 is not motionless

Now that's not very helpful, because unfortunately there's been a fair bit of code rewriting before the streamability analysis is done. The saxon:stream() instruction gets turned into a call on xsl:source-document, and the expression count(XXX) > 0 gets turned into a call on fn:exists(XXX). But the essence of this is that the stylesheet doesn't satisfy the streamability rules, which basically means that this sample app somehow found it into the release without testing. (A likely explanation is that we changed the sample so it worked but the release process picked up the old version.)

Using xsl:source-document rather than saxon:stream() actually fixes the issue. Changing the stylesheet to this makes it work:

String xsl = "<xsl:transform version='3.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:saxon='http://saxon.sf.net/'>\n" +
                    " <xsl:template name='main'> " +
                    " <xsl:source-document href='/Users/mike/repo/samples/data/othello.xml'>"
                    + "<xsl:value-of select=\"count(//LINE[count(tokenize(.,'/s')) &gt; 0] )\" />"
                    + "</xsl:source-document>" +
                    " </xsl:template></xsl:transform>";
Actions #2

Updated by Michael Kay about 6 years ago

  • Category set to Build and release
  • Status changed from New to In Progress
  • Assignee set to O'Neil Delpratt
  • Applies to branch trunk added
  • Fix Committed on Branch 9.8, trunk added
Actions #3

Updated by Michael Kay about 6 years ago

One other observation, the tokenize() function is clearly intended to tokenize on whitespace, so the regular expression should be \s rather than /s. But in XPath 3.1 white-space tokenization can be achieved more easily with the one-arg version of the tokenize() function.

Actions #4

Updated by Michael Kay about 6 years ago

  • Assignee changed from O'Neil Delpratt to Debbie Lockett

Transferred to Debbie - please rewrite this .NET sample application to use a standard XSLT 3.0 streamable stylesheet rather than the proprietary saxon:stream() mechanism.

Actions #5

Updated by Debbie Lockett almost 6 years ago

In order to actually use streaming, the attribute streamable='yes' is also required on the xsl:source-document instruction. When this is added, Oxygen (using Saxon-EE 9.8.0.8) still shows the validation error "The body of the xsl:stream instruction is not streamable * Predicate [fn:exists(...)] at line 11 is not motionless". I believe the required solution is to use copy-of(//LINE) rather than //LINE (see http://www.saxonica.com/documentation/index.html#!sourcedocs/streaming/xslt-streaming). So the new code becomes:

String s = "<xsl:transform version='3.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>\n" +
				" <xsl:template name='main'>\n" +
				"  <xsl:source-document streamable='yes' href='" + new Uri(samplesDir, "data/othello.xml").ToString() + "'>\n" +
				"   <xsl:value-of select=\"count(copy-of(//LINE)[count(tokenize(.)) &gt; 0] )\" />\n" +
				"  </xsl:source-document>\n";
				" </xsl:template>\n" +
				"</xsl:transform>";

Committed in the 9.9 samples. (To be tested!)

Actions #6

Updated by Debbie Lockett almost 6 years ago

Fix also committed in svn/Saxon.Net/ExamplesEE/ExamplesEE.cs (the actual source file!)

Actions #7

Updated by Debbie Lockett almost 6 years ago

  • Status changed from In Progress to Closed
  • % Done changed from 0 to 100
  • Applies to branch 9.9 added
  • Applies to branch deleted (trunk)
  • Fix Committed on Branch 9.9 added
  • Fix Committed on Branch deleted (9.8, trunk)
  • Fixed in Maintenance Release 9.9.1.1 added

The 9.9 saxon-resources download has been updated with the 9.9.1.1 release. This includes the updated .NET samples.

Please register to edit this issue

Also available in: Atom PDF