[xsl] How to do Control Break?

Subject: [xsl] How to do Control Break?
From: Jonathan_Wheelhouse@xxxxxxxxxx
Date: Mon, 1 Jul 2002 18:37:41 +1000
Hi

I've got what I call a control break problem which I could easily solve in
a procedural language but don't know how to in XSLT.

The problem is that I want to alternate a <tr bgcolor="#E3EEFB"> with a <tr
bgcolor="#D0E3F8"> for each group; a group having the same firstname and
same surname.  eg.  2 rows of Adam Awad will have #E3EEFB; the 2 rows of
Adam Hutchinson will have #D0E3F8; then the next group will have #E3##FB
and so on.
Note that the number of rows per group is not constant.

I've solved this using SQL to generate a count attribute = either 0 or 1
per group.  XSLT then chooses a color based on that attribute.

However, I'm not happy with that solution because this count attribute is
not data; it's a fudge to achieve a certain presentation look.

I've read about the Muenchian method of grouping but the examples are all
about outputting something different when the group changes but not
continuing it on per entity of the group.

How would you guys do it?

Jonathan
Here's the xml, xslt and output of the current kludgey solution.

   <rs:data>
      <z:row FirstName='Adam' Surname='Awad' CurrentCountryName=''
            CurrentCityName='' CompanyName='AMP' CurrentEmailaddress
   ='Adam_Awad@xxxxxxxxxx'
            CurrentPhoneNumber='9257 3002' Count='1'/>
      <z:row FirstName='Adam' Surname='Awad' CompanyName='Compliance'
            CurrentEmailaddress='adam_awad@xxxxxxxxxx' CurrentPhoneNumber
   ='02 9257 5456'
            Count='1'/>
      <z:row FirstName='Adam' Surname='Hutchinson' CurrentCountryName=''
            CurrentCityName='' CompanyName='AMP' CurrentEmailaddress
   ='Adam_Hutchinson@xxxxxxxxxx'
            CurrentPhoneNumber='61-2-9257 5427' Count='0'/>
      <z:row FirstName='Adam' Surname='Hutchinson' CurrentCountryName=''
            CurrentCityName='' CompanyName='' CurrentEmailaddress
   ='Adam_Hutchinson@xxxxxxxxxx'
            CurrentPhoneNumber='813-5575-5400' Count='0'/>
      <z:row FirstName='Adam' Surname='Ryan' CurrentCountryName=''
            CurrentCityName='' CompanyName='AMPBanking' CurrentEmailaddress
   ='Adam_Ryan@xxxxxxxxxxxxxxxxx'
            CurrentPhoneNumber='0412 00 00 67' Count='1'/>
      <z:row FirstName='Adam' Surname='Ryan' CurrentCountryName=''
            CurrentCityName='' CompanyName='NPI' CurrentEmailaddress
   ='Adam_Ryan@xxxxxxxxxx'
            CurrentPhoneNumber='' Count='1'/>
   </rs:data>

ie. the xml is sorted on firstname and surname.  Note the "Count" attribute
flip flops between "0" and "1" when firstname and surname change.

The following XSL

    <xsl:for-each select="xml/rs:data/z:row">
       <xsl:choose>
      <xsl:when test="@Count=1">
           <tr bgcolor="#E3EEFB">
           <td><font class="FontBlack"><xsl:value-of select="@FirstName"
/></font></td>
           <td><font class="FontBlack"><xsl:value-of select="@Surname"
/></font></td>
           <td><font class="FontBlack"><xsl:value-of select="
@CurrentCityName" /></font></td>
           <td><font class="FontBlack"><xsl:value-of select="
@CurrentCountryName" /></font></td>
           <td><font class="FontBlack"><xsl:value-of select="@CompanyName"
/></font></td>
           <td><font class="FontBlack"><xsl:value-of select="
@CurrentEmailaddress" /></font></td>
           <td><font class="FontBlack"><xsl:value-of select="
@CurrentPhoneNumber" /></font></td>
           </tr>
         </xsl:when>
         <xsl:otherwise>
           <tr bgcolor="#D0E3F8">
           <td><font class="FontBlack"><xsl:value-of select="@FirstName"
/></font></td>
           <td><font class="FontBlack"><xsl:value-of select="@Surname"
/></font></td>
           <td><font class="FontBlack"><xsl:value-of select="
@CurrentCityName" /></font></td>
           <td><font class="FontBlack"><xsl:value-of select="
@CurrentCountryName" /></font></td>
           <td><font class="FontBlack"><xsl:value-of select="@CompanyName"
/></font></td>
           <td><font class="FontBlack"><xsl:value-of select="
@CurrentEmailaddress" /></font></td>
           <td><font class="FontBlack"><xsl:value-of select="
@CurrentPhoneNumber" /></font></td>
           </tr>
         </xsl:otherwise>
       </xsl:choose>
    </xsl:for-each>

produces

<tr bgcolor="#E3EEFB">
<td><font class="FontBlack">Adam</font></td>
<td><font class="FontBlack">Awad</font></td>
<td><font class="FontBlack"></font></td>
<td><font class="FontBlack"></font></td>
<td><font class="FontBlack">AMP</font></td>
<td><font class="FontBlack">Adam_Awad@xxxxxxxxxx</font></td>
<td><font class="FontBlack">9257 3002</font></td>
</tr>
<tr bgcolor="#E3EEFB">
<td><font class="FontBlack">Adam</font></td>
<td><font class="FontBlack">Awad</font></td>
<td><font class="FontBlack"></font></td>
<td><font class="FontBlack"></font></td>
<td><font class="FontBlack">Compliance</font></td>
<td><font class="FontBlack">adam_awad@xxxxxxxxxx</font></td>
<td><font class="FontBlack">02 9257 5456</font></td>
</tr>
<tr bgcolor="#D0E3F8">
<td><font class="FontBlack">Adam</font></td>
<td><font class="FontBlack">Hutchinson</font></td>
<td><font class="FontBlack"></font></td>
<td><font class="FontBlack"></font></td>
<td><font class="FontBlack">AMP</font></td>
<td><font class="FontBlack">Adam_Hutchinson@xxxxxxxxxx</font></td>
<td><font class="FontBlack">61-2-9257 5427</font></td>
</tr>
<tr bgcolor="#D0E3F8">
<td><font class="FontBlack">Adam</font></td>
<td><font class="FontBlack">Hutchinson</font></td>
<td><font class="FontBlack"></font></td>
<td><font class="FontBlack"></font></td>
<td><font class="FontBlack"></font></td>
<td><font class="FontBlack">Adam_Hutchinson@xxxxxxxxxx</font></td>
<td><font class="FontBlack">813-5575-5400</font></td>
</tr>
<tr bgcolor="#E3EEFB">
<td><font class="FontBlack">Adam</font></td>
<td><font class="FontBlack">Ryan</font></td>
<td><font class="FontBlack"></font></td>
<td><font class="FontBlack"></font></td>
<td><font class="FontBlack">AMPBanking</font></td>
<td><font class="FontBlack">Adam_Ryan@xxxxxxxxxxxxxxxxx</font></td>
<td><font class="FontBlack">0412 00 00 67</font></td>
</tr>
<tr bgcolor="#E3EEFB">
<td><font class="FontBlack">Adam</font></td>
<td><font class="FontBlack">Ryan</font></td>
<td><font class="FontBlack"></font></td>
<td><font class="FontBlack"></font></td>
<td><font class="FontBlack">NPI</font></td>
<td><font class="FontBlack">Adam_Ryan@xxxxxxxxxx</font></td>
<td><font class="FontBlack"></font></td>
</tr>





This email message and any accompanying attachments may contain
information that is confidential and is subject to legal privilege. If you are not
the intended recipient, do not read, use, disseminate, distribute or copy this 
message or attachments. If you have received this message in error, please 
notify the sender immediately and delete this message. Any views expressed
in this message are those of the individual sender, except where the sender
expressly, and with authority, states them to be the views of AMP. Before 
opening any attachments, please check them for viruses and defects.



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread