I am using XSLT to convert a very large XML document into (X)HTML. For some of the tags I am converting them to a <div>
. I would like to be able to create a unique id for these tags, using an incremented integer to form part of the unique id.
An example of the rule I am using is:
<xsl:template match="bookcoll/book">
<div class="book">
<xsl:apply-templates/>
</div>
</xsl:template>
This XSLT template is working nicely. What I would now like to have is the tag:
<div class="book">;
becoming:
<div class="book" id="book-[COUNTER-VALUE]">
Ideally the counter would start from 1, not 0.
I don't know if it makes much difference, I am using the Java packages javax.xml.parsers and javax.xml.transform to perform the actual transformation. I am a bit of an XSLT noob, so if there's any pertinent information I've missed please let me know.
How could this be achieved in XSLT?