This may look a bit better - the code is the same i have just added the code correctly into tags nowThe XML is:
<p> <name>jack</name> <name>jack</name> <name>jan</name> <name>jack</name> <name>jack</name></p>
The XSL is:
<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.1" xmlns:str="http://exslt.org/strings"><xsl:output method="text" indent="no"/><xsl:variable name="newline" select="''"/><xsl:key name="names" match="name" use="text()"/> <xsl:template match="/"> <xsl:for-each select="p/name[generate-id() = generate-id(key('names',text())[1])]"> <xsl:variable name="currentName" select="text()"/> <!-- print output --> <xsl:value-of select="text()"/> <xsl:value-of select="': '"/> <xsl:value-of select="count(//name[text() = $currentName])"/> <xsl:value-of select="$newline"/> </xsl:for-each> </xsl:template></xsl:stylesheet>
The Output is:jack: 4jan: 1