On 3/30/07, Scott Coon <scoon(_at_)gracenote(_dot_)com> 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('
', ., ' - ',
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
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--