|
next
|
Subject: observing xquery at work Author: David Rogers Date: 25 Jul 2009 12:42 PM
|
Hi There,
I am learning xquery and trying to start thinking functionally, rather than procedurally - this is a painful transition.
Anyhow, when I learnt things like "for" loops in OO programming, I would do little things like output to screen a counter, or some uniquely identifiable text, so that I could observe exactly what was going on. I'm having a lot of troublg doing this in xquery, on account of the fact that variables cannot be changed, once assigned.
So as an example, I have a query that sets up two "for" statements - an inner one and an outer one (see below). Many of the elements in the result-set are identical, so I can't observe exactly how the output was arrived at. I tried to implement a counter (but I kinda knew that wouldn't work before I even tried).
Can anyone please give me a couple of tips which might be helpful in observing exactly how results are arrived at. E.g. I'm looking for a way to print out something unique with each element that is output by my nested for statements.
My query looks like this:
let $store := doc("stores.xml")//store
for $store1 in $store
for $store2 in $store
for $prod1 in $store1/product
for $prod2 in $store2/product
return
<elem>{$prod1/@pid, $prod1/name/text()</elem>
Thanks
|
|
|