Hi everyone!
I'm quite new to XML and XSLT and am trying to work out how to do the following example:
xml code:
Code:<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet href="Example02.xsl" type="text/xsl"?> <root> <dog> <breed>Clumber</breed> <name>Bonnie</name> <weight>70</weight> </dog> <dog> <breed>Clumber</breed> <name>Presley</name> <weight>85</weight> </dog> <dog> <breed>Cocoa</breed> <name>Lhasa Apso</name> <weight>22</weight> </dog> </root>
XSLT code:
Code:<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml"> <xsl:output method="xml" indent="yes" encoding="UTF-8"/> <xsl:key name="dogs" match="/root/dog" use="breed"/> <xsl:template match="/"> <html> <head> <title>Example02</title></head> <body> <table border="1"> <tr bgcolor="#9acd32"> <th>Breed</th> <th>Number of Dogs</th> </tr> <xsl:for-each select="root/dog[generate-id() = generate-id(key('dogs',breed)[1])]"> <xsl:sort select="breed"/> <tr> <th><xsl:value-of select="breed"/></th> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
I have written it so that if you open the xml file in explorer you get a table which shoes the different breeds of dogs in the left hand column.
The part that I am unable to do it to fill the right hand column with the number of each breed of dog that is in the xml...
I believe I should use count() somehow but am having trouble working out exactly what to do...
any help would be appreciated.
Thanks!!
(files should be attached too)


Reply With Quote
