This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Counting nodes


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@fes.uwaterloo.ca]
Sent: 02 July 2002 14:52
To: XSL-List@lists.mulberrytech.com
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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]