[xsl] line numbering

Subject: [xsl] line numbering
From: James Cummings <James.Cummings@xxxxxxxxxxxxxx>
Date: Thu, 5 Aug 2004 14:17:21 +0100 (BST)
Hi there,

I have some poems marked up something like:

<body>
<div type="poem">
<lg type="stanza">
<l>This is a line of verse</l>
<l>This is a line of verse</l>
<l>This is a line of verse</l>
<l>This is a line of verse</l>
</lg>
<lg type="stanza">
<l>This is a line of verse</l>
<l>This is a line of verse</l>
<l>This is a line of verse</l>
<l>This is a line of verse</l>
</lg>
<p>This is something not counted as a line</p>
<lg type="stanza">
<l>This is a line of verse</l>
<l>This is a line of verse</l>
<l>This is a line of verse</l>
<l>This is a line of verse</l>
</lg>
</div>
<!-- and multiple poem div's like this here... -->
</body>

What I want to end up with is for each line to be 
given an @id in the html output like:
<span id="poem3line10">This is a line of verse <span
class="number">10</span></span>

<xsl:template match="l">
<xsl:variable name="linenumber" select="count(preceding-sibling::l)+1"/>
<span class="line" id="line{$linenumber}"><xsl:apply-templates /></span>
</xsl:template>

But now I need to account for two factors:
a) that the linenumbering needs to take account of 
the existence of the line-groups (lg) and that it 
should only count back within it's own <div> ancestor.
b) that I want to number the lines every 5 lines. 

Is position() a better way to do this than counting the 
preceding-sibilings?

Any (XSLT1 preferred, but XSLT2 acceptable) suggestions/solutions?

-James
---
Dr James Cummings, Oxford Text Archive, University of Oxford
James dot Cummings at oucs dot ox dot ac dot uk 

Current Thread