[xquery-talk] using a context node in a for loop

Robert Koberg rob at koberg.com
Tue Oct 17 10:00:33 PDT 2006


Hi, (more newbie questions)

Should the function below work? I want to define a node and use it to 
base the attributes off of. In the for loop (unlike the if..then 
statement), it seems I need the return statement, otherwise I get an 
error saying "unexpected token 'doc'". But, as written, I get an error 
"undefined context sequence for 'attribute::label'". I have also tried 
removing the parans grouping the li.

Also, notice in the for loop I am using a function to get the list to 
iterate through. Should that be a variable - or - does it only get 
evaluated once?

Here is the function:

declare function local:display-user-groups() as element()* {
   for $user-group in xmldb:get-user-groups($user)
     return
       doc(concat("projects/", $user-group, "/project.xml"))/*/
       (
         <li>
           <a href="#"
             onclick="submitForm('{@id}', '{@db-ref}')">
             {string(@label)}
           </a>
         </li>
       )
};

thanks,
-Rob



More information about the talk mailing list