Re: counter

Subject: Re: counter
From: Nick Browne <NickBrowne@xxxxxxxxxxxxxxx>
Date: Wed, 21 Jun 2000 13:59:47 +0100
Kay Michael wrote:

The way to print something every fifty <item> elements is:
>
> <xsl:template match="item[position() mod 50 = 1]">
> <fifty-items>
> Here's the next 50:
> <xsl:for-each select=". | following-sibling::item[position() &lt; 50]">
>   <item><xsl:value-of select="."/></item>
> </xsl:for-each>
> </fifty-items>
> </xsl:template>

Having tried this solution and some variations I had a couple of questions (I
presume that this template was called by <xsl:apply-templates select="item">)

a. I found that when running this I was getting the item content repeated in the

ouput for each element where the expression in the template match attribute was
false . I put this down to a built-in template being called for those elements,
is this correct ?

b. I changed the code such that the position() test was applied to the
apply-templates instruction, the example used was :

 <xsl:template match="root">
  <xsl:apply-templates select="item[position() mod $cntr = 1]"/>
 </xsl:template>

 <xsl:template match="item">
  <xsl:for-each select=". | following-sibling::item[position() &lt; $cntr]">
   Item <xsl:value-of select="."/>
 </xsl:for-each>
 </xsl:template>

This did not display the extra output, presumably because the template was able
to handle all item elements passed to it. However I did notice a significant
performance improvement over Mike's code which was disproportionate to the
number of item elements in the source document. For example :

No. of                   Seconds to run  Seconds to run
Item Elements        Original Code    Modified Code
100                                1                       1
200                                2                       1
400                                7                       2
800                               43                     5

Can someone explain the reason for these differences ?

Regards

Nick Browne
Slipstone Ltd




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread