Summary question... is this legal in JSTL/XPath:

<x:forEach select="$workitemList/workItem" var="workItem1">
<x:set var="thisWorkItem" select="$workItem1"/>
......other xpath/html.....
</x:forEach>

Basically... it seems like it should work. But I can't make it work. I get blanks trying to show anything using select="$thisWorkItem/....."

I have reasons why I have to do this. Details are below. Maybe I'm going about the problem all wrong. But this seems to be the most obvious given the requirements below of nested loops. I just need a bit of direction. Thanks.

================ Details ====>

I have some XML that has recursive nesting similar to the following. It is basically representing a tree structure of workitems, child workitems, child workitems of the children, etc.

<workitems>
<workitem>
<workitems>
<workitem ......./>
<workitem>
<workitems/>
</workitem>
</workitems>
<workitem>
</workitems>

To display these in HTML, I have a large section of common code that I don't really want to have to code three or four times. So I have the 'guts' of workitem content in an include file.

I have three nested <x:forEach> blocks:
<x:forEach select="$workitemList/workItem" var="workItem1">
...level 1 html...
<%@ include file="workitemlist_row_incl.jsp" %>
<x:forEach select="$workItem1/workItems/workItem" var="workItem2">
...level 2 specific html...
<%@ include file="workitemlist_row_incl.jsp" %>
<x:forEach select="$workItem2/workItems/workItem" var="workItem3">
... level 3 specific html....
<%@ include file="workitemlist_row_incl.jsp" %>
</x:forEach>
</x:forEach>
</x:forEach>

That all pretty much works... but what I'm struggling with is the common code. The include file needs one variable that is set to the 'current' workitem, no matter what iteration or loop it's in.

I tried <x:set var="thisWorkItem" select="$workItem1"/> in the outer loop before the include statement ( and setting thisWorkItem to $workItem2 and the to $workItem3 in inner loops) The loops all happen correctly and the proper workitems are selected. But everywhere the common code has <x:out select="$thisWorkItem/@anAttribute"/> I get all blanks.

Basically, I need to know the correct JSTL/XPath way set a common variable inside nested loops.