RE: [xsl] Generate-id() issue, well maybe?

Subject: RE: [xsl] Generate-id() issue, well maybe?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 19 Aug 2005 08:51:22 +0100
> (XSL NEWBIE)
> Th following produces the desired output asthetically, but the data is
> coming out pretty skewed.
> Test file has (3) User Data Activty Elements
> (1) The first stance of the User Element Prints the User name but no
> data is output to the table.
> (2) The second instance of the User Element creates the desired output
> (for the most part)
> (3) The third instance creates the correct MDBService rows, but the
> count is not correct (sometimes double)


You've only shown us one of the User elements. The others must be different
in some way if they are coming out differently, but we can only guess at
how. You also haven't shown us the key definitions, or the namespace
declarations.

I have a suspicion that the problem is because you are assuming that the
key() function is operating locally to the current User, when in fact it is
operating across the whole document.

One suggestion: use CSS for the styling. Generate HTML elements that refer
to a CSS class, and then adjust the appearance using the CSS class
definitions. If you can't do that, at least get rid of all the styling
clutter to produce a cut-down stylesheet that illustrates your coding
problem. Sometimes when you cut it down to the bare bones, the error stares
at you in the face.

Michael Kay
http://www.saxonica.com/


> 
> What below is creating this erratic behaviour?
> 
> 
>                  <xsl:for-each select="n1:User">
>                         <br />
>                         <xsl:for-each select="n1:Name">
>                             <span style="font-family:Arial;
> font-weight:bold; ">
>                                 <xsl:apply-templates />
>                             </span>
>                         </xsl:for-each>
>                         <table border="1"
> style="border-collapse:collapse ; width: 678px; " cellpadding="1" >
>                             <thead>
>                                 <tr bgcolor="C5D8FF"
> style="font-family:Arial; font-weight:bold">
>                                     <td align="left" width="556">MDB
> SERVICE</td>
>                                     <td align="center"
> width="61">MCAP</td>
>                                     <td align="center"
> width="61">HSS</td>
>                                 </tr>
>                             </thead>
>                             <tbody style="font-family:Arial;">
>                                 <xsl:for-each
> select="n1:Activity[generate-id(.) =
> generate-id(key('service',n1:MDBService)[1] )]">
>                          <xsl:variable name="temp_1"
> select="n1:MDBService"/>
>                                     <tr>
>                                         <td align="left">
>                                             <xsl:value-of
> select="$temp_1" />
>                                         </td>
>                                         <td align="center" 
> width="61" >
>                          <xsl:value-of
> select="count(key('service',$temp_1)[n1:MDBDivision ='MCAP'])"/>
>                          </td>
>                                         <td align="center" 
> width="61" >
>                          <xsl:value-of
> select="count(key('service',$temp_1)[n1:MDBDivision ='HSS'])"/>
>                          </td>
>                                     </tr>
>                                 </xsl:for-each>
>                             </tbody>
>                          <tfoot>
>                          <tr style=" font-family:Arial; 
> font-size:smaller ;
> align:center;">
>                          <td height="15" colspan="3" align="center">
>                          MCAP = Medical Capital Intelligence Products
> HSS = Healthcare Systems and Software Products
>                          </td>
>                          </tr>
>              </tfoot>
>                         </table>
>                     </xsl:for-each>
> 
> 
> Example User Element
> 
> <User ID="111911">
>              <Name>Robert Gerick</Name>
>              <Activity>
>                          <MDBService>Intelligence Rep: 
> Full</MDBService>
>                          <Description>Computerized Patient
> Record</Description>
>                          <SendDate>2/18/2002</SendDate>
>                          <MDBDivision>HSS</MDBDivision>
>              </Activity>
>              <Activity>
>                          <MDBService>Intelligence Rep: 
> Fast</MDBService>
>                          <Description>Picture Archive and 
> Communication
> Systems -
> PACS</Description>
>                          <SendDate>2/18/2002</SendDate>
>                          <MDBDivision>MCAP</MDBDivision>
>              </Activity>
>              <Activity>
>                          <MDBService>Price Analysis</MDBService>
>                          <Description>Picture Archive and 
> Communication
> Systems -
> PACS</Description>
>                          <SendDate>2/18/2002</SendDate>
>                          <MDBDivision>HSS</MDBDivision>
>              </Activity>
>              <Activity>
>                          <MDBService>Intelligence Rep: 
> Full</MDBService>
>                          <Description>Ambulatory Care 
> System</Description>
>                          <SendDate>2/18/2002</SendDate>
>                          <MDBDivision>MCAP</MDBDivision>
>              </Activity>
>              <Activity>
> </User>
> 
> _________________________________________________________________
> 
> This message is for the designated recipient only and may contain
> privileged, proprietary, or otherwise private information. If you
> have received it in error, please notify the sender immediately
> and delete the original. Any other use of the email by you is
> prohibited.
> _________________________________________________________________
> 
> 
> 
> 
> 
> This e-Mail may contain proprietary and confidential 
> information and is sent for the intended recipient(s) only. 
> If by an addressing or transmission error this mail has been 
> misdirected to you, you are requested to delete this mail immediately.
> You are also hereby notified that any use, any form of 
> reproduction, dissemination, copying, disclosure, modification,
> distribution and/or publication of this e-mail message, 
> contents or its attachment other than by its intended 
> recipient/s is strictly prohibited.
> 
> Visit Us at http://www.polaris.co.in

Current Thread