I want a solution for udnerstanding how to hold a real loop counter as Java in xQuery, not a workaround for my particular simplified demo. I know in xQuery 3.0 there is a count reserved word for FLOWR structures but its useless pre-Saxon 9.something. Here my example.
for $elem at $x in /Data/* return element Elem {
attribute Name {concat('_',$x,'.',name($elem))},
(: ...10 lines of code... :)
for $subelem at $y in $elem/*
(: ...5 lets... :)
return element SubElemen {
attribute Name {concat('_',$x,'.',$y,'_',name($subelement))},
(...20 lines of other attrs and elements ...)
for $subsubelem at $z in $subElem/SubSubElement
let $absIterIndex := 'THIS IS WHAT IM LOOKING'
let $subSubElemName := concat('_',$absIterIndex,'_',name($subElem))
return
element SubSubElem {
attribute Name {$subsubelem},
(..100 lines more playing with $x, $y, $absIterIndex, all lets for that iteration, attributes depending on them...)
The output is something like this (real data hidden and simplified)
<Elem Name="_1.Name">
<SubElem Name="_1.1_Name">
<SubSubElem Name="_1.First"/>
<SubSubElem Name="_2.Second"/>
<SubSubElem Name="_3.Third"/>
</SubElem Name="_1.1_Name">
<SubElem Name="_1.2_Name">
<SubSubElem Name="_4.Fourth"/>
<SubSubElem Name="_5.Fifth"/>
<SubSubElem Name="_6.Sixth"/>
<SubSubElem Name="_7.Seventh"/>
</SubElem Name="_1.1_Name">
<Elem Name="_2.Name">
<SubElem Name="_2.1_Name">
<SubSubElem Name="_8.Eighth"/>
<SubSubElem Name="_9.Ninth"/>
<SubSubElem Name="_10.Tenth"/>
<SubSubElem Name="_11.Eleventh"/>
</SubElem Name="_2.1_Name">
<SubElem Name="_2.2_Name"/>
</Elem Name="_2.Name">
<Elem Name="_3.Name">
<SubElem Name="_3.1_Name">
<SubSubElem Name="_12.Twelven"/>
</SubElem Name="_3.1_Name">
<SubElem Name="_3.2_Name"/>
</Elem Name="_3.Name">
This is a extension of a previous question Autoincremental auxiliar index var for XQuery nested loops, which I accepted the solution for the xQuery 3.0 counter, and then propose an alternative for manually doing it. But know i think the perspective is different and more concrete, and with a new example. If you think it should be deleted just tell it to me.