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

Re: counter

Subject: Re: counter
From: Nick Browne <NickBrowne@xxxxxxxxxxxxxxx>
Date: Wed, 21 Jun 2000 13:59:47 +0100
counter nick
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

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.