Re: [xsl] how getting a list of occurences

Subject: Re: [xsl] how getting a list of occurences
From: Elena Pierazzo <pierazzo@xxxxxxxxxxxxx>
Date: Fri, 19 Sep 2003 10:28:28 +0200
Hi Stuart,

it works perfectly, thank you a lot!


Stuart Brown wrote:

Hi Elena,

Try this

<xsl:transform xmlns:xsl="";

<xsl:key name="persNames" match="persName" use="."/>

 <xsl:template match="/">
   <xsl:for-each select="root//persName[not(.=preceding::persName)]">
     <xsl:sort select="."/>
     <xsl:value-of select="concat(.,' ',count(key('persNames',.)))"/>


This creates a key, which is essentially a list of all the nodes that match
the match= attribute expression (in this case, all the persName elements),
and then indexes them by their contect (use=".").

The for-each instruction then selects all the persNames which do not equal a
preceding occurrence of persName (i.e. a uniqued list). I've added a sort
for alphabetical ordering. Finally, it outputs the value of the element
itself, a space, and then uses the key to count the number of persName
elements that have the same content.

Hope this helps,


-----Original Message-----
From: Elena Pierazzo [mailto:pierazzo@xxxxxxxxxxxxx] Sent: 19 September 2003 08:36
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] how getting a list of occurences

Hi all, I firstly apologize for my beginner's question.

I've an XML document like this

I would like to get as an output a list of all the occurences of the <persName> element and the number of time that the form occours, like that:

pippo 2
pluto 1
ciccio 1

I've tryed to do this using <xsl:number> as follow:

<xsl:template match="p">
<xsl:for-each select="persName">
<br />
<xsl:value-of select="." />:
<xsl:number count="*" value="???">

but I'm unable to complete the expression required by the value attribute.
Thank you in advance

Elena Pierazzo

XSL-List info and archive:

XSL-List info and archive:

XSL-List info and archive:

Current Thread