Project

Profile

Help

Bug #2512

closed

Adaptive and JSON output methods from the XSLT command line

Added by Michael Kay over 8 years ago. Updated over 8 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Command Line
Sprint/Milestone:
-
Start date:
2015-12-01
Due date:
% Done:

100%

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

Description

XSLT 3.0 / XQuery 3.1 introduce two new serialization methods: "json" and "adaptive". It's currently not possible to use these when running XSLT from the command line.

In the past, the result of the initial template in XSLT was always converted to a document node. For example, given

<xsl:template match="/">
  <xsl:sequence select="1 to 5"/>
</xsl:template>

the result would be a document node containing a single text node whose string value was the string "1 2 3 4 5".

This makes it impossible to do

<xsl:template match="/">
  <xsl:sequence select="map{'London':3, 'Paris':8}"/>
</xsl:template>

because a map cannot be converted to a string and added to a document in this way. To remedy this, XSLT 3.0 adds the attribute

<xsl:output build-tree="no"/>

which suppresses the construction of the document. The spec also says that if the output method is "json" or "adaptive", then this should be the default.

Saxon 9.7 does not yet implement the build-tree attribute on xsl:output. It does allow the building of the tree to be suppressed when using the s9api interface, for example

XdmValue result = transformer.applyTemplates(input)

returns the "raw" result of the initial template, which may be (for example) a sequence of integers or a map. But there is no way of invoking this functionality from the command line.

Actions #1

Updated by Michael Kay over 8 years ago

  • Status changed from New to In Progress

I have made good progress on this but the changes are fairly extensive and will need careful testing.

I have changed the Transform class (implementing the command line interface) to use the Xslt30Transformer in s9api rather than the old XsltTransformer. The old class won't handle serialization options other than those that wrap the result in a document tree, which means it won't handle the JSON and Adaptive output methods.

The relationship between the transformer and the serializer has always been complex and I decided to change the way this is handled a little. I've extended Xslt30Transformer with a bunch of newSerializer() methods that allow you to create a serializer preconfigured with the serialization properties defined in the stylesheet (in the unnamed xsl:output declarations); you can then modify this serializer by setting additional properties, and then pass the serializer to the transformer.applyTemplates() or transformer.callTemplate() methods.

Actions #2

Updated by Michael Kay over 8 years ago

I have done an initial commit of these changes on the 9.7 branch, but am leaving the bug open while I conduct more extensive testing. I suspect similar changes may also be needed for the Query command.

Actions #3

Updated by Michael Kay over 8 years ago

This patch caused a failure of QT3 test transform-err-010. The test is attempting to set the output base URI to some kind of null value, in order to trigger an error condition, and the attempt is unsuccessful - Saxon defaults the value to the working directory.

In response to this I have changed the mechanism fn:transform uses to represent an absent base URI (it now uses a URI with the scheme "dummy"), and in order to make the same code work across all delivery formats I have done some refactoring so that all code that's specific to a delivery format is now moved into a subclass of the new inner class Deliverer, which itself extends OutputURIResolver.

Actions #4

Updated by Michael Kay over 8 years ago

  • Status changed from In Progress to Resolved

JSON and adaptive serialization methods appear to work OK with XQuery from the command line. (Perhaps "adaptive" should become the default, but I'd prefer to see it get more exposure first - and the spec is still not 100% stable).

So, marking as resolved.

Actions #5

Updated by Martin Honnen over 8 years ago

Michael Kay wrote:

JSON and adaptive serialization methods appear to work OK with XQuery from the command line.

Is that working for you on the 9.7 release or in your development build? I don't get any map or array output with method=adaptive with 9.7.0.1 and XQuery from the command line, it seems the output is swallowed and remains empty, samples are like mentioned in https://saxonica.plan.io/boards/3/topics/6240?r=6243#message-6243.

Actions #6

Updated by O'Neil Delpratt over 8 years ago

  • Applies to branch 9.7 added
  • Fix Committed on Branch 9.7 added
Actions #7

Updated by O'Neil Delpratt over 8 years ago

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

Bug fix applied in the Saxon 9.7.0.2 maintenance release

Actions #8

Updated by O'Neil Delpratt over 8 years ago

  • Status changed from Resolved to Closed

Please register to edit this issue

Also available in: Atom PDF