This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.
<test-case name="orderBy63" xmlns="http://www.w3.org/2010/09/qt-fots-catalog"> <description>Test that the context item for evaluating a sort key is NOT the item whose sort key is being computed</description> <created by="Michael Kay" on="2011-07-30"/> <environment ref="orderdata"/> <dependency type="spec" value="XQ10+"/> <test><![CDATA[ declare default element namespace "http://www.w3.org/XQueryTestOrderBy"; /DataValues/( for $x in NegativeNumbers/orderData order by xs:decimal(.) return $x)]]></test> <result> <any-of> <error code="FOTY0004"/> <error code="FOTY0012"/> <error code="FORG0001"/> </any-of> </result> </test-case> Some implementations may be able to compute the result of this query without evaluating the order by clause, thereby avoiding the error condition (which is allowed under 2.3.4 Errors and Optimization). I would like to modify the query to force the order by clause to be relevant to the result. For example: declare default element namespace "http://www.w3.org/XQueryTestOrderBy"; /DataValues/( ( for $x at $pos in NegativeNumbers/orderData order by xs:decimal(.) + $pos return $x )[1] )
I don't think the proposed change helps much. An implementation can still determine that xs:decimal(.) contributes nothing to the sorting. A better fix would be one where the test is made error-free. Perhaps /DataValues/( for $x in NegativeNumbers/* order by (if name(.) = 'orderData' then $x else -$x) return $x) which produces different results depending on the context item used to evaluate name(.).
The results of the path expression should be in document order so the order by can still be eliminated in your version. What about this: /DataValues/( ( for $x in NegativeNumbers/* order by (if (name(.) = 'orderData') then $x else -$x) return $x )[1] ) With expected result: <orderData xmlns="http://www.w3.org/XQueryTestOrderBy">-0</orderData>
I missed the document order problem: could solve that by using "!" instead of "/".
I think that would work as well except currently it is a 1.0 test.
I applied the fix in Comment 2 since it appears to achieve the goal of the test without restricting it to 3.0+. Please reopen if you see a problem with this.