xsl-list
[Top] [All Lists]

Re: line numbering

2004-08-05 07:10:17
Hi James,

I hope this template helps -

<xsl:template match="/body">
   <xsl:for-each select="div">
     <xsl:for-each select="lg/l">
       <xsl:variable name="linenumber">
         <xsl:choose>
           <xsl:when test="(position() mod 5) =
0">5</xsl:when>
           <xsl:otherwise><xsl:value-of
select="position() mod 5" /></xsl:otherwise>
         </xsl:choose>
       </xsl:variable>
       <span class="line" id="line{$linenumber}">
         <xsl:value-of select="." /><span
class="number"><xsl:value-of select="$linenumber"
/></span>
       </span>
     </xsl:for-each>
   </xsl:for-each>
</xsl:template>

Regards,
Mukul

--- James Cummings <James(_dot_)Cummings(_at_)ota(_dot_)ahds(_dot_)ac(_dot_)uk>
wrote:


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 



                
__________________________________
Do you Yahoo!?
Y! Messenger - Communicate in real time. Download now. 
http://messenger.yahoo.com


<Prev in Thread] Current Thread [Next in Thread>