Subject: Re: [xsl] FW: Recursion over a tree From: "Joerg Heinicke" <joerg.heinicke@xxxxxx> Date: Wed, 10 Apr 2002 22:36:05 +0200 |
Hello Geoff, it's much easier you think. You only must process the nodes in document order and for each ancestor a node has you must add a indent string: <xsl:template match="*"> <xsl:for-each select="ancestor::*"> <xsl:text> </xsl:text> </xsl:for-each> <xsl:value-of select="name()"/> <xsl:text> </xsl:text> <xsl:apply-templates select="*"/> </xsl:template> Or in HTML: <xsl:template match="*"> <div style="padding-left: 10px;"> <xsl:value-of select="name()"/> <xsl:apply-templates select="*"/> </div> </xsl:template> Regards, Joerg > 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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] FW: Recursion over a tree, geoffb | Thread | [xsl] SVG Manipulation Problems con, Jeremy E. Denton |
[xsl] FW: Recursion over a tree, geoffb | Date | Business logic (was: Re: [xsl] Effi, J.Pietschmann |
Month |