XQuery For Loop Index variable not working
794954Feb 1 2011 — edited Oct 10 2011Hi,
I am using the below syntax for the for loop implementation in xquery
for $Reading at $Position in $MiddlewareMessage1/ns1:Data/ns1:Message/ns1:Reading
return
<ns0:Event latitude="{xs:decimal(data($MiddlewareInboundMessage1/ns1:Data/ns1:Message/ns1:Reading[$Position]/ns1:Lat))}"
longitude="{xs:decimal(data($MiddlewareInboundMessage1/ns1:Data/ns1:Message/ns1:Reading[$Position]/ns1:Long))}">
</ns0:Event>
}
Reading is a repeatable element under the source schema of Xquery at $MiddlewareMessage1/ns1:Data/ns1:Message and Event is a repeating element of the atrget schema of xquery.
When i test this using just one complex of Reading element it works fine. But if i try giving multiple records for Reading then i get an error - expected zero or one item, got two or more items
I am not sure what the problem is. Is there any error with the usage of for loop Position variable. Please suggest. Thanks in advance.