html - change count value under condition in XSLT -


i new xslt have following xml file (pets.xml)

<?xml version = "1.0"?> <?xml-stylesheet type="text/xsl" href = "pets.xsl"?> <stores> <store> <animal kind="cat">cat</animal> <animal kind="dog">dog</animal> <animal kind="bird">bird</animal> </store> <store> <animal kind="cat">cat</animal> <animal kind="bird">bird</animal> </store> <store> <animal kind="dog">dog</animal> <animal kind="bird">bird</animal> </store> </stores> 

what need generate html page contains table displaying how many pet stores have kind of animal result should be

------------------- |animal| nb stores| ------------------- |cat   |   2      | ------------------- |dog   |   2      | ------------------- |bird  |   3      | ------------------- 

what did in xslt is:

<?xml version = "1.0" encoding = "utf-8"?> <xsl:stylesheet version = "2.0"  xmlns:xsl = "http://www.w3.org/1999/xsl/transform" > <xsl:template match= "/"> <html> <body> <table border="1"> <tr> <td>animal</td> <td>nb stores</td> </tr> <xsl:variable name="count" select="0"/> <xsl:for-each select="stores/store/animal"> <xsl:variable name="an" select="@kind"/> <!--<xsl:for-each select="stores/store/animal"> <xsl:variable name="newan" select="@kind"/> <xsl:when test = "$newan=$an"> <xsl:variable name="count" select="$count+1"/> </xsl:when>--> <tr> <td> <xsl:value-of select="$an"/> </td> <td><xsl:value-of select="$count"/></td> </tr> </xsl:for-each> </table> </body> </html>  </xsl:template> </xsl:stylesheet> 

the part commented increment counter every time find store have animal placed in variable gave problems commented , table listing types of animal , under nb stores have zeros. if tell me how can change count variable when condition met. in advance.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -