w3c / qtspecs

XSLT and XQuery Specifications - the source used to build the specs, and the errata
Other
30 stars 25 forks source link

[xslt30] Streamable functions: streaming parameter used twice #15

Open michaelhkay opened 4 years ago

michaelhkay commented 4 years ago

Consider the function:

<xsl:function name="x" streamability="absorbing">
  <xsl:param name="p" as="element(*)*">
  <xsl:for-each select="$p">
    <xsl:variable name="i" select="position()"/>
    <xsl:value-of select="name($p[$i + 1])"/>
  </xsl:for-each>
</xsl:function>

This clearly isn't streamable, because it involves jumping around within the sequence $p more than once. But it seems to satisfy the streamability rules in the spec.

Most constructs don't allow more than one operand to be consuming. But xsl:for-each does. The streamability rules for xsl:for-each weren't written with streamable stylesheet functions in mind; it was assumed that if the select expression selected streamed nodes, the body of the xsl:for-each would process them one at a time, with only downward selections allowed.

So there's a rule missing: possibly a rule that the function body must contain at most one reference to the streaming parameter (with a caveat allowing use in multiple choice branches).

michaelhkay commented 4 years ago

A possible fix is to say that if the declaration of a streaming parameter allows multiple nodes, then a variable reference (to the streaming parameter) that appears within a high-order operand of any construct is roaming and free-ranging.