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

Re: Use 'count' or xsl:variable?

Subject: Re: Use 'count' or xsl:variable?
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Sun, 23 Dec 2001 09:04:36 +0000
initialize a variable in xslt
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


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.