Project

Profile

Help

Bug #5110

closed

XPDY0002 The context item is absent, so position() is undefined for use of position() inside predicate

Added by Martin Honnen about 3 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
XQuery conformance
Sprint/Milestone:
Start date:
2021-09-30
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
10, 11, trunk
Fix Committed on Branch:
10, trunk
Fixed in Maintenance Release:
Platforms:
.NET, Java

Description

I get the error

Error on line 8 column 29 of powerset1.xq:
  XPDY0002  The context item is absent, so position() is undefined
     Focus: absent
     Local variables
        $counter = 0
        $input =  ("A", "B", "C", ... [4])
        $counter-bin = xs:base64Binary("AA==")
     invoked by unknown caller (class net.sf.saxon.value.MemoClosure)
     Focus: absent
     Local variables
        $counter = 0
        $input =  ("A", "B", "C", ... [4])
     invoked by function call at file:/C:/Users/Martin%20Honnen/OneDrive/Documents/XQuery/powerset/./powerset1.xq#17
     Focus: absent
     Local variables
        $a = []
        $i = 0
        $input =  ("A", "B", "C", ... [4])
     invoked by unknown caller (class net.sf.saxon.functions.hof.UserFunctionReference$BoundUserFunction)

running Saxon 10.6 EE Java against the XQuery

declare namespace math = 'http://www.w3.org/2005/xpath-functions/math';
declare namespace bin = 'http://expath.org/ns/binary';
declare namespace array = 'http://www.w3.org/2005/xpath-functions/array';

declare function local:combination($counter as xs:integer, $input as item()*) as item()* {
   let $counter-bin := bin:from-octets($counter)
   return $input[
     let $j:= position() - 1,
     $bin := bin:and($counter-bin, bin:shift(bin:hex('1'), $j)) 
     return bin:to-octets($bin) > 0]
 };
 
declare function local:powerset($input as item()*) as array(item()*) {
  fold-left(
    0 to (xs:integer(math:pow(2, count($input))) - 1),
    [],
    function($a, $i) { array:append($a, local:combination($i, $input)) }
   )
 };
 
local:powerset(('A', 'B', 'C', 'D'))

The code runs fine with BaseX, outputting [(), "A", "B", ("A", "B"), "C", ("A", "C"), ("B", "C"), ("A", "B", "C"), "D", ("A", "D"), ("B", "D"), ("A", "B", "D"), ("C", "D"), ("A", "C", "D"), ("B", "C", "D"), ("A", "B", "C", "D")].

Please register to edit this issue

Also available in: Atom PDF