[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: "Scott Coon" <scoon@xxxxxxxxxxxxx>
Date: Tue, 3 Apr 2007 19:07:58 -0700
Re:  Subject: Counting Path Occurrences
> On 4/1/07, Mukul Gandhi <gandhi.mukul@xxxxxxxxx> wrote:
> > On 3/30/07, Andrew Welch <andrew.j.welch@xxxxxxxxx> wrote:
>
> >    <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>
>
>
> Nice solution.
>
> Except, if we change slightly the concat to following (please note a
> starting '/'):
> concat('&#xa;', '/', ., ' - ', count(current-group()))
>
>
> We'll get exactly what the OP wants.


So, just to make sure I understand this right, for each descendent node,
you use this string-join function to build the full path via the
ancestors:

 -- string-join(ancestor-or-self::*/name(), '/')

Since you're doing this in the select clause of the for-each-group, the
things to be grouped are already the desired paths, so you just group-by
".".  And for the same reason, you can use "." in the concat clause to
format the output.

I would also get the same result by separating things like this, right?

<xsl:for-each-group select="//*"
group-by="string-join(ancestor-or-self::*/name(), '/')">
[blah....]
</xsl:for-each-group>

Guys, this is terrific.  Thanks very much for the prompt replies.

Scott

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.