Hi,
variables defined as global or local variables should also be accessible within a for-each construct.
If you created a xslt variable at runtime, you could handover the variable information via attribute into your for-each construct. Therefore please define an attribute for the root element you plan to handover into the for-each loop and fill it with variable value.
Best regards
Bastian