I have this XML document where I want to modify using XSLT to a different format. The problem I'm currently facing is finding the absolute position of a tag relative to root and not to the parent.
For instance take the following example:
<book>
<section>
<chapter>
</chapter>
</section>
</book>
<book>
<section>
<chapter>
</chapter>
</section>
</book> <book>
<section>
<chapter>
</chapter>
</section>
</book> <book>
<section>
<chapter>
</chapter>
</section>
</book>
Desired output:
<book id=1>
<section id=1>
<chapter id=1>
</chapter>
</section>
</book>
<book id=2>
<section id=2>
<chapter id=2>
</chapter>
</section>
</book>
<book id=3>
<section id=3>
<chapter id=3>
</chapter>
</section>
</book>
<book id=4>
<section id=4>
<chapter id=4>
</chapter>
</section>
</book>
To get the id for the book tag can be easily achieved by using the position(), but once we go down to section and chapter things get trickier.
A solution for this problem would be creating a global variables that would work as counters for section and chapter, which would increment every time one of these tags are found in the document, but variables in XSLT behave like constants.
thanks in advance,
fbr