Subject: Re: [xsl] line numbering From: Mukul Gandhi <mukul_gandhi@xxxxxxxxx> Date: Thu, 5 Aug 2004 07:10:17 -0700 (PDT) |
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.Cummings@xxxxxxxxxxxxxx> 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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] line numbering, David Carlisle | Thread | RE: [xsl] How to add a new font, Michael Kay |
Re: [xsl] grouping questions, Xiang Li | Date | RE: [xsl] line numbering, Andrew Welch |
Month |