Problems using 'at'

Hi,
I have Tamino 4.4 patch 6 and the following query give me a Variable Undefined: $deal error


for $contract in input()/contract return
  <contract>{
    $contract/*[not(deals)],
      <deals>{for $deal at $i in $contract/deals/deal return
        <index>{$i}</index>,
        $deal[$deal-index]/*[not(index)]
      }</deals>
  }</contract>

Am I missing something obvious?

Thanks

Ryan

Ryan,

sorry to answer “yes” :wink:

your inner FLWOR expression ends at the comma, hence
$deal[$deal-index]/*[not(index)] is outside, and $deal is not known.
I do not know what the intended semantics is, maybe you want to add parenthesis to include this into the return clause. I changed the layout of your query to make things more obvious:


for $contract in input()/contract return
  <contract>{
    $contract/*[not(deals)],
      <deals>
     {
        for $deal at $i in $contract/deals/deal return <index>{$i}</index>,
        $deal[$deal-index]/*[not(index)]
      }
      </deals>
  }</contract> 

Maybe what you want is:


for $contract in input()/contract return
  <contract>{
    $contract/*[not(deals)],
      <deals>
     {
        for $deal at $i in $contract/deals/deal 
        return (<index>{$i}</index>,
                   $deal[$deal-index]/*[not(index)])
      }
      </deals>
  }</contract> 

By the way, maybe you have to exchange $deal-index by $i

Regards

Harald

Harald,
Wow, really not having a good day with XQuery. Thanks for the help that all works now

Ryan