Hi!
If I understand correctly and you really want to use indexes (positions), you should be able to use something like:
Quote:for $p in $XML1/PEOPLE/PERSON
return if ( $XML2/TYPES/TYPE[xs:integer($p/TYPENUM)]/SELECT='1') then $p/NAME else ()
If you have big XML trees with many elements, you can also build a map at the beginning for faster execution, e.g.:
Quote:let $m := map:merge($XML2/TYPES/TYPE/map:entry(position(), SELECT ='1'))
return $XML1/PEOPLE/PERSON[map:get($m, xs:integer(TYPENUM))]/NAME
When trying out the attached sample, you will see a bug in your sample data: ‘Paul’ is handled as ‘Woman’ (because its TYPENUM is ‘2’ although its TYPE is 'BOY')
Depending on your real use case, it can also make sense to directly use the TYPE of the PERSONs to make the lookup in $XML2, e.g.:
Quote:let $selected := $XML2/TYPES/TYPE[SELECT='1']/NAME
return $XML1/PEOPLE/PERSON[TYPE=$selected]/NAME
Unsure how the attached sample fits your original question, so please let us know if this helps.