Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Grouping within a group?

From: Martin Honnen <mahotrash@-----.-->
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/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent