You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Robin Green <gr...@hotmail.com> on 2000/09/02 20:36:04 UTC

Re: xsl problem: converting rows to a hierarchy

Steve Conover <sc...@groundswell.net> wrote:
>Another recursion problem:
>
>Given a set of rows
>
><rows>
>	<row>apple</row>
>	<row>orange</row>
>	<row>banana</row>
>	<row>grape</row>
></rows>
>
>I'd like to put them in a hierarchy:
>
><item>
>	apple
>	<item>
>		orange
>		<item>
>			banana
>			<item>
>				grape
>			</item>
>		</item>
>	</item>
></item>
>
>Any suggestions?  I haven't dealt with coding my own recursion in xsl yet 
>so
>it's kinda hard to know where to start.

I haven't tried this but it's probably along the right lines:


<xsl:template match="rows">
  <xsl:apply-templates select="row[position()=1]"/>
</xsl:template>

<xsl:template match="row">
  <item>
    <xsl:value-of select="."/>
    <xsl:apply-templates select="following-siblings::row[position()=1]"/>
  </item>
</xsl:template>


_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

Share information about yourself, create your own public profile at 
http://profiles.msn.com.