[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: FW: Recursion over a tree

Subject: Re: FW: Recursion over a tree
From: "Joerg Heinicke" <joerg.heinicke@xxxxxx>
Date: Wed, 10 Apr 2002 22:36:05 +0200
recursive select tree
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>&#10;</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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.