[xquery-talk] problem with loops
titash_neogi at symantec.com
Wed Jan 4 03:46:45 PST 2006
Thanks a Lot!!
This worked like a breeze. :)
From: John Snelson [mailto:jsnelson at sleepycat.com]
Sent: Wednesday, January 04, 2006 4:59 PM
To: Titash Neogi
Cc: talk at xquery.com
Subject: Re: [xquery-talk] problem with loops
In that case, you'll want to do something like this:
declare function local:depends($map as node(), $name as xs:string) as
let $entry := $map/maps/map[res = $name]
let $depend := string($entry/pre)
return if(exists($entry)) then ($name, local:depends($map, $depend))
Which should do want you want.
Titash Neogi wrote:
> Thanks for the replies.
> Here is a simplified outline of what I am trying to do
> I have a xml file as shown below
> <pre> DATA0 </pre> <res> DATA1 </res> </map>
> <pre> DATA1 </pre> <res> DATA2 </res> </map>
> <pre> DATA2 </pre> <res> DATA3 </res> </map>
> <pre> DATA3 </pre> <res> DATA4 </res> </map>
> Now the idea is that if I search for DATA4, the system will trace its
> path backwards and find out all the linked dependencies. So the output
> would something like
> Query - DATA4
> Result - DATA4 DATA3 DATA2 DATA1 DATA0
> The algorithm I am trying to implement is
> 1. Obtain input from user
> 2. repeat steps 3 through 5 for the entire file
> 3. send user input to function A that identifies the <map> </map>
> corresponding to this input
> 4. send the output of function A (step 3) to a function B that
> the pre/text() bit of this chunk
> 5. send the output of function B (step 4) to function A (step 3 again)
> to identify the <map> </map> chunk
> Now, to repeat, my problem is that my function overwrites the values
> the loop so that I only get the last variable's output.
> Hope this makes the logic a little clearer.
> Any further help on this would be really nice.
John Snelson, Berkeley DB XML Engineer
Sleepycat Software, Inc
Contracted to Sleepycat through Parthenon Computing Ltd
More information about the talk