Hi Joseph, 
I hope this helps: 

let $c := <c><a>red</a><a>red</a><a>blue</a><a>green</a><a>green</a></c>
return 
  <c>
    { 
       for $color-group in $c/a
       let $color := $color-group/text()
       group by $color
       return
         for $color at $color-count in $color-group
         return <a n="{$color-count}">{$color/text()}</a>
     }
</c>

best regards, 
 Sebastian


Hi,

I have a structure like this:

<c>
<a>red</a>
<a>red</a>
<a>blue</a>
<a>green</a>
<a>green</a>
</c>

And I would like to get:

<c>
<a n="1">red</a>
<a n="2">red</a>
<a n="1">blue</a>
<a n="1">green</a>
<a n="2">green</a>
</c>

I have tried with two for loops after having identified the distinct-values(). This is in principle correct but it takes too long (I have many distinct values and a elements), because I cannot exit the for loop as soon as I get a match. I have been able to get the result with the window clause  and then counting the elements of the window with a nested for-loop: is there an alternative solution? Thanks.

Joseph

-------------------------------------------------------
     >>> business. people. technology. <<<
-------------------------------------------------------

adesso AG mit Sitz in Dortmund
Vorstand: Michael Kenfenheuer (Vors.), Christoph Junge, Andreas Prenneis
Vorsitzender des Aufsichtsrates: Prof. Dr. Volker Gruhn
Amtsgericht Dortmund HRB 20663