Ryan,
sorry to answer “yes” 
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
#webMethods#API-Management#Tamino