This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Use 'count' or xsl:variable?
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: ssd xcxc <marina777uk at yahoo dot com>
- Cc: xsl-list at lists dot mulberrytech dot com
- Date: Sun, 23 Dec 2001 09:04:36 +0000
- Subject: Re: [xsl] Use 'count' or xsl:variable?
- Organization: Jeni Tennison Consulting Ltd
- References: <20011223083052.79241.qmail@web21201.mail.yahoo.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi Marina,
> I have an xml document of books like this...
[snip]
> and need to count how many titles there are for every instance of
> last_names. Is it better to initialize a variable and increment it
> every time or just use the 'count' part of select?
In XSLT, once a variable has been given a value, you can't change that
variable's value, so it's not possible to increment it. The easiest
way to count nodes is to use the count() function. For example to
count how many books there are with a last_name of 'Austen', you would
use:
count(/library/book[last_name = 'Austen'])
(although if you're doing this a lot you'll be better off with a key)
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list