[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: counter
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() < 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() < $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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|