RE: [xsl] Counting nodes

Subject: RE: [xsl] Counting nodes
From: "Andrew Welch" <awelch@xxxxxxxxxxxxxxx>
Date: Tue, 2 Jul 2002 15:24:22 +0100
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: [xsl] 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