[Bug 18445] New: [3.1] New functions for 3.1

https://www.w3.org/Bugs/Public/show_bug.cgi?id=18445

           Summary: [3.1] New functions for 3.1
           Product: XPath / XQuery / XSLT
           Version: Working drafts
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XQuery 3.1 Requirements and Use Cases
        AssignedTo: jonathan.robie@gmail.com
        ReportedBy: mike@saxonica.com
         QAContact: public-qt-comments@w3.org


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.)

-- 
Configure bugmail: https://www.w3.org/Bugs/Public/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.

Received on Tuesday, 31 July 2012 07:46:44 UTC