<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>30049</bug_id>
          
          <creation_ts>2017-01-16 11:44:33 +0000</creation_ts>
          <short_desc>[XSLT30] Request for clarification if xsl:evaluate example supposed to implement function-lookup is supposed to return empty sequence if function is not found</short_desc>
          <delta_ts>2017-01-27 10:56:32 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>XPath / XQuery / XSLT</product>
          <component>XSLT 3.0</component>
          <version>Candidate Recommendation</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows NT</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Martin Honnen">martin.honnen</reporter>
          <assigned_to name="Michael Kay">mike</assigned_to>
          
          
          <qa_contact name="Mailing list for public feedback on specs from XSL and XML Query WGs">public-qt-comments</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>128390</commentid>
    <comment_count>0</comment_count>
    <who name="Martin Honnen">martin.honnen</who>
    <bug_when>2017-01-16 11:44:33 +0000</bug_when>
    <thetext>https://www.w3.org/XML/Group/qtspecs/specifications/xslt-30/html/Overview-diff.html#evaluate-examples has an example saying

----------------------------------------------------------------------
The function-lookupFO30 function, if it were not available in the standard library, could be implemented like this:

&lt;xsl:function name=&quot;f:function-lookup&quot;&gt;
       &lt;xsl:param name=&quot;name&quot; as=&quot;xs:QName&quot;/&gt;
       &lt;xsl:param name=&quot;arity&quot; as=&quot;xs:integer&quot;/&gt;
       &lt;xsl:evaluate xpath=&quot;&apos;Q{&apos; || namespace-uri-from-QName($name) || &apos;}&apos; 
                      || local-name-from-QName($name) || &apos;#&apos; || $arity&quot;&gt;
         &lt;xsl:with-param name=&quot;name&quot; as=&quot;xs:QName&quot; select=&quot;$name&quot;/&gt;
         &lt;xsl:with-param name=&quot;arity&quot; as=&quot;xs:integer&quot; select=&quot;$arity&quot;/&gt;
       &lt;/xsl:evaluate&gt;
     &lt;/xsl:function&gt;  
     

The xsl:evaluate instruction uses the supplied QName and arity to construct an expression of the form Q{namespace-uri}local#arity, which is then evaluated to return a function item representing the requested function. 

--------------------------------------------------------------------------

However, the FO30/31 &apos;function-lookup&apos; https://www.w3.org/TR/xpath-functions-30/#func-function-lookup has the signature fn:function-lookup($name as xs:QName, $arity as xs:integer) as function(*)? and is defined to return an empty sequence if the function is not found: &quot;Otherwise (if no known function can be identified by name and arity), an empty sequence is returned&quot;.

As far as I can tell and have tested, above example of using xsl:evaluate inside of the function declaration of &apos;f:function-lookup&apos; will return an error XTDE3160 if the function is not found so in that case it is not an implementation of &apos;function-lookup&apos; and behaves differently.

So I think either the explanation should say that &apos;f:function-lookup&apos; behaves slightly differently or the function implementation needs to be fixed to

	&lt;xsl:function name=&quot;f:function-lookup&quot;&gt;
		&lt;xsl:param name=&quot;name&quot; as=&quot;xs:QName&quot;/&gt;
		&lt;xsl:param name=&quot;arity&quot; as=&quot;xs:integer&quot;/&gt;
		&lt;xsl:try&gt;
            &lt;xsl:evaluate xpath=&quot;&apos;Q{&apos; || namespace-uri-from-QName($name) || &apos;}&apos; 
                || local-name-from-QName($name) || &apos;#&apos; || $arity&quot;&gt;
                &lt;xsl:with-param name=&quot;name&quot; as=&quot;xs:QName&quot; select=&quot;$name&quot;/&gt;
                &lt;xsl:with-param name=&quot;arity&quot; as=&quot;xs:integer&quot; select=&quot;$arity&quot;/&gt;
            &lt;/xsl:evaluate&gt;
            &lt;xsl:catch errors=&quot;err:XTDE3160&quot; select=&quot;()&quot;/&gt;
		&lt;/xsl:try&gt;
	&lt;/xsl:function&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>128391</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2017-01-16 23:42:19 +0000</bug_when>
    <thetext>Certainly we should fix the example. I think it&apos;s dangerous to try and write an example and claim that its effect is precisely equivalent to fn:function-lookup(); I think it&apos;s safer to leave the example &quot;as is&quot; and qualify the claim of equivalence: 

&quot;If the function-lookupFO30 function were not available in the standard library, then a very similar function could be implemented like this:&quot;

... &quot;Note: this differs from the effect of fn:function-lookup() in that it raises an error when the function does not exist, rather than returning an empty sequence.&quot;

The related discussion on the mulberrytech xsl-list and on https://saxonica.plan.io/issues/3109 appears to raise another point, however.

Under xsl:evaluate (§10.4.2) we say: &quot;All other aspects of the dynamic context are the same as the dynamic context for the xsl:evaluate instruction itself, except ...&quot;

and this presumably includes &quot;named functions&quot;. But the dynamic context for xsl:evaluate is defined by §5.3.3, and this omits to tell us how the dynamic context component &quot;named functions&quot; is initialised. For example, does it include stylesheet functions with visibility=&quot;private&quot;?

* If such functions are excluded, then we break the rule in XPath that the functions in the dynamic context always include all the functions in the static context

* If such functions are included, then we have a strange inconsistency with the statement that the static context for the evaluation of the XPath expression supplied to xsl:evaluate excludes these functions.

Similarly, does it include XSLT-defined functions such as fn:document()? It seems a little odd that these are available to calls on fn:function-lookup(), but not available to calls on xsl:evaluate - except of course that the reason we excluded them from xsl:evaluate is to allow a free-standing third-party XPath parser to be used.

Concerning §5.3.3, we should note also:

* the dynamic context component previously called &quot;dynamic variables&quot; is now called &quot;variable values&quot;

* there are new components &quot;default language&quot;, &quot;default calendar&quot;, &quot;default place&quot;, &quot;available text resources&quot;, &quot;available uri collections&quot;, &quot;default uri collection&quot;, &quot;environment variables&quot;.

It seems best to handle these with a catch-all addition: &quot;Other components of the dynamic context are initialized as described in the [XPath 3.0] specification (or [XPath 3.1], where supported).

I also note that in §5.3.3 the link rendered as &quot;available collections&quot; is actually a link to the anchor &quot;dt-known-collections&quot; in XP30, but there is no such anchor (the actual anchor is dt-available-collections). It&apos;s not clear to me why the build system allows the link to be created without error (or, for that matter, why it passes W3C link checking). Similarly, the link rendered as &quot;available documents&quot; has anchor &quot;dt-known-docs&quot; whereas the actual anchor is &quot;dt-available-docs&quot;.

Summary of Recommendations (more detailed wording above):

1. Fix the example by withdrawing the claim that the behavior is the same as fn:function-lookup()

2. Fix the gaps in the specification of the dynamic context by saying that other components of the dynamic context are defined as in the XPath spec.

3. (Editorial) Investigate why broken links to the XPath 3.0 specification are not being detected by the build system, and fix the links that are broken.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>128392</commentid>
    <comment_count>2</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2017-01-16 23:50:00 +0000</bug_when>
    <thetext>Actually the targets &quot;dt-known-docs&quot; and &quot;dt-known-collections&quot; do exist, but they are the wrong targets: they refer to the statically known documents and collections, rather than &quot;available documents&quot; and &quot;available node/resource collections&quot;. This is also complicated by the fact that &quot;available node collections&quot; in XPath 3.0 is replaced by &quot;available resource collections&quot; in XPath 3.1.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>128415</commentid>
    <comment_count>3</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2017-01-27 10:56:32 +0000</bug_when>
    <thetext>The WG reviewed the bug and agreed with the proposed changes.

I have applied the following changes:

(a) change the example to catch XTDE3160 and return () if the function is unknown.

(b) withdraw the assertion that the function has exactly the same effect as fn:function-lookup, and add the note: &quot;The main difference between this function and the standard fn:function-lookup function is that there are differences in the functions that are visible: for example fn:function-lookup gives access to user-defined functions with private visibility, whereas xsl:evaluate does not.

(c) I have added to 5.3.3.2 (additional components of the dynamic context) the entry:

The *named functions* (representing the functions accessible using function-available or function-lookup include all the functions available in the static context, and may also include an additional implementation-defined set of functions that are available dynamically but not statically.
                        
Note: This set therefore includes some functions that are not available for dynamic calling using &lt;elcode&gt;xsl:evaluate&lt;/elcode&gt;, for example stylesheet function whose visibility is private, and XSLT-defined functions such as current and key.

Note: The rule that all functions present in the static context must always be present in the dynamic context is a consistency constraint. The effect of violating a consistency constraint is implementation-defined: it does not necessarily lead to an error. For example, if the version of a used package that is available at evaluation time does not include all public user-defined functions that were available in the version that was used at analysis time, then a processor &lt;rfc2119&gt;may&lt;/rfc2119&gt; recover by signaling an error only if the function is actually called. Conversely, if the evaluation-time version of the package includes additional public functions, these may be included in the dynamic context even though they were absent from the static context. Thus dynamic calling of functions using function-lookup may be an effective strategy for coping with variations between versions of a library package on which a stylesheet depends.

(d) Also in 5.3.3 I have added the catch-all: &quot;All other aspects of the dynamic context (for example,the current date and time, the implicit timezone, the default language, calendar, and place, the available documents, text resources, and collections, and the default collection &amp;mdash; details vary slightly between XPath 3.0 and XPath 3.1) are implementation-defined, and do not change in the course of a single transformation.&quot; and I have deleted the existing entries which this rule subsumes (current-date-time, implicit-timezone, collections).

(d) In 10.4.2 (dynamic context for xsl:evaluate) I have added the same rule as in (c), but without the notes.

(e) In the existing note in 10.4.2 I have changed &quot;document&quot; to &quot;collection&quot; in the list of example functions whose use may be restricted, because the &quot;document&quot; function is not available in xsl:evaluate.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>