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

Re: n-nodes recursive tree

Subject: Re: n-nodes recursive tree
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Fri, 28 Nov 2003 22:33:01 +0100
xsl recursive tree
> >There isn't any indentation in the presented output.
>
> There is, though it seems to contain a mix of tabs and spaces.
> I saw this (with tabs converted to 8 spaces):
>
> ==========
> In effect, i will never know the max number of levels in tree node, and so
i'd
> like to obtain an html file formated with xsl and wich looks like that:
>
> Tree
>      ---- 1
>              ---- 4
>              ---- 5
>                      ---- 7
>      ---- 2
>              ---- 6
>      ---- 3
> ==========


OK, then the solution is rather straightforward:

This transformation:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

 <xsl:output method="text"/>
 <xsl:strip-space elements="*"/>

  <xsl:template match="/*">
     <xsl:apply-templates select="node">
       <xsl:with-param name="pstrIndent" select="'&#xA;'"/>
     </xsl:apply-templates>
  </xsl:template>

  <xsl:template match="node">
    <xsl:param name="pstrIndent"/>

    <xsl:variable name="vthisIndent"
         select="concat($pstrIndent, '&#09;')"/>

    <xsl:value-of select="concat($vthisIndent, '----', id)"/>

    <xsl:apply-templates select="node">
      <xsl:with-param name="pstrIndent" select="$vthisIndent"/>
    </xsl:apply-templates>
  </xsl:template>

</xsl:stylesheet>

when applied on the provided source.xml:

<tree>
  <node>
    <id> 1</id>
    <parent> root</parent>
    <node>
      <id> 4</id>
      <parent> 1</parent>
    </node>
    <node>
      <id> 5</id>
      <parent> 1</parent>
      <node>
        <id> 7</id>
        <parent> 5</parent>
      </node>
    </node>
  </node>
  <node>
    <id> 2</id>
    <parent> root</parent>
    <node>
      <id> 6</id>
      <parent> 2</parent>
    </node>
  </node>
  <node>
    <id> 3</id>
    <parent> root</parent>
  </node>
</tree>

produces the wanted result:


 ---- 1
  ---- 4
  ---- 5
   ---- 7
 ---- 2
  ---- 6
 ---- 3


Hope this helped.



=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL




 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.