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

Re: xsl:counter

Subject: Re: xsl:counter
From: Mike Brown <mike@xxxxxxxx>
Date: Tue, 20 Jun 2000 09:20:11 -0600 (MDT)
xsl counter
> Is there some way of using a counter in XSL?  I have a list of items, and
> I'd like some extra text to be printed after every 50th item.

For this you don't need to increment a counter; you just need to
look at the position() of the current node. If when divided by 50 the
remainder is zero, add the extra text, like this:

<xsl:template match="item">
  <xsl:text>item text: </xsl:text>
  <xsl:value-of select="."/>
  <xsl:text>&#xA;</xsl:text>
  <xsl:if test="position() mod 50 = 0">
    <xsl:text>some extra text</xsl:text>
  </xsl:if>
</xsl:template>

> The only things which I've found which look to do this are xsl:counter and
> xsl:counter-reset, but these always seem to be unrecognised by whatever
> XML/XSL parser I use.

There is no counter in XSLT. "xsl:counter" is something Microsoft made up
for MSXML1/IE5. 

You also can't implement a counter in an obvious way, since variables
cannot be updated once they are assigned. A named template can be used to
generate a result tree fragment that contains a number that is 1 greater
than a number passed into it as a parameter. When assigned to a variable,
this fragment can be treated like a number in numeric comparisons.

For generating numeric text nodes based on things in the source tree, you
can use xsl:count.

   - Mike
____________________________________________________________________
Mike J. Brown, software engineer at         My XML/XSL resources:
webb.net in Denver, Colorado, USA           http://www.skew.org/xml/


 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.