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

RE: Counting nodes

Subject: RE: Counting nodes
From: "Andrew Welch" <awelch@xxxxxxxxxxxxxxx>
Date: Tue, 2 Jul 2002 15:24:22 +0100
getelementsbytagname xsl number
wd-xsl doesnt have a count function, so you have to write your own.
This should do what you want:

function count(obj,tagName) {
    var a = getElementsByTagName(tagName);
    return a.length;
  } 

Pass to it the parent element which contains all of the nodes you wish
to count, and the element name.  For example:

<xsl:template match="lineage">
  <xsl:eval>count(this,'procstep')</xsl:eval>
</xsl:template>

Or, the less reusable but ultimately better:

<xsl:template match="lineage">
  <xsl:eval>getElementsByTagName('procstep').length</xsl:eval>
</xsl:template>

Of course, to save your head from bursting, its easier to move to XSLT
and use the count() function or <xsl:number>

cheers
andrew

-----Original Message-----
From: Mike Leahy [mailto:mgleahy@xxxxxxxxxxxxxxxx]
Sent: 02 July 2002 14:52
To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
Subject:  Counting nodes


Hello list,

I am using the namespace "http://www.w3.org/TR/WD-xsl"

I would like to be able to count the occurrance of a particular tag
(e.g.
"procstep" can occur multiple times within "metadata/dataqual/lineage"
in
the XML files I am using).  The count function is not a recognized
function
in the namespace I am using - is there any other way I could get this
number?

Mike


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list





---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.350 / Virus Database: 196 - Release Date: 17/04/2002
 

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.350 / Virus Database: 196 - Release Date: 17/04/2002
 

 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.