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 29627 - Appendix examples eg:highest, eg:lowest - proposed improvement
Summary: Appendix examples eg:highest, eg:lowest - proposed improvement
Status: CLOSED WONTFIX
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: Functions and Operators 3.1 (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-05-15 18:42 UTC by Hans-Juergen Rennau
Modified: 2016-07-21 14:06 UTC (History)
0 users

See Also:


Attachments

Description Hans-Juergen Rennau 2016-05-15 18:42:32 UTC
The current examples assume a value getter function which maps an item to exactly one atomic value. In practise, typical candidates for such a value getter more often than not may also produce the empty sequence, for example due to the rare but not impossible absence of some XML element or attribute.

Please consider making the example a little more realistic by assuming a value getter function with this signature:
   function(item()) as xs:anyAtomicType?

The implementation of eg:higest, for example, might then look like this:

declare function eg:highest(
                     $seq as item()*, 
                     $getValue as function(item()) as xs:anyAtomicType?)
                 as item()* {
  fold-left(
    $seq,
    (),
    function($highestSoFar as item()*, $item as item()) as item()* {
      let $value := $getValue($item)
      let $highestValue := $highestSoFar[1] ! $getValue(.)
      return
        if (empty($value)) then $highestSoFar
        else if ($value > $highestValue or empty($highestSoFar)) then $item
        else if ($value = $highestValue) then ($highestSoFar, $item)
        else $highestSoFar
      }
  )
};
Comment 1 Michael Kay 2016-05-23 11:51:38 UTC
These functions are provided as examples. I'm reluctant to do work on them that is justified only because people might want to use them to solve a real problem that is different from the requirement they currently address. Indeed, one of the reasons that some of these functions were put in an appendix as examples of user-written functions, rather than putting them into the spec as core functions, was that we recognized there might be a variety of user requirements and it would be hard for a single function to satisfy them all.
Comment 2 Michael Kay 2016-05-24 15:38:07 UTC
The WG agreed with the reasoning in comment #1 and decided to take no action. There's plenty of scope for publishing useful example functions outside the W3C specification.