Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: Grouping within a group? >Thread Next - Re: Grouping within a group? Re: Grouping within a group?To: NULL Date: 7/3/2009 2:08:00 PM Chris Gannon wrote: > This is my guess at the XML file structure. I'm only including 2 > different structures and only a few rows... > <!-- Structure 1 --> > <dsQueryResponse> > <Rows> > <Row> > <Meeting_x0020_Date>2009-08-27T05:00:00Z</Meeting_x0020_Date> > <bsc_SiteProperties>New Hire Orientation</bsc_SiteProperties> > <_x0023_>1</_x0023_> > <Task>Reserve room</Task> > <Row> That is not even well-formed XML, you need </Row> to close the element. Assuming the XML input is <dsQueryResponse> <Rows> <Row> <Meeting_x0020_Date>2009-08-27T05:00:00Z</Meeting_x0020_Date> <bsc_SiteProperties>New Hire Orientation</bsc_SiteProperties> <_x0023_>1</_x0023_> <Task>Reserve room</Task> </Row> <Row> <Meeting_x0020_Date>2009-08-27T05:00:00Z</Meeting_x0020_Date> <bsc_SiteProperties>New Hire Orientation</bsc_SiteProperties> <_x0023_>2</_x0023_> <Task>Place order with Catering</Task> </Row> <Row> <Meeting_x0020_Date>2009-08-27T05:00:00Z</Meeting_x0020_Date> <bsc_SiteProperties>New Hire Orientation</bsc_SiteProperties> <_x0023_>3</_x0023_> <Task>Request A/V equipment</Task> </Row> <Row> <Meeting_x0020_Date>2009-08-27T05:00:00Z</Meeting_x0020_Date> <bsc_SiteProperties>Welcome Back Session</bsc_SiteProperties> <_x0023_>1</_x0023_> <Task>Prepare invitation list</Task> </Row> <Row> <Meeting_x0020_Date>2009-08-27T05:00:00Z</Meeting_x0020_Date> <bsc_SiteProperties>Welcome Back Session</bsc_SiteProperties> <_x0023_>2</_x0023_> <Task>Contact invitees</Task> </Row> <Row> <Meeting_x0020_Date>2009-08-27T05:00:00Z</Meeting_x0020_Date> <bsc_SiteProperties>Welcome Back Session</bsc_SiteProperties> <_x0023_>3</_x0023_> <Task>Invite guest speaker</Task> </Row> <Row> <Meeting_x0020_Date>2009-09-04T05:00:00Z</Meeting_x0020_Date> <bsc_SiteProperties>General Assembly</bsc_SiteProperties> <_x0023_>1</_x0023_> <Task>Reserve Auditorium</Task> </Row> <Row> <Meeting_x0020_Date>2009-09-04T05:00:00Z</Meeting_x0020_Date> <bsc_SiteProperties>General Assembly</bsc_SiteProperties> <_x0023_>2</_x0023_> <Task>Compile Multi-Media files</Task> </Row> <Row> <Meeting_x0020_Date>2009-09-04T05:00:00Z</Meeting_x0020_Date> <bsc_SiteProperties>General Assembly</bsc_SiteProperties> <_x0023_>3</_x0023_> <Task>Notify attendees</Task> </Row> </Rows> </dsQueryResponse> then this XSLT 1.0 stylesheet <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html" indent="yes"/> <xsl:key name="k1" match="Row" use="Meeting_x0020_Date"/> <xsl:key name="k2" match="Row" use="concat(Meeting_x0020_Date, '|', bsc_SiteProperties)"/> <xsl:template match="/"> <html> <head> <title>Example</title> </head> <body> <table> <thead> <tr> <th>Meeting Date</th> <th>Meeting Details</th> </tr> </thead> <tbody> <xsl:apply-templates select="dsQueryResponse/Rows/Row[generate-id() = generate-id(key('k1', Meeting_x0020_Date)[1])]" mode="g1"/> </tbody> </table> </body> </html> </xsl:template> <xsl:template match="Row" mode="g1"> <tr> <td> <xsl:value-of select="Meeting_x0020_Date"/> </td> <td> <table> <thead> <tr> <th>Meeting Site</th> <th>Details</th> </tr> </thead> <tbody> <xsl:apply-templates select="key('k1', Meeting_x0020_Date)[1][generate-id() = generate-id(key('k2', concat(Meeting_x0020_Date, '|', bsc_SiteProperties))[1])]" mode="g2"/> </tbody> </table> </td> </tr> </xsl:template> <xsl:template match="Row" mode="g2"> <tr> <td> <xsl:value-of select="bsc_SiteProperties"/> </td> <td> <table> <thead> <tr> <th>#</th> <th>Task</th> </tr> </thead> <tbody> <xsl:apply-templates select="key('k2', concat(Meeting_x0020_Date, '|', bsc_SiteProperties))"/> </tbody> </table> </td> </tr> </xsl:template> <xsl:template match="Row"> <tr> <td> <xsl:value-of select="_x0023_"/> </td> <td> <xsl:value-of select="Task"/> </td> </tr> </xsl:template> </xsl:stylesheet> uses two keys and Muenchian grouping to group the Row elements first on the Meeting_x0020_Date child element and then on the bsc_SiteProperties child element. The output, when run against the sample shown above, is as follows: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Example</title> </head> <body> <table> <thead> <tr> <th>Meeting Date</th> <th>Meeting Details</th> </tr> </thead> <tbody> <tr> <td>2009-08-27T05:00:00Z</td> <td> <table> <thead> <tr> <th>Meeting Site</th> <th>Details</th> </tr> </thead> <tbody> <tr> <td>New Hire Orientation</td> <td> <table> <thead> <tr> <th>#</th> <th>Task</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>Reserve room</td> </tr> <tr> <td>2</td> <td>Place order with Catering</td> </tr> <tr> <td>3</td> <td>Request A/V equipment</td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </td> </tr> <tr> <td>2009-09-04T05:00:00Z</td> <td> <table> <thead> <tr> <th>Meeting Site</th> <th>Details</th> </tr> </thead> <tbody> <tr> <td>General Assembly</td> <td> <table> <thead> <tr> <th>#</th> <th>Task</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>Reserve Auditorium</td> </tr> <tr> <td>2</td> <td>Compile Multi-Media files</td> </tr> <tr> <td>3</td> <td>Notify attendees</td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </body> </html> -- Martin Honnen --- MVP XML http://msmvps.com/blogs/martin_honnen/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
