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

Re: Subject: Counting Path Occurrences

Subject: Re: Subject: Counting Path Occurrences
From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx>
Date: Fri, 30 Mar 2007 11:48:09 +0100
Re:  Subject: Counting Path Occurrences
On 3/30/07, Scott Coon <scoon@xxxxxxxxxxxxx> wrote:

Hi - I'm trying to write a generic stylesheet to count occurrences of full paths to elements. For example, I'd like input like this:

<a>
        <b>
                <x>
                        <w>blah</w>
                </x>
                <y>bleh</y>
        </b>
        <b>
                <x>
                        <w>blih</w>
                </x>
                <x>
                        <w>bloh</w>
                </x>
        </b>
        <c>
                <w>blwh</w>
                <w>blyh</w>
        </c>
</a>

To generate this output:

/a - 1
/a/b - 2
/a/b/x - 3
/a/b/x/w - 3
/a/b/y - 1
/a/c - 1
/a/c/w - 2

This for-each-group


 <xsl:for-each-group
   select="//*/string-join(ancestor-or-self::*/name(), '/')"
   group-by=".">
	<xsl:sequence select="concat('&#xa;', ., ' - ', count(current-group()))"/>
 </xsl:for-each-group>

give this result:

a - 1
a/b - 2
a/b/x - 3
a/b/x/w - 3
a/b/y - 1
a/c - 1
a/c/w - 2

cheers
andrew

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.