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 4031 - Final Result Trees
Summary: Final Result Trees
Status: CLOSED FIXED
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: XSLT 2.0 (show other bugs)
Version: Proposed Recommendation
Hardware: PC Windows XP
: P2 major
Target Milestone: ---
Assignee: Michael Kay
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL: http://www.w3.org/TR/2006/PR-xslt20-2...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-12-03 13:19 UTC by Mukul Gandhi
Modified: 2007-01-16 17:49 UTC (History)
0 users

See Also:


Attachments

Description Mukul Gandhi 2006-12-03 13:19:50 UTC
This comment applies to the document "XSLT 2.0, Proposed Recommendation 21 November 2006", located at http://www.w3.org/TR/2006/PR-xslt20-20061121/.

Section "19 Final Result Trees" specifies -

"A final result tree can be created explicitly, by evaluating an xsl:result-document instruction. A final result tree is also created implicitly if no xsl:result-document instruction is evaluated, or if the result of evaluating the initial template is a non-empty sequence."

I think there is an error in the 2nd sentence. The correct paragraph should be - 

"A final result tree can be created explicitly, by evaluating an xsl:result-document instruction. A final result tree is also created implicitly if no xsl:result-document instruction is evaluated, and the result of evaluating the initial template is a non-empty sequence."

Please note the use of word "and" instead of "or".

Regards,
Mukul
Comment 1 Mukul Gandhi 2006-12-03 13:30:53 UTC
(In reply to comment #0)

The section "19 Final Result Trees" says, "The output of a transformation is a set of zero or more final result trees.". 

But it is not described, under what circumstances, *zero* final result trees are created.

I'll appreciate if this point can be clarified a bit more.

Regards,
Mukul
Comment 2 Michael Kay 2006-12-03 14:02:10 UTC
No, I think the text is correct. In fact it's very carefully written, even though this is just an introductory summary (the WG spent a lot of time on this during last call!). As explained more fully in section 2.4, you get an implicit final result tree in two situations:

(a) if there's no xsl:result-document instruction executed, regardless whether the result of the initial template is empty

(b) if there is an xsl:result-document instruction executed and the result of the initial template is non-empty.

The only time you don't get one, by implication, is when result-document is executed AND the result of the initial template is empty. This is to cover the use case

<xsl:template match="/">
  <xsl:result-document validate="strict">
    <xsl:apply-templates/>
  </xsl:result-document>
</xsl:template>

(Note: I think recent Saxon releases get this right, but that's a question for a different forum. There's an unstated assumption in the spec, unstated because it's out of scope, that if there is no implicit result tree, then the contents of any output file specified as the destination for the implicit result tree will not be overwritten; and in this sense producing an empty result tree is different from not producing one.)
Comment 3 Michael Kay 2006-12-03 14:11:33 UTC
In comment #2 I didn't address your supplementary question made in comment #1:

>But it is not described, under what circumstances, *zero* final result trees are created.

I believe the Note in 2.4 is correct when it says "This means that there is always at least one result tree.". By implication the first sentence of section 19:

"The output of a transformation is a set of zero or more final result trees."

could be more precise. (I could say it's wrong, but pedantically it isn't, and the difference is important, because it means I can fix it editorially before going to Recommendation...)

Thanks for the comment.
Comment 4 Mukul Gandhi 2006-12-03 20:32:34 UTC
(In reply to comment #3)
I am happy with your explanation. You could close this bug report.

Regards,
Mukul
Comment 5 Michael Kay 2006-12-14 18:28:18 UTC
Thank you for this comment. The Working Group decided to make the following editorial changes to section 17:

1. Before the quoted sentence "A final result tree is also created implicitly
if no xsl:result-document instruction is evaluated, ...", add "As explained in [section 2.4], ...".

2. Change the sentence "The output of a transformation is a set of zero or more final result trees." to read "The output of a successful transformation is a set of one or more final result trees."

We assume this response meets your concerns.

Michael Kay
for the XSL Working Group
Comment 6 Mukul Gandhi 2006-12-15 18:38:54 UTC
Thanks that you would be making these changes in the spec. I have few further comments please. Please read my response below your comments.

(In reply to comment #5)
> Thank you for this comment. The Working Group decided to make the following
> editorial changes to section 17:
> 1. Before the quoted sentence "A final result tree is also created implicitly
> if no xsl:result-document instruction is evaluated, ...", add "As explained in
> [section 2.4], ...".

This looks good to me.
But I think, you mean Section 19, and not Section 17.

> 2. Change the sentence "The output of a transformation is a set of zero or more
> final result trees." to read "The output of a successful transformation is a
> set of one or more final result trees."

I think this is ok, if the result of transformation is a tree, which can be serialized as XML. Does the term final result tree is right, if output is plain text (e.g. when produced by stylesheet instruction <xsl:output method="text" /> (and not XML) ) ?

> We assume this response meets your concerns.
> Michael Kay
> for the XSL Working Group

Comment 7 Michael Kay 2006-12-15 18:58:46 UTC
>But I think, you mean Section 19, and not Section 17.

Yes, sorry for the typo.

>Does the term final result tree is right, if output is plain text

The result of the transformation is always a set of trees. Serialization, if it happens, is regarded as a separate process from the transformation proper.

Michael Kay 
Comment 8 Mukul Gandhi 2006-12-15 19:19:27 UTC
Thanks for your reply.

But I am still not convinced by this sentence in Section "19 Final Result Trees" (please read my comment #0):

"A final result tree can be created explicitly, by evaluating an
xsl:result-document instruction. A final result tree is also created implicitly
if no xsl:result-document instruction is evaluated, or if the result of
evaluating the initial template is a non-empty sequence."

I still have a feeling, it should have word "and" instead of "or" (please read my comment #0).

The 2nd sentence above says, "A final result tree is also created implicitly
if no xsl:result-document instruction is evaluated, or if the result of
evaluating the initial template is a non-empty sequence." 

The word "or" means, either 1st part of sentence is true, or the 2nd. If "or" holds correct, then I find 1st part of "or" to be wrong. How could a final result tree be created implicitly if no xsl:result-document instruction is evaluated ? 

(In reply to comment #7)
> >But I think, you mean Section 19, and not Section 17.
> Yes, sorry for the typo.
> >Does the term final result tree is right, if output is plain text
> The result of the transformation is always a set of trees. Serialization, if it
> happens, is regarded as a separate process from the transformation proper.
> Michael Kay 

Regards,
Mukul

Comment 9 Michael Kay 2006-12-15 19:53:21 UTC
>But I am still not convinced by this sentence in Section "19 Final Result Trees" (please read my comment #0):

>"A final result tree can be created explicitly, by evaluating an xsl:result-document instruction. A final result tree is also created implicitly if no xsl:result-document instruction is evaluated, or if the result of evaluating the initial template is a non-empty sequence."

Consider the following cases:

(a)
<xsl:template match="/"/>

(b)
<xsl:template match="/">
  <xsl:result-document><a/></xsl:result-document>
</xsl:template>

(c)
<xsl:template match="/">
  <a/>
</xsl:template>

(d)
<xsl:template match="/">
  <a/>
  <xsl:result-document href="2.xml"><a/></xsl:result-document>
</xsl:template>

An implicit result tree is created in cases (a), (c), and (d), but not in case (b). In case (a) it is created because no xsl:result-document instruction has been executed. In cases (c) and (d) it is created because the result of the initial template is non-empty. It is only necessary for one of these conditions to be true. If we said "and", then it would be necessary for both conditions to be true, which means we would not create an implicit result tree in case (a). But we made a deliberate and conscious decision that we should create an implicit result tree (containing a document node with no children) in case (a), partly for backwards compatibility and partly because it seems the right thing to do.
Comment 10 Mukul Gandhi 2006-12-16 05:28:52 UTC
Thanks a lot for clarification. As per your clarifications below, I think, the paragraph I cited below from Section 19 could be written as:

"A final result tree can be created explicitly, by evaluating an xsl:result-document instruction. A final result tree is also created implicitly if no xsl:result-document instruction is evaluated."

(I have dropped the part - "or if the result of evaluating the initial template is a non-empty sequence")

This I think will be more clear to readers.

I would also like to see your comments (Comment #5) appear as editorial changes. 

Regards,
Mukul

(In reply to comment #9)
> >But I am still not convinced by this sentence in Section "19 Final Result Trees" (please read my comment #0):
> >"A final result tree can be created explicitly, by evaluating an xsl:result-document instruction. A final result tree is also created implicitly if no xsl:result-document instruction is evaluated, or if the result of evaluating the initial template is a non-empty sequence."
> Consider the following cases:
> (a)
> <xsl:template match="/"/>
> (b)
> <xsl:template match="/">
>   <xsl:result-document><a/></xsl:result-document>
> </xsl:template>
> (c)
> <xsl:template match="/">
>   <a/>
> </xsl:template>
> (d)
> <xsl:template match="/">
>   <a/>
>   <xsl:result-document href="2.xml"><a/></xsl:result-document>
> </xsl:template>
> An implicit result tree is created in cases (a), (c), and (d), but not in case
> (b). In case (a) it is created because no xsl:result-document instruction has
> been executed. In cases (c) and (d) it is created because the result of the
> initial template is non-empty. It is only necessary for one of these conditions
> to be true. If we said "and", then it would be necessary for both conditions to
> be true, which means we would not create an implicit result tree in case (a).
> But we made a deliberate and conscious decision that we should create an
> implicit result tree (containing a document node with no children) in case (a),
> partly for backwards compatibility and partly because it seems the right thing
> to do.

Comment 11 Michael Kay 2006-12-16 19:05:25 UTC
I'm sorry, but your proposed change is incorrect. It's not sufficient to say that "A final result tree is also created implicitly if no xsl:result-document instruction is evaluated.", because that doesn't cover the implicit result tree that is created (in addition to the explicit result tree) in case (d).
Comment 12 Mukul Gandhi 2006-12-17 11:55:59 UTC
Thanks for letting me know the right concepts. It's also been a learning experiance for me during these discussions. I am convinced by your remarks. 

Please update the text of spec, as you think it's right.

Regards,
Mukul

(In reply to comment #11)
> I'm sorry, but your proposed change is incorrect. It's not sufficient to say
> that "A final result tree is also created implicitly if no xsl:result-document
> instruction is evaluated.", because that doesn't cover the implicit result tree
> that is created (in addition to the explicit result tree) in case (d).