[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

problem with loops

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


function sleepycat declare
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


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.