RE: [xsl] recursive template call, howto

Subject: RE: [xsl] recursive template call, howto
From: cknell@xxxxxxxxxx
Date: Tue, 22 Aug 2006 00:03:00 -0400
Taking the liberty of assuming a document root named "root-element" (just substitute whatever is the case in your document), this will do what you asked. "Look Ma! No recursion!" (Pardon an American old enough to remember 1950's TV ads.)

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="";>

	<xsl:template match="/">
		<xsl:apply-templates />
<xsl:template match="root-element">
    			<xsl:apply-templates select="group[not(@type)]" />
    		<xsl:apply-templates select="group[@type]" />
  <xsl:template match="group[not(@type)]">
    <xsl:apply-templates />

  <xsl:template match="group[@type]">
    	<xsl:apply-templates />
  <xsl:template match="line">
    <tr><td><xsl:value-of select="@id" /></td></tr>

Charles Knell
cknell@xxxxxxxxxx - email

-----Original Message-----
From:     Sam Carleton <scarleton@xxxxxxxxxxxxxxxx>
Sent:     Mon, 21 Aug 2006 22:13:53 -0400
To:       xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  [xsl] recursive template call, howto

Here is the data:

  <line id = "1"/>
  <line id="2"/>
<group type="complex">
  <line id="3"/>
  <line id="4"/>
  <line id="5"/>
  <line id="6"/>
  <line id="7"/>
  <line id="8"/>

The idea behind the data is that there are two types of groups: simple
and complex.  The simple do not have a "type" attribute (it could if it
would help things).  The end result should be HTML where the first two
simple groups are in one HTML table, than there is a second table for
each of the complex groups and thing a final table for the last three
simple groups.  The order of simple and complex groups is random.

My thought was when the first simple group was encountered, call a
recursive template starting at the simple group and building a nodeset
of lines until a complex group or the end was encountered.  I cannot
figure out how to do that in xsl.  Am I on the right path? If so, how
do I do it?  If not, what is the right path?


Current Thread