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 18445 - [XQ31ReqUC] New functions for 3.1
Summary: [XQ31ReqUC] New functions for 3.1
Status: NEW
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: Requirements for Future Versions (show other bugs)
Version: Working drafts
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Jim Melton
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-07-31 07:46 UTC by Michael Kay
Modified: 2014-05-20 17:03 UTC (History)
1 user (show)

See Also:


Attachments

Description Michael Kay 2012-07-31 07:46:40 UTC
Here are some proposals for new functions in XPath 3.1.

fn:sort($seq, $function, [$collation])

sorts the items in the sequence $seq by applying $function to each one to compute a sort key; if specified, the resulting sort keys are compared using $collation. 

Justification: XPath currently has no sorting capability, this will fill the gap. In addition, XQuery sorting capability is sometimes cumbersome and inflexible, for example collations cannot be selected dynamically.

fn:index-where($seq, $function)

returns the index positions of items in $seq where $function returns true. Equivalent to

for $item at $pos in $seq where $function($item) return $pos

Justification: more flexible than index-of, less cumbersome than the equivalent FLWOR expression, available in XPath as well as XQuery. Example: to find all the paragraphs before the first h1 element, use subsequence(1, index-where(*, function($p){$p[self::h1]})[1]-1).

fn:highest($seq, $function, [$collation])
fn:lowest($seq, $function, [$collation])

returns the items in $seq having a higher/lower value for $function than any other items in the sequence. For example, fn:highest(emp, function($e){number($e/salary)}) returns the highest paid employees. The function results are compared using $collation if specified

Justification: using min() and max() for this common task is cumbersome and inefficient; using sorting is not much better. Writing a recursive function is too difficult for many users.

fn:collation($language, $flags)

returns an (implementation-dependent) collation URI suitable for sorting strings in a given language, parameterized by a set of flags. Flags might include i=case-blind, a=accent-blind, p=ignore punctuation, w=multi-word sorting, n=smart numerics, etc. The resulting collation URI is implementation-dependent and the effect of using the returned collation is also implementation-dependent.

Justification: gives an interoperable way of requesting a collation with desired characteristics, even though the results of using this collation might not be 100% interoperable. 

(An alternative which has also been suggested is to standardize a collation URI syntax using query parameters. A problem with using a function is that XQuery "order by" currently requires a statically-known collation URI. But the function would serve the needs of XPath and XSLT well.)
Comment 1 Jonathan Robie 2014-05-20 17:03:24 UTC
Assigning to future requirements per Working Group decision (https://lists.w3.org/Archives/Member/w3c-xsl-query/2012Oct/0087.html).