Subject: RE: [xsl] how getting a list of occurences From: Stuart Brown <sbrown@xxxxxxxxxxx> Date: Fri, 19 Sep 2003 09:12:57 +0100 |
Hi Elena, Try this <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <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',.)))"/> <xsl:text> </xsl:text> </xsl:for-each> </xsl:template> </xsl:transform> 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, Stuart -----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 <root> .... ... <p> <persName>pippo</persName> ... <persName>pluto</persName> ... <persName>pippo</persName> ... <persName>ciccio</persName> .... </p> .... .... </root> 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="???"> </xsl:number> </xsl:for-each> </xsl:template> but I'm unable to complete the expression required by the value attribute. Thank you in advance Elena Pierazzo XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] how getting a list of occuren, Elena Pierazzo | Thread | Re: [xsl] how getting a list of occ, Elena Pierazzo |
[xsl] xsl:result-document appending, Kloeck, Erwin | Date | Re: [xsl] element selection based o, vinod . agarwal |
Month |