Q:

XQuery variable has not been declared

I know this error happens when I forget to wrap a sequence in parenthesis. But I was playing with this query for a while and put parenthesis where I saw fit. I still cannot get this query to work
         <ul>
            {for $R in doc("exp.xml")/exp/R
            let $groups := tokenize($R/@an_attribute, '\s')  

            return (
                <li>
                    <div>{$R}</div>

                    <ol> 
                        for $group in $groups
                        return (<li>{$group}</li>)
                    </ol>
                </li>
                )
            }
        </ul>

A:

you're missing the brackets to run the FLOWR inside the  tag!
<ol> 
{
    for $group in $groups
    return <li>{ $group }</li>
}
</ol>

and that's why you're getting the "variable has not been declared":  it's not setting the for loop variable $group at all

