This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 30209 - [FO31] fn:transform() with an empty principal result document
Summary: [FO31] fn:transform() with an empty principal result document
Status: NEW
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: Functions and Operators 3.1 (show other bugs)
Version: Recommendation
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Michael Kay
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
Depends on:
Reported: 2017-11-30 15:08 UTC by Michael Kay
Modified: 2018-05-21 14:41 UTC (History)
1 user (show)

See Also:


Description Michael Kay 2017-11-30 15:08:07 UTC
Consider a transform like this:

<xsl:template match="/">
  <xsl:for-each select="1 to 5">
    <xsl:result-document href="out{.}.xml">

The transformation produces 5 secondary output documents, but we need to ask whether it produces a primary output document (if it does, then it's empty)

F+O says of fn:transform:

<quote from="F+O 3.1">
The result of the transformation is returned as a map. There is one entry in the map for the principal result document, and one for each secondary result document. The key is a URI in the form of an xs:string value. The key for the principal result document is the base output URI if specified, or the string "output" otherwise.

But we have tests (for example fn-transform-33) that assume there will be no entry in the map for the principal result document if it is empty. This is justified by the XSLT 2.0 specification, which states: 

<quote from="XSLT 2.0 §2.4">
An implicit result tree is also created when the result sequence is empty, provided that no xsl:result-document instruction has been evaluated during the course of the transformation. In this situation the implicit result tree will consist of a document node with no children.


This means that there is always at least one result tree. It also means that if the content of the initial template is a single xsl:result-document instruction, as in the example above, then only one result tree is produced, not two. It is useful to make the result document explicit as this is the only way of invoking document-level validation.

It's hard to interpret what the F+O statement "There is one entry in the map for the principal result document" means in the case where there is no principal result document.

And XSLT 3.0 changes the rules:

<quote from="XSLT 3.0 §">
In previous versions of this specification it was stated that when the raw result of the initial template or function is an empty sequence, a result tree should be produced if and only if the transformation generates no secondary results (that is, if it does not invoke xsl:result-document).... Processor APIs offering backwards compatibility with earlier versions of XSLT must respect this behavior, but there is no requirement for new processor APIs to do so.

Given these differences, I think it would be best if we tolerate diversity:

(a) the spec should say that it's implementation-defined whether the result map returned by fn:transform() contains an entry in respect of the principal result document in the case where the principal result is empty or absent.
(b) the relevant tests should be changed to allow the principal result to be either present or absent.

Affected tests are:

Comment 1 Andrew Coleman 2017-12-20 13:41:23 UTC
The XSL WG will lead the resolution of this bug
Comment 2 Michael Kay 2018-05-21 14:41:35 UTC
I am modifying the relevant test cases to allow the entry for the principal result document to be either present or absent.

The following tests are affected:

transform-13, 13a, 14, 33, 37, 38, 39, 40, 43, 44, 46, err-10, err-11, err-12