W3C home > Mailing lists > Public > public-qt-comments@w3.org > November 2014

[Bug 27455] New: [xp31[ Unary lookup: specification gaps

From: <bugzilla@jessica.w3.org>
Date: Thu, 27 Nov 2014 11:16:46 +0000
To: public-qt-comments@w3.org
Message-ID: <bug-27455-523@http.www.w3.org/Bugs/Public/>

            Bug ID: 27455
           Summary: [xp31[ Unary lookup: specification gaps
           Product: XPath / XQuery / XSLT
           Version: Last Call drafts
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XPath 3.1
          Assignee: jonathan.robie@gmail.com
          Reporter: mike@saxonica.com
        QA Contact: public-qt-comments@w3.org

@@ comments on the text flagged with "@@"

[76]       UnaryLookup       ::=       "?" KeySpecifier
[53]       KeySpecifier       ::=       NCName | IntegerLiteral |
ParenthesizedExpr | "*"
UnaryLookup returns a sequence of values selected from the context item, which
must be a map or array. If the context item is not a map or an array, an error
is raised [err:XPTY0tbd].

@@ already raised: tbd needs to be defined.

If the KeySpecifier is not a wildcard

@@ nowhere is it said that "wildcard" means "*"

, the semantics of the UnaryLookup operator are as follows: Let KS denote the
items in the sequence to which the KeySpecifier evaluates. The UnaryLookup
operator is equivalent to the following expression:

for $k in KS
return .($k)

@@ This equivalence does not hold in the error case where teh context item is a
function other than a map or array.

Unary lookup is used primarily in predicates (e.g. $map[?name='Mike'] or with
the simple mapping operator (e.g. $maps ! ?name='Mike'). 

@@ In XSLT, which makes much more use of the context item, it is likely to be
used much more widely, e.g <xsl:sort select="?id"/>.

See Postfix Lookup for the postfix lookup operator.


?name is equivalent to .("name"), an appropriate lookup for a map.
?2 is equivalent to .(2), an appropriate lookup for an array or an
integer-valued map.
?($a) is equivalent to for $k in $a return .($k), allowing keys for an array or
map to be passed using a variable.
?(2 to 4) is equivalent to for $k in (2,3,4) return .($k), a convenient way to
return a range of values from an array.

@@ It might be worth pointing out that the function signature for array
functions expects xs:integer, the supplied value is atomized, and converted to
integer if it is untyped atomic. But supplying a double will give a type error.
So if @id is untypedAtomic "3", then ?(@id) works, but ?(@id+1) does not.

@@ It might also be worth a reminder that you get a dynamic error if the
subscript is out of bounds. For example

([1,2,3], [1,2,5], [1,2])[?3 = 5] gives an error because ?3 on one of the items
in the sequence fails. However, exists(([1,2,3], [1,2,5], [1,2])[?3 = 5]) might
succeed because of early exit.

If the KeySpecifier is "*" and the context item is a map, unary lookup is
equivalent to the following expression:

for $k in map:keys(.)
return .($k)

@@ We don't provide an equivalence for the case where the KeySpecifier is "*"
and the context item is an array. I think the equivalence is

for $k in 1 to array:size(.)
return .($k)

You are receiving this mail because:
You are the QA Contact for the bug.
Received on Thursday, 27 November 2014 11:16:47 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 16:57:51 UTC