[xsl] Summarizing sibling nodes

Subject: [xsl] Summarizing sibling nodes
From: Wayne Rambo <WRambo@xxxxxxxxxx>
Date: Wed, 14 Mar 2001 11:42:10 -0800
I'm rather new to XSL (Few months) and am running across a little problem,
hoping someone here can help me. Thanks for your time.

I have the following XML. . .

<Truck-list>
    <Truck>
      <VINModelName>
        T600
      </VINModelName>
      <VINModelYearName>
        1999
      </VINModelYearName>
    </Truck>
    <Truck>
      <VINModelName>
        T100
      </VINModelName>
      <VINModelYearName>
        1999
      </VINModelYearName>
    </Truck>
   <Truck>
      <VINModelName>
        T600
      </VINModelName>
      <VINModelYearName>
        2000
      </VINModelYearName>
    </Truck>
   <Truck>
      <VINModelName>
        T600
      </VINModelName>
      <VINModelYearName>
        1999
      </VINModelYearName>
    </Truck>
</Truck-list>

What I am trying to accomplish is a summary of the truck somewhat like this
(Except in HTML and prettier):

Build Year: 1999
Model: T100
Count: 1

Build Year: 1999
Model: T600
Count: 2

Build Year: 2000
Model: T100
Count: 1

Build Year: 2000
Model: T600
Count: 1

The XSL chunk I have currently is as follows (I think this is the closest
I've been, but I've tried lots of things here):

<xsl:template match="Truck-list">
   [HTML table build]
     <xsl:for-each
select="Truck[not(VINModelYearName/preceding::Truck/VINModelYearName)]
             |Truck[not(VINModelName/preceding::Truck/VINModelName)]">
	   <tr>
		  <td class="lensBody" bgcolor="#FFFFFF" nowrap="true">	  
	          <xsl:value-of select="VINModelYearName"/>&#160; 
		  </td>
		  <td class="lensBody" bgcolor="#FFFFFF" nowrap="true">	  
	          <xsl:value-of select="VINModelName"/>&#160;
		  </td>
              <td class="lensBody" bgcolor="#FFFFFF" nowrap="true">	  
	          <xsl:value-of select="count(VINModelName)"/>&#160;
		  </td>
         </tr>
     </xsl:for-each>  
   </table>
</xsl:template>

I know the count part is wrong. I think I would put whatever pattern I use
in my for-each in my count to return the same set of results to count. I'm
not sure though, because basically what I'm trying to do is create nodes on
the fly matching a particular pattern. The pattern can change, because I
want it for all the years, and for any Model (Which I could make a list of,
but it would be quite long).

Again, thank you for your time.

wtr.

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


Current Thread