Subject: [xsl] Grouping by key From: gopinath.emmidisetty@xxxxxxxxxxxxxxxxxxxxxxxxx Date: Thu, 4 Nov 2004 15:08:32 +0000 |
Hello, I have XML document like below. I am trying to present the data categorised by say for eg. town like as in expected output section. I am not getting the expected output when using the xsl file as given below. I am obviously missing something. Can somebody correct me to get the above output. Many thanks. XML Docment: <documents> <account> <accountnumber>0001></accountnumber> <companyname>ABC Ltd</companyname> <town>Ford</town> <postcode>FD13QG</postcode> </account> <account> <accountnumber>0002></accountnumber> <companyname>XYZ Ltd</companyname> <town>Ford</town> <postcode>XY13QZ</postcode> </account> ... ... ... </documents> Expected output: Ford 0001 ABC Ltd FD13QG 0002 XYZ Ltd XY13QZ xsl file: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.0"> <xsl:output method="xml" omit-xml-declaration="yes"/> <xsl:key name="categorise" match="account" use="town" /> <xsl:template match="/"> <div> <xsl:apply-templates select="documents" /> </div> </xsl:template> <xsl:template match="documents"> <table> <xsl:apply-templates select="account[generate-id() = generate-id( key( 'categorise', town ) )]" mode="catcols" /> </table> </xsl:template> <xsl:template match="account" mode="catcols"> <tr> <td><xsl:value-of select="town" /></td> <xsl:apply-templates select="//account[generate-id() = generate-id( key( 'categorise', town ) )]" mode="catrows" /> </tr> </xsl:template> <xsl:template match="account" mode="catrows"> <tr> <td><xsl:value-of select="accountnumber" /></td> <td><xsl:value-of select="companyname" /></td> <td><xsl:value-of select="postcode" /></td> </tr> </xsl:template> </xsl:stylesheet>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] XSLT - update attribute w, Geert Josten | Thread | Re: [xsl] Grouping by key, Geert Josten |
Re: [xsl] Filtering duplicated data, Fanyin Wang | Date | Re: [xsl] Grouping by key, Geert Josten |
Month |