This discussion is archived
0 Replies Latest reply: Jul 25, 2012 9:05 AM by MarcPérez RSS

XQuery in for-each returns changes in runtime

MarcPérez Newbie
Currently Being Moderated
Hi,
I have the following XQuery function:

------------------------------------------------------------------------------------------------------------------------
if ($calloutResponse//Error)
     then
<ns0:serviceResponse>
               <ns1:code>001</ns1:code>
               <ns0:contacts>{$tempVar//ns0:contacts/node()}</ns0:contacts>
     </ns0:serviceResponse>
          else
     <ns0:serviceResponse>
          {if ($tempVar//ns1:code/text() = 001)
                 then(
                      <ns1:code>001</ns1:code>
             else(
                         <ns1:code>000</ns1:code>
             }<ns0:contacts>{$datosContactosOutput//ns0:contactos/node()}
{              
for $contact in ($calloutResponse//contact)
     return
     <ns0:contact>
          FILL CONTACT INFO
</ns0:contact>
                    }
</ns0:contacts>
</ns0:serviceResponse>
------------------------------------------------------------------------------------------------------------------------

The goal is to call an external service for-each user and get it's contact info. If the call results in an error, code 001 is set with the previous obtained data and the loop continues.

The following correct executions should skip the first condition and check if the existing code is 001, keeping it if so.

When executed on the tester, it respects the <code> value from the previous iteration, but in runtime it takes the last execution's value. That means 001 is only set when the last execution results in an error.

$TempVar is the variable being set with the result of this XQuery and is being fed into the XQuery itself.

Can anyone tell me what's going wrong in runtime?

Thank you!

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points