![]() |
|
![]() | ||
|
Subject:
xslt grouping
Category: Computers > Software Asked by: boulderdude-ga List Price: $20.00 |
Posted:
12 Oct 2004 01:10 PDT
Expires: 11 Nov 2004 00:10 PST Question ID: 413552 |
I need to group and count nodes in an xml document with xslt. I've read the grouping stuff on the web, but I'm either dumb or lazy and can't get it to work. I'm not interested in how to do this generically. I'm interested in how to specifically write the xslt that produces the output below, not generic information about grouping, Muenchen method, nor anything else. (I'm lazy :) Anyway. I have the following xml. <page> <foo accountID="1" createdDate="10/9/2004 10:20:03 AM"/> <foo accountID="2" createdDate="10/9/2004 11:20:03 AM"/> <foo accountID="5" createdDate="10/10/2004 10:15:27 AM"/> <foo accountID="6" createdDate="10/10/2004 10:14:00 AM"/> <foo accountID="7" createdDate="10/12/2004 10:15:27 AM"/> </page> I want the output to be like this: <table> <tr> <th>Date Created</th> <th>Accounts Created</th> </tr> <tr> <td>10/9/2004</td> <td>2</td> </tr> <tr> <td>10/10/2004</td> <td>2</td> </tr> <tr> <td>10/12/2004</td> <td>1</td> </tr> </table> ps. I've been trying the grouping xslts that I've seen on the web (with keys and such, but b/c I'm selecting substring-before(@createdDate, ' ') I can't seem to get it to work. |
![]() | ||
|
There is no answer at this time. |
![]() | ||
|
Subject:
Re: xslt grouping
From: markmceahern-ga on 12 Oct 2004 05:48 PDT |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:key name="createdDate" match="*[@createdDate]" use="substring-before(@createdDate, ' ')" /> <xsl:template match="foo"> <table> <tr> <th>Date Created</th> <th>Accounts Created</th> </tr> <xsl:apply-templates select="*[@createdDate and generate-id(.)=generate-id(key('createdDate', substring-before(@createdDate, ' ')))]" /> </table> </xsl:template> <xsl:template match="*[@createdDate]"> <tr> <!-- first column is the value of the date attribute --> <td><xsl:value-of select="substring-before(@createdDate, ' ')" /></td> <!-- second column is the number of records with that date --> <td><xsl:value-of select="count(key('createdDate', substring-before(@createdDate, ' ')))" /></td> </tr> </xsl:template> </xsl:stylesheet> |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |