Jump to content

matts888

Members
  • Posts

    2
  • Joined

  • Last visited

Contact Methods

  • MSN
    matts888
  • Website URL
    http://
  • ICQ
    0

Profile Information

  • Location
    Sydney, Australia

matts888's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. 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
  2. This may not be the best way but it is one method which works with version 1 and the sample XML you gave. This is my first post so i hope it inserts the code neatly.<?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>
×
×
  • Create New...