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 28154 - [xslt 3.0] streamable templates: climbing body
Summary: [xslt 3.0] streamable templates: climbing body
Status: CLOSED FIXED
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: XSLT 3.0 (show other bugs)
Version: Last Call drafts
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
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-06 13:08 UTC by Michael Kay
Modified: 2015-04-23 22:40 UTC (History)
1 user (show)

See Also:


Attachments

Description Michael Kay 2015-03-06 13:08:30 UTC
I can't see anything in the rules in 6.6.4 (Streamable templates) that disallows the following:

<xsl:template match="*" mode="a-streamable-mode" as="xs:string">
  <xsl:sequence select="ancestor::section"/>
</xsl:template>

Clearly this isn't streamable: we can't atomize a node reached via the ancestor axis. But the rules don't seem to say so.

We get the same issue with streamable stylesheet functions, so I propose to define:

The *type-adjusted posture* of a construct C with respect to a U-type T is as follows:

* If the intersection of T with U{N} is empty (that is, if T does not permit nodes), the posture of a call to the fn:data function with C as an operand. (Equivalently: it is the posture computed by the general streamability rules for a construct that has C as its only operand, with operand usage absorption).

* Otherwise, the posture of C.

In 6.6.4 Rule 3 then changes to:

3. The sweep of the sequence constructor in the body of the xsl:template element is either motionless or consuming

4. The type-adjusted posture of the sequence constructor forming the body of the xsl:template element, with respect to the U-type that corresponds to the declared return type of the template (defaulting to item()*), is grounded.


These rules solve the example case because data(..) is roaming, not grounded.
Comment 1 Michael Kay 2015-03-06 14:23:35 UTC
An alternative formulation is as follows: the posture and sweep of the template result are determined by applying the general streamability rules to a construct whose single operand is the sequence constructor forming the body of the template, with an operand usage that is the type-determined usage based on the declared return type, defaulting to item()*.

Then the posture of the template result, as defined above, must be grounded, and the sweep of the template result must be motionless or consuming.
Comment 2 Abel Braaksma 2015-03-12 16:02:55 UTC
<xsl:template match="*" mode="a-streamable-mode" as="xs:string">
  <xsl:sequence select="ancestor::section"/>
</xsl:template>

Note: we didn't allow templates to return nodes and atomization because of the as-attribute was not taken into account.

We allow this now:

<quote>
The xsl:template element has an as attribute that specifies an atomic or union type.
</quote>

I agree that this text does not explicitly take atomization into account, which essentially makes even fully roaming bodies streamable, because we allow it to be roaming if this clause is true. 

I think that the type-adjusted posture is a good way forward.
Comment 3 Michael Kay 2015-04-16 16:44:14 UTC
Noted that we have now introduced the concept of type-adjusted posture, we need to check whether we now use this in the streambility rules for templates.
Comment 4 Michael Kay 2015-04-17 09:29:15 UTC
We now have the concept of type-adjusted posture and sweep in the spec, although it doesn't use quite the wording proposed here. I believe we can now resolve this bug by changing rule 3 in 6.6.4 (and adding a rule 4), so the rules now read:

<rules>

A template rule that is applicable to a mode M is guaranteed-streamable if and only if all the following conditions are satisfied:

1. Mode M is declared in an xsl:mode declaration that specifies streamable="yes".

2. The pattern defined in the match attribute of the xsl:template element is a motionless pattern as defined in 19.8.10 Classifying Patterns.

<new>
3. The sweep of the sequence constructor in the body of the xsl:template element is either motionless or consuming

4. The type-adjusted posture of the sequence constructor forming the body of the xsl:template element, with respect to the U-type that corresponds to the declared return type of the template (defaulting to item()*), is grounded.

  Note: this means that either the sequence constructor is grounded as written (that is, it does not return streamed nodes), or that it effectively becomes grounded because the declared result type of the template forces atomization.
</new>

5. Every expression and contained sequence constructor in a contained xsl:param element (the construct that provides the default value of the parameter) is motionless.

</rules>

The reason the original example is non-streamable is that the type-adjusted posture in this case is roaming; this happens because the GSRs are invoked with an operand having posture=climbing, usage=absorption, and this combination gives a result posture of roaming.
Comment 5 Michael Kay 2015-04-17 09:39:08 UTC
I have applied this fix to the spec, but am leaving the bug open so that the fix can be reviewed and approved by the WG.
Comment 6 Michael Kay 2015-04-23 16:50:35 UTC
The WG accepted this change.