This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

FW: Recursion over a tree


Hi,
I've been messing around in the magical world of XSL recently, and I'm a bit
new, so bear with me.
One thing I need to do is loop over a structure, which can contain any
number of nodes, and any number of levels. The names of the nodes can be
different (very important), so my script needs to be modular.

Take the following structure (purely an example):

<object>
<object>
<object></object>
</object>
<object>
<object>
<object></object>
</object>
</object>
</object>

I need to create a tree type structure based on the above structure:
object
   object
object
   object
      object

So... how? I've got the following code, which is meant to be
recursive. It is a bit hack... I'm missing something here.

<xsl:template match="\">
<xsl:call-template name="recursive-child">
<xsl:with-param name="thisPath"
select="following-sibling::*"/>
</xsl:call-template>
</xsl:template>

<xsl:template name="recursive-child">
<xsl:for-each select="thisPath">
<div align="" style="padding-left:
10px;">
<!-- iterate over children -->
<xsl:value-of select="name
()"/>
</div>
<xsl:call-template name="recursive-
child">
<xsl:with-param
name="thisPath" select="following-sibling::*"/>
</xsl:call-template>
</xsl:for-each>
</xsl:template>


Anyway. Any help would be appreaciated!

Geoff B



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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]