Hi Jordan, without looking more closely, I suppose the problem is that you incidentally put a slash in front of predicates, e.g.

   packagedElement/[@xmi:id=$currID]/ownedAttribute...

while you probably wanted to say

   packagedElement[@xmi:id=$currID]/ownedAttribute...

Apart from not expressing what you wanted, foo/[...]/bar produces an error as it means a non-terminal path step producing an array, while non-terminal path steps MUST produce a sequence of nodes.

With kind regards,
Hans-Jürgen


Am Mittwoch, 3. Juli 2019, 22:24:51 MESZ hat Jordan Castillo <jordantcastillo1992@gmail.com> Folgendes geschrieben:


Hello BaseX Staff,

I am trying to finish building a map of data I have been working on and am nearly complete, but am stuck on trying to retrieve an elements value, which should just be a single integer in string format.

The function doing the work:
declare function local:propGenerator($propList, $currID){
  let $context := db:open($documentName)
  let $ret := for $x at $pos in 1 to (xs:integer(count($propList) div 3))
    let $mult := ($pos - 1) * 3
    return 
      map:merge(($propsMap, 
        map:entry(concat("prop", $pos), 
          map{"xmi:type" : $propList[1 + $mult],
              "xmi:id" : $propList[2 + $mult],
              "name" : $propList[3 + $mult],
              "lowerValue" : 1,
              "upperValue" : ($context//packagedElement/[@xmi:id=$currID]/ownedAttribute/[@xmi:id=$propList[2 + $mult]]/upperValue/[@value])
            })))
  return $ret
};

this function takes a list of strings, which come in triplets. The map is nearly built except for the "lowerValue" and "upperValue" and I'm getting an error I can't make sense of because of the line: 
"upperValue" : ($context//packagedElement/[@xmi:id=$currID]/ownedAttribute/[@xmi:id=$propList[2 + $mult]]/upperValue/[@value])

This search is going to be mirrored for the lowerValue once I get it working. The value in the "upperValue" element should always exist, and this should be unique because I am providing the IDs to narrow it down. 
The error message I am getting:
[XPTY0019] ownedAttribute: node expected, array(*) found: [ false() ].

I tried wrapping the line in question with:
if (exists($context//packagedElement/...restOfQuery...)) then 2 else ()
and I got the same error.  If I omit the line in question, the query works so I am certain that line is the problem.  
For additional info, I tried the search using an absolute path earlier and I didn't have context so I am now using the context declaration.
The snippet of the XML being used: 

<packagedElement xmi:type="uml:Classxmi:id="_18_5_2_4c1014b_1538502774996_709119_83315name="Tape">
<ownedAttribute xmi:type="uml:Propertyxmi:id="_19_0_3e30194_1541527239959_149409_93200name="InformationAssurancePropertiesvisibility="private">
<lowerValue xmi:type="uml:LiteralUnlimitedNaturalxmi:id="_19_0_3e30194_1541527239960_849380_93202"/>
<upperValue xmi:type="uml:LiteralUnlimitedNaturalxmi:id="_19_0_3e30194_1541527239960_70368_93203value="*"/>
</ownedAttribute>
<!-- lots more ownedAttributes here... -->
</packagedElement>

Any advice here would be greatly appreciated,  I am currently looking for other solutions but figured asking here would be the most helpful.

Thank you,

Jordan Castillo