RE: [xsl] Grouping of Tags

Subject: RE: [xsl] Grouping of Tags
From: Américo Albuquerque <melinor@xxxxxxx>
Date: Sat, 21 Jun 2003 11:38:28 +0100
Hi.

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Marc Baumgartner
> Sent: Friday, June 20, 2003 12:53 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Grouping of Tags
> 
> 
> Hello Everybody,
> 
> I have got a little problem with my Stylesheet.
> In my XML I have two types of tags. My result should be a 
> table where I want 
> for every block of the first tag a new row which contains all 
> the following 
> second tags.
> 
(...)
> Is this possbile with xsl? I haved tried this for several 

Sure. Try this:

<xsl:template match="root">
 <table>
  <!-- select all <first> that starts a new group, i.e., that doesn't have a
preceding-sibling or that the nearst preceding-sibling is a <second> -->
  <xsl:apply-templates select="first[not(preceding-sibling::*) or
preceding-sibling::*[1][self::second]]"/>
 </table>
</xsl:template>

<xsl:template match="first">
 <tr>
  <td><xsl:copy-of select="."/></td>
  <!-- first apply to the next consecutive <first> whose
following-sibling::second is the some of the current node  -->
  <xsl:apply-templates mode="next"
select="following-sibling::first[generate-id(following-sibling::second)=gene
rate-id(current()/following-sibling::second)]"/>
  <!-- then apply to the next consecutive <second> whose
following-sibling::first is the same of the first following-sibling::second
-->
  <xsl:apply-templates mode="next"
select="following-sibling::second[generate-id(following-sibling::first)=gene
rate-id(current()/following-sibling::second[1]/following-sibling::first)]"/>
 </tr>
</xsl:template>

<xsl:template match="first | second" mode="next">
 <td><xsl:copy-of select="."/></td>
</xsl:template>

Hope this helps you.



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


Current Thread