XSLT : hierarchy recursive problem...help

Discussion in 'XML' started by poofpoof, Aug 13, 2004.

  1. poofpoof

    poofpoof Guest

    Dear Experts,

    I have some problems with XSLT recursivity...
    here what I want to do


    XML part :
    ----------

    <struct>
    <node current="1" parent="0" level="1">A</node>
    <node current="2" parent="1" level="2">AB</node>
    <node current="3" parent="2" level="3">ABC</node>
    <node current="4" parent="3" level="4">ABCD/node>
    <node current="5" parent="0" level="1">B</node>
    </struct>



    HTML result :
    -------------
    <div id="A">
    <div id="AB">
    <div id="ABC">
    <div id="ABCD">
    </div>
    </div>
    </div>
    </div>
    <div id="B"></div>

    I just want to imbricate nodes with "level" attributes or "parent" attributes.
    If anyone has samples of url or xsl code ...

    thanks very much
     
    poofpoof, Aug 13, 2004
    #1
    1. Advertising

  2. poofpoof wrote:

    > Dear Experts,
    >
    > I have some problems with XSLT recursivity...
    > here what I want to do
    >
    >
    > XML part :
    > ----------
    >
    > <struct>
    > <node current="1" parent="0" level="1">A</node>
    > <node current="2" parent="1" level="2">AB</node>
    > <node current="3" parent="2" level="3">ABC</node>
    > <node current="4" parent="3" level="4">ABCD/node>
    > <node current="5" parent="0" level="1">B</node>
    > </struct>
    >
    >
    >
    > HTML result :
    > -------------
    > <div id="A">
    > <div id="AB">
    > <div id="ABC">
    > <div id="ABCD">
    > </div>
    > </div>
    > </div>
    > </div>
    > <div id="B"></div>
    >
    > I just want to imbricate nodes with "level" attributes or "parent" attributes.
    > If anyone has samples of url or xsl code ...
    >
    > thanks very much



    try this:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:eek:utput method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/struct">
    <html>
    <body>
    <xsl:apply-templates select="node[@level='1']"/>
    </body>
    </html>
    </xsl:template>
    <xsl:template match="node">
    <xsl:element name="div">
    <xsl:attribute name="id"><xsl:value-of
    select="text()"/></xsl:attribute>
    <xsl:variable name="current" select="@current"/>
    <xsl:apply-templates select="//node[@parent=$current]"/>
    </xsl:element>
    </xsl:template>
    </xsl:stylesheet>


    Peter
     
    Peter Gerstbach, Aug 13, 2004
    #2
    1. Advertising

  3. poofpoof

    poofpoof Guest

    Peter Gerstbach a écrit :
    > poofpoof wrote:
    >
    >> Dear Experts,
    >>
    >> I have some problems with XSLT recursivity... here what I want to do
    >>
    >>
    >> XML part :
    >> ----------
    >>
    >> <struct>
    >> <node current="1" parent="0" level="1">A</node>
    >> <node current="2" parent="1" level="2">AB</node>
    >> <node current="3" parent="2" level="3">ABC</node>
    >> <node current="4" parent="3" level="4">ABCD/node>
    >> <node current="5" parent="0" level="1">B</node>
    >> </struct>
    >>
    >>
    >>
    >> HTML result :
    >> -------------
    >> <div id="A">
    >> <div id="AB">
    >> <div id="ABC">
    >> <div id="ABCD">
    >> </div>
    >> </div>
    >> </div>
    >> </div>
    >> <div id="B"></div>
    >>
    >> I just want to imbricate nodes with "level" attributes or "parent"
    >> attributes.
    >> If anyone has samples of url or xsl code ...
    >> thanks very much

    >
    >
    >
    > try this:
    >
    > <?xml version="1.0" encoding="UTF-8"?>
    > <xsl:stylesheet version="1.0"
    > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    > <xsl:eek:utput method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    > <xsl:template match="/struct">
    > <html>
    > <body>
    > <xsl:apply-templates select="node[@level='1']"/>
    > </body>
    > </html>
    > </xsl:template>
    > <xsl:template match="node">
    > <xsl:element name="div">
    > <xsl:attribute name="id"><xsl:value-of
    > select="text()"/></xsl:attribute>
    > <xsl:variable name="current" select="@current"/>
    > <xsl:apply-templates select="//node[@parent=$current]"/>
    > </xsl:element>
    > </xsl:template>
    > </xsl:stylesheet>
    >
    >
    > Peter



    whaou! that's work!
    I thank you very infinitely Peter! ;)
     
    poofpoof, Aug 13, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John McC
    Replies:
    2
    Views:
    474
    Harald Hein
    Aug 20, 2003
  2. Rolf Kemper

    Create Netlist Hierarchy with XSLT

    Rolf Kemper, Jan 12, 2005, in forum: XML
    Replies:
    1
    Views:
    563
    Joris Gillis
    Jan 15, 2005
  3. Harlan Messinger
    Replies:
    1
    Views:
    384
  4. n00m
    Replies:
    12
    Views:
    1,122
  5. vamsi
    Replies:
    21
    Views:
    2,113
    Keith Thompson
    Mar 9, 2009
Loading...

Share This Page