[xquery-talk] problem with loops

John Snelson jsnelson at sleepycat.com
Wed Jan 4 11:29:04 PST 2006


In that case, you'll want to do something like this:

declare function local:depends($map as node(), $name as xs:string) as 
xs:string*
{
   let $entry := $map/maps/map[res = $name]
   let $depend := string($entry/pre)
   return if(exists($entry)) then ($name, local:depends($map, $depend)) 
else $name
};

local:depends(doc("file.xml"), "DATA4")

Which should do want you want.

John

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
> 
> <maps>
> <map>
> <pre> DATA0 </pre> <res> DATA1 </res> </map>
> <map>
> <pre> DATA1 </pre> <res> DATA2 </res> </map>
> <map>
> <pre> DATA2 </pre> <res> DATA3 </res> </map>
> <map>
> <pre> DATA3 </pre> <res> DATA4 </res> </map>
> .
> .
> .
> 
> </maps>
> 
> 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> chunk
> corresponding to this input
> 
> 4. send the output of function A (step 3) to a function B that extracts
> 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 in
> 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.
> 
> Thanks 
> Titash

-- 
John Snelson, Berkeley DB XML Engineer
Sleepycat Software, Inc
http://www.sleepycat.com

Contracted to Sleepycat through Parthenon Computing Ltd
http://blog.parthcomp.com/dbxml


More information about the talk mailing list