[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[Recent Entries]
[Reply To This Message]
Re: Count all instances of a named element in a tree
Subject: Re: Count all instances of a named element in a tree
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Fri, 29 May 2009 17:55:35 +0200
|
W Charlton wrote:
Does anyone know an elegant solution to counting all elements in an XML
fragment where the elements to be counted are nested in a tree? An example
of the XML is below:
<xmltree>
<countmein>Node1</countmein>
<nodes>
<node>
<countmein>Node2</countmein>
<level>1</level>
<nodes>
<node>
<countmein>Node3</countmein>
<level>2</level>
<nodes>
<node>
<countmein>Node4</countmein>
<level>3</level>
<nodes/>
</node>
</nodes>
</node>
<node>
<countmein>Node5</countmein>
<level>2</level>
<nodes/>
</node>
<node>
<countmein>Node6</countmein>
<level>2</level>
<nodes/>
</node>
</nodes>
</node>
<node>
<countmein>Node7</countmein>
<level>1</level>
<nodes>
<node>
<countmein>Node8</countmein>
<level>2</level>
<nodes/>
</node>
</nodes>
</node>
</nodes>
</xmltree>
The count in this case would be 8.
count(/descendant::countmein)
--
Martin Honnen
http://msmvps.com/blogs/martin_honnen/
|
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format
RSS 2.0 |
|
Atom 0.3 |
|
|