Project

Profile

Help

Bug #3960

Transformation API: supplying lexical XML input and setting the global context item

Added by Michael Kay over 3 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Normal
Category:
s9api API
Sprint/Milestone:
-
Start date:
2018-10-10
Due date:
% Done:

100%

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

Description

XSLT 3.0 has separated the concept of the "initial match selection" and the "global context item"; they no longer need to be the same thing.

Nevertheless, many stylesheets follow the traditional pattern of a single principal source document that is available both as the initial match selection (for <xsl:template match="/">) and as the global context item (for reference within global variables).

The problem is that in some APIs (notably, the fn:transform interface and the s9api Xslt30Transformer) these have to be supplied separately. The global context item can only be supplied as a node, which means the tree has to be built under application control, and building the tree under application control makes it hard to ensure that stylesheet-defined whitespace stripping is applied during parsing. We handle this OK for the Transform command line, but it's messy: the call

builder.setWhitespaceStrippingPolicy(sheet.getWhitespaceStrippingPolicy());

isn't exactly intuitive to users. If you're calling fn:transform() from XSLT or XQuery then this mechanism isn't available anyway.

I'm currently looking at the XSLT test driver written in XSLT (in xsl30-tests/runner) which invokes the transformation using fn:transform(). In cases where validation is requested, it passes the source document to fn:transform using our Saxon-specific source-location property. This invokes the transformation via Xslt30Transformer.applyTemplates(source, destination), which does not set the global context item. But some of the tests, such as as-1701, are expecting the global context item to be set. At present you can't set the global context item unless you take charge of document building, and doing the document building externally in a way that respects the stylesheet's whitespace policy isn't possible in the fn:transform interface.

History

#1 Updated by Michael Kay over 3 years ago

  • Subject changed from Transformation API: supplying unparsed input and setting the global context item to Transformation API: supplying lexical XML input and setting the global context item

#2 Updated by Michael Kay over 3 years ago

  • Description updated (diff)

#3 Updated by Michael Kay over 3 years ago

At the level of the Xslt30Transformer, I'm inclined to add a new method transform(Source, Destination) which behaves like applyTemplates(Source, Destination) except that the tree built from the supplied Source also becomes the global context item. (This means that the new method is not suitable for use when streaming).

At the level of fn:transform(), I'm inclined to define our Saxon-specific source-location property so that it sets the global context item (like source-node does) except in the case where the initial mode is streamable.

#4 Updated by Michael Kay over 3 years ago

  • Category changed from JAXP Java API to s9api API
  • Status changed from New to In Progress
  • Priority changed from Low to Normal
  • Applies to branch 9.9 added
  • Fix Committed on Branch 9.9 added

I have committed changes to add a transform() method to Xslt30Transformer, and to use it to set the global context item when fn:transform() is called supplying schema-location.

Leaving open as more tests and documentation are needed.

#5 Updated by Michael Kay over 3 years ago

  • Assignee changed from Michael Kay to O'Neil Delpratt

Now fixed and tested in the Java API, handing over to OND because we need to do something similar for .NET

#6 Updated by O'Neil Delpratt almost 3 years ago

  • Status changed from In Progress to Resolved

The following methods added to the .NET:

Transform(Stream input, XmlDestination destination);

Transform(Stream input, Uri baseUri, XmlDestination destination);

Available in the next maintenance release for Saxon 9.9.

#7 Updated by O'Neil Delpratt over 2 years ago

  • Status changed from Resolved to Closed
  • % Done changed from 0 to 100
  • Fixed in Maintenance Release 9.9.1.3 added

Bug fix applied to the Saxon 9.9.1.3 maintenance release

Please register to edit this issue

Also available in: Atom PDF