[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Counting and double sorting on parameter
Hi all,
I would like to make a summary of a file by counting the occurence of the value of a parameter of a certain element. I've used 6. Dynamically counting an attribute from http://www.dpawson.co.uk/xsl/sect2/N2018.html. I've problem to sort the result. Can someone have an idea? What are the change I have to do in the XSLT? I'm using Saxon. Below are my data 1) the XML input 2) The expected output: 3) the current output 4) the complete XSL Thanx, Xavier. 1) the XML input <?xml version="1.0" encoding="UTF-8"?> <tiptop> <qwerty> <CPU partNum="1234"/> <CPU partNum="234"/> <CPU partNum="234"/> <CPU partNum="1234"/> <CPU partNum="54"/> </qwerty> <qwerty> <CPU partNum="89"/> <CPU partNum="94"/> <CPU partNum="934"/> <CPU partNum="934"/> </qwerty> <CPU partNum="12"/> <CPU partNum="26"/> </tiptop> 2) The expected output: partNum Qty 1234 2 234 2 934 2 12 1 26 1 54 1 89 1 94 1 3) the current output partNum Qty 1234 2 234 2 54 1 89 1 94 1 934 2 12 1 26 1 4) the complete XSL <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html" indent="yes"/> <xsl:key name="CPUs" match="*[@partNum]" use="@partNum" /> <xsl:template match="/"> <html><head></head> <body> <xsl:apply-templates select="*"/> </body> </html> </xsl:template> <xsl:template match="tiptop"> <table> <tr><th>partNum</th><th>Qty</th></tr> <xsl:apply-templates select="//*[@partNum and generate-id(.)=generate-id(key('CPUs', @partNum))]" > </xsl:apply-templates> </table> </xsl:template> <xsl:template match="*[@partNum]"> <tr> <!-- first column is the value of the partNum attribute --> <td><xsl:value-of select="@partNum" /></td> <!-- second column is the number of parts with that partNum --> <td><xsl:value-of select="count(key('CPUs', @partNum))" /></td> </tr> </xsl:template> </xsl:stylesheet>
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|