This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: How to do Control Break?


You've actually got two levels of grouping here. The first level is
"successive rows with the same firstname and surname". The second level
is "two such groups".

I think it's very hard to do both these levels in one pass, because
identifying the nodes in the outer group depends on identifying those in
the inner group. So do two passes. In the first pass create a temporary
tree containing a <person> element for each group of rows with the same
firstname+surname; in the second pass do 

<xsl:for-each select="xx:node-set($temp)/person[position() mod 2 = 1]"

However, perhaps you are making life more difficult than you need to by
not doing the work in the SQL statement. XSLT is designed to process
heirarchic data, whereas SQL always delivers flat tabular data. XSLT 1.0
isn't particular good at turning flat data into hierarchic data (this is
what "grouping" is all about) so any help you can give it by including
extra data in the generated XML is worth doing.

Michael Kay
Software AG
home: Michael.H.Kay@ntlworld.com
work: Michael.Kay@softwareag.com 

> -----Original Message-----
> From: owner-xsl-list@lists.mulberrytech.com 
> [mailto:owner-xsl-list@lists.mulberrytech.com] On Behalf Of 
> Jonathan_Wheelhouse@amp.com.au
> Sent: 01 July 2002 09:38
> To: XSL-List@lists.mulberrytech.com
> Subject: [xsl] How to do Control Break?
> 
> 
> 
> 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@amp.com.au'
>             CurrentPhoneNumber='9257 3002' Count='1'/>
>       <z:row FirstName='Adam' Surname='Awad' CompanyName='Compliance'
>             CurrentEmailaddress='adam_awad@amp.com.au' 
> CurrentPhoneNumber
>    ='02 9257 5456'
>             Count='1'/>
>       <z:row FirstName='Adam' Surname='Hutchinson' 
> CurrentCountryName=''
>             CurrentCityName='' CompanyName='AMP' CurrentEmailaddress
>    ='Adam_Hutchinson@amp.com.au'
>             CurrentPhoneNumber='61-2-9257 5427' Count='0'/>
>       <z:row FirstName='Adam' Surname='Hutchinson' 
> CurrentCountryName=''
>             CurrentCityName='' CompanyName='' CurrentEmailaddress
>    ='Adam_Hutchinson@amp.com.au'
>             CurrentPhoneNumber='813-5575-5400' Count='0'/>
>       <z:row FirstName='Adam' Surname='Ryan' CurrentCountryName=''
>             CurrentCityName='' CompanyName='AMPBanking' 
> CurrentEmailaddress
>    ='Adam_Ryan@ampbanking.com.au'
>             CurrentPhoneNumber='0412 00 00 67' Count='1'/>
>       <z:row FirstName='Adam' Surname='Ryan' CurrentCountryName=''
>             CurrentCityName='' CompanyName='NPI' CurrentEmailaddress
>    ='Adam_Ryan@amp.com.au'
>             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@amp.com.au</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@amp.com.au</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@amp.com.au</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@amp.com.au</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@ampbanking.com.au</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@amp.com.au</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
> 


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]