Project

Profile

Help

Bug #5663

closed

SaxonCS - XSLT compile fails with FormatException (priority="0.5")

Added by Sieben De Vreese over 1 year ago. Updated about 1 year ago.

Status:
Closed
Priority:
High
Assignee:
Category:
Localization
Sprint/Milestone:
-
Start date:
2022-08-26
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
11, trunk
Fix Committed on Branch:
11, trunk
Fixed in Maintenance Release:
Platforms:
.NET

Description

We used both Saxon-HE and SaxonCS during our tests. Saxon-HE loads the xslt, SaxonCS does not.


Files

clipboard-202208261110-2lubh.png (113 KB) clipboard-202208261110-2lubh.png Sieben De Vreese, 2022-08-26 11:10
Actions #1

Updated by Sieben De Vreese over 1 year ago

Project , XSLT and invoice provided via email. ()

Actions #2

Updated by Michael Kay over 1 year ago

I haven't been able to reproduce this yet, but I think you could be seeing a problem with the document-uri() function (see bug #5615, etc). We had to make changes to the document-uri() function because the implementation wasn't conformant with the W3C specs - the requirement that the returned URI is unique and always acceptable to the doc() function meant that we had to be much more restrictive in deciding which documents should have a document-uri(). See what happens if you use base-uri() instead.

Or, check what value document-uri() is actually returning. If it's a zero-length string, this could well lead to problems when you try to use the URI later.

Actions #3

Updated by Sieben De Vreese over 1 year ago

At this moment we are using Uri, we even tried passing the file as a stream but we still get the same error.

Actions #4

Updated by Michael Kay over 1 year ago

The transformation works (apparently correctly) when run from the command line, and I've also run it successfully using the API, though I had to change the filenames to match my Mac filestore layout.

My next step would be to run it on a Windows machine; unfortunately I'm away from the office so I won't be able to do that until the middle of next week.

Are you sure the failure is coming from Saxon, and not simply from your call on "new Uri(...)" supplying a Windows filename? (Try making the same call on new Uri() in a separate statement, where Saxon is not involved).

Actions #5

Updated by Sieben De Vreese over 1 year ago

Can you check the xslt handling in .net6 with SaxonCS installed?

Actions #6

Updated by Michael Kay over 1 year ago

Could you report the results of my suggested diagnostics, please?

Actions #7

Updated by Martin Honnen over 1 year ago

I am not able to see the error the original poster got, nor the file used, but code like

var uri = new Uri("C:/Users/marti/OneDrive/Documents/EN16931-UBL-validation.xslt"); 
Console.WriteLine(uri.AbsoluteUri);

Processor processor = new();

var xslt30Transformer = processor.NewXsltCompiler().Compile(uri).Load30();

(with the file EN16931-UBL-validation.xslt downloaded from the public Github repository of that standard (https://github.com/ConnectingEurope/eInvoicing-EN16931)) runs fine for me on Windows 11 with SaxonCS 11.4.1 in a .NET 6 console application.

The uri.AbsoluteUri is output as file:///C:/Users/marti/OneDrive/Documents/EN16931-UBL-validation.xslt. Neither the Compile nor the Load call gives any error and I can run the XSLT Schematron validation fine with a sample taken also from that repository (e.g.

var input = processor.NewDocumentBuilder().Build(new Uri("https://github.com/ConnectingEurope/eInvoicing-EN16931/raw/master/ubl/examples/ubl-tc434-example1.xml"));

xslt30Transformer.GlobalContextItem = input;

xslt30Transformer.ApplyTemplates(input, processor.NewSerializer(Console.Out));

HTH. Otherwise just ignore me, as I said, the error the original poster encountered is not visible to me.

Actions #8

Updated by Sieben De Vreese over 1 year ago

I have tried the code Martin provided. This writes the Uri correctly to output, it does not seem like that is the issue. Is it possible I have issues because I'm using Windows 10?

Actions #9

Updated by Michael Kay over 1 year ago

  • Subject changed from SaxonCS XSLT load issue to SaxonCS - XSLT compile fails with FormatException (priority="0.5")
  • Applies to branch 11, trunk added
  • Fix Committed on Branch 11, trunk added

Had a Zoom session with the client on this one.

Compilation of a stylesheet fails with a FormatException.

Analysis of the diagnostics pinned it down to the fact that there's a template with priority="-0.5", and we are parsing this using Double.Parse() without specifying a Culture; if the default culture for the machine expects "," as a decimal separator this will fail.

Actions #10

Updated by Michael Kay over 1 year ago

The Java-to-C# transpiler is translating java.lang.Double.parseDouble(n) to System.Double.Parse(n), when it should be System.Double.Parse(n, CultureInfo.InvariantCulture) (note, we've already checked the format is correct, this call is only to do the conversion).

In fact it would probably make sense for the transpiler to generate a call on a helper method so that we can get the exception handling right. The code in StringToNumber does the right thing and should be copied.

Actions #11

Updated by Michael Kay over 1 year ago

Although the fix is straightforward, I'm having some trouble replicating the error, which means I haven't really tested it.

The test driver has an option which I can set to -locale:nl-BE and this doesn't trigger the failure, even though it is correctly setting the CurrentCulture: the call on Double.Parse("0.2") correctly parses the value (as 0.2000000000000...0001). But if I call Double.Parse with the culture explicitly set to "nl-BE", it parses "0.2" as "2" (presumably treating the "." as a thousands separator).

The problem is that the default behaviour of Double.Parse seems to depend on a great number of configuration settings, so it's probably going to be hard to reproduce the exact settings that trigger the failure. So I think I'll content myself with assuming that a specific setting of CultureInfo.InvariantCulture will do the job.

Actions #12

Updated by Michael Kay over 1 year ago

  • Category set to Localization
  • Status changed from New to Resolved
  • Platforms .NET added

Fixed by (a) changing the transpiler to map Double.parseDouble() to a new helper method in Utils.cs, and (b) making that helper method invoke System.Double.Parse() using the invariant culture.

Actions #13

Updated by Michael Kay over 1 year ago

  • Status changed from Resolved to In Progress

Reopened. It seems the patch is causing QT3 tests Literals041 et seq to fail in SaxonCS. These tests are supposed to reject an invalid numeric literal with an XPST0003; they actually cause a crash, presumably as a result of changes to the exception handling.

Actions #14

Updated by Michael Kay over 1 year ago

  • Status changed from In Progress to Resolved

Fixed this by removing the annotation that causes special-case handling of the NumberFormatException in NumericValue.parseNumber()

Actions #15

Updated by Community Admin over 1 year ago

  • % Done changed from 0 to 100
  • Fixed in Maintenance Release 12.0 added

Bug issue fix applied in the Saxon 12.0 Major Release. Leaving this bug marked as Resolved until fix applied

Actions #16

Updated by O'Neil Delpratt about 1 year ago

  • Fixed in Maintenance Release 11.5 added

Bug applied in the Saxon 11.5 Maintenance release.

Actions #17

Updated by O'Neil Delpratt about 1 year ago

  • Status changed from Resolved to Closed

Please register to edit this issue

Also available in: Atom PDF