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 29981 - required="no" on additional tunnel parameters of overriding template
Summary: required="no" on additional tunnel parameters of overriding template
Status: RESOLVED FIXED
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: XSLT 3.0 (show other bugs)
Version: Candidate Recommendation
Hardware: PC Windows NT
: 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: 2016-11-06 01:31 UTC by Max Toro
Modified: 2016-11-17 21:11 UTC (History)
1 user (show)

See Also:


Attachments

Description Max Toro 2016-11-06 01:31:45 UTC
On section 3.5.3.3 (Overriding Components from a Used Package) it says:

> Two named templates with the same name are compatible if and only if they satisfy all the following rules:
> 
> ...
> 3. Any parameter on the overriding template for which there is no corresponding parameter on the overridden template specifies required="no".
> ...

I understand this requirement for "normal" parameters, but not for tunnel parameters. If the existence of tunnel parameter arguments for a template invocation can only be determined at runtime, why can't we let an overriding template fail at runtime because of a missing tunnel parameter, just like any other template?
Comment 1 Abel Braaksma 2016-11-06 07:53:08 UTC
Interesting. I am not sure the current rules for tunnel parameters are 100% complete. The only case I could find related to existing/non-existing tunnel parameters is this:

"If a tunnel parameter is declared in an xsl:param element with the attribute tunnel="yes", then a dynamic error occurs [see ERR XTDE0700] if the set of tunnel parameters passed to the template does not include a parameter with a matching expanded QName."

And this seems at odds with our other statement:

"All other options of xsl:with-param and xsl:param are available with tunnel parameters just as with non-tunnel parameters. For example, parameters may be declared as mandatory or optional,...."

Since the first statement requires a parameter to be passed (same as required="yes") and the second statement allows you to specify required="yes" and required="no".

Suppose you have the following:

<xsl:template match="foo">
   <xsl:param tunnel="yes" select="12" name="count" />
</xsl:template>

This tunnel parameter has a default. But if the template is entered and there is no such tunnel parameter, we need to raise XTDE0700. If this is intentional, then having a default value is redundant. But I think this is not intentional.

But, if we change this:

<xsl:template match="foo">
   <!-- explicitly required -->
   <xsl:param tunnel="yes" name="foo" required="yes" />
   <!-- implicitly required -->
   <xsl:param tunnel="yes" name="bar" as="xs:integer" />
</xsl:template>

This suggests that *if* the template is hit, it is required, but it already was required per XTDE0700. So, conversely, this is redundant given the current reading of this error.

I may be misinterpreting this part of the spec, but I would assume that some tightening up may be needed.

Without this cleared up, it will be hard to give an informed decision on your point.
Comment 2 Michael Kay 2016-11-06 14:23:48 UTC
Abel: yes, the paragraph "If a tunnel parameter is declared in an xsl:param element with the attribute tunnel="yes", then a dynamic error occurs [see ERR XTDE0700] if the set of tunnel parameters passed to the template does not include a parameter with a matching expanded QName." is clearly incomplete: if you follow the link to XTDE0700 it is clear that the error only applies if the parameter is explicitly or implicitly required.

Max: yes, I agree, the constraints here could be relaxed. I think it's very unlikely that a processor would attempt to make any static inferences or optimizations based on the tunnel parameters declared in a named template, and therefore we could in principle remove all constraints about the compatibility of tunnel parameter declarations in an overriding template (whatever the value of the 'required' attribute).

In fact we've unintentionally eliminated what was probably the original use case for tunnel parameters, which is to override one template A by setting a tunnel parameter, and override another template B by using that tunnel parameter, without having to override all the other templates on the call stack from A to B.
Comment 3 Abel Braaksma 2016-11-06 17:39:08 UTC
> if you follow the link to XTDE0700 it is clear that the error only applies 
> if the parameter is explicitly or implicitly required.
Mea culpa, I thought I was quoting the error itself...
Comment 4 Michael Kay 2016-11-11 10:01:31 UTC
I have modified the paragraph cited by Abel in comment #1 to make it clear that the error applies only where a parameter is explicitly or implicitly mandatory.

The original observation from Max pointing out that the "compatibility" rules for template overriding should be relaxed remains for WG attention. My recommendation is that in 3.5.3.3, in the section dealing with named templates, we should change the rule:

Two named templates with the same name are compatible if and only if they satisfy all the following rules:...

(2) For every parameter on the overridden template, there is a parameter on the overriding template that has the same name, an identical required type, and the same effective values for the tunnel and required attributes.

to read:

(2) For every non-tunnel parameter on the overridden template, there is a non-tunnel parameter on the overriding template that has the same name, an identical required type, and the same effective values for the required attribute.

plus a Note:

Note: tunnel parameters can vary between the overriding template and the overridden template; in particular (a) the overriding template can omit the declaration of a tunnel parameter whose value is not needed, and (b) the overriding template can add tunnel parameters that were not present in the original if these are needed to parameterize the behavior of the overriding template.
Comment 5 Michael Kay 2016-11-17 20:31:29 UTC
The proposal was accepted with an amendment: if a tunnel parameter is present on both the overriding and overridden template, then it must have the same type in both.
Comment 6 Michael Kay 2016-11-17 21:11:24 UTC
The changes have been applied.