I'm creating and styling an XML file, and I'm facing a problem when trying to give numbering to an element inside an ancestor. The equivalent code of the XML I'm working on is:
<A> <B> <C> <D>Text 1</D> <D>Text 2</D> <D>Text 3</D> </C> </B> <B> <C> <D>Text 4</D> <D>Text 5</D> </C> </B> </A> <A> <B> <C> <D>Text 6</D> <D>Text 7</D> <D>Text 8</D> </C> </B> </A> The numbering has to be restarted on each "A", and to do that, I'm trying to get the position of each "D" inside its "A" ancestor.
I tried with an expression like count(preceding-sibling::D)+1, but the numbering restarts on each "C" element. Also I tried with count(preceding::D)+1, but it doesn't work because it selects all the previous "D" elements of the document.
The result should be:
- Text 1 and 6 -> Position 1
- Text 2 and 7 -> Position 2
- Text 3 and 8 -> Position 3
- Text 4 -> Position 4
- Text 5 -> Position 5
How could I do to count only preceding "D" elements of each "A"?