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

RE: Incrementing a counter

Subject: RE: Incrementing a counter
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 14 Jun 2007 18:37:43 +0100
RE:  Incrementing a counter
> I have a problem that I cannot solve and would appreciate some help. 
> From what I understand about variables in XSLTs, you can't 
> change the value. So if that's true, how can I increment a counter?

You need to think about a higher-level description of your problem, and not
about how you would solve it in an imperative programming language.
> 
> 
> In my scripting experience, I would sort the list by 
> category, create a counter and loop through the list of items 
> comparing each subsequent item to the previous item. It it 
> was the same, I would ignore the category. That may not be 
> the most elegant solution, but it works

This "sorting and comparing to the previous category" is a procedural
algorithm for doing grouping. Grouping in XSLT 2.0 is done using
xsl:for-each-group; in 1.0 it's done (clumsily) using keys as described at
http://www.jenitennison.com/xslt/grouping.

Numbering items within a group can be done using the position() function.

Michael Kay
http://www.saxonica.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.