[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: line numbering

Subject: Re: line numbering
From: Mukul Gandhi <mukul_gandhi@xxxxxxxxx>
Date: Thu, 5 Aug 2004 07:10:17 -0700 (PDT)
counting lines in xsl
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.