XSL /XML replication of tree folder structure

Discussion in 'XML' started by ragha, Nov 23, 2003.

  1. ragha

    ragha Guest

    Dear friends

    I am emulating thr tree structure mentioned in the article
    http://www.15seconds.com/issue/010921.htm

    I have succesfully created the folder structure for level 2 I need
    this structure till 5 level is there any easier way to generate this
    using xsl

    My xml tree node is

    <tree>
    <entity>
    <description>Level 0</description>
    <contents>
    <entity>
    <description>Level 1</description>
    <contents>
    <entity>Level 2</entity>
    <contents>
    <entity>Level 3</entity>

    </contents>
    </contents>
    </entity>
    ..........

    </contents>
    </entity>
    </tree>

    xsl code which used to generate


    <!-- First xsl for each start -->

    <xsl:for-each select="tree/entity">
    <table border="0" cellpadding="1" cellspacing="1">
    <tr>
    <td width="16">
    <a id="x{./description}"
    href="javascript:Toggle('{./description}');">
    <img src="../images/closedfolder.gif" width="16" height="16"
    hspace="0" vspace="0" border="0"/>
    </a>
    </td>
    <td>
    <a id="x{./description}"
    href="javascript:Toggle('{./description}');">
    <b><xsl:value-of select="./description"/></b>
    </a>
    </td>
    </tr>
    </table>
    <DIV id="{./description}" style="display: none; margin-left: 2em;">
    <!-- Second xsl for each start-->
    <xsl:for-each select="./contents/entity">
    <table border="0" cellpadding="1" cellspacing="1">
    <tr>
    <td width="16">
    <a id="x{./description}"
    href="javascript:Toggle('{./description}');">
    <img src="../images/openfolder.gif" width="16" height="16"
    hspace="0" vspace="0" border="0"/>
    </a>
    </td>
    <td>
    <a id="x{./description}"
    href="javascript:Toggle('{./description}');">
    <b>
    <xsl:value-of select="./description"/>
    </b>
    </a>
    </td>
    </tr>
    </table>
    <DIV id="{./description}" style="display: none; margin-left: 2em;">
    <!-- Third xsl for each start -->
    <xsl:for-each select="./contents/entity">
    <table border="0" cellpadding="1" cellspacing="1">
    <xsl:choose>
    <xsl:when test="string-length(./contents/entity)&lt;5">
    <tr>
    <td width="16">

    <DIV id="x{./Programmeid}" style="display:hidden;">
    <img src="../images/doc.gif" width="16" height="16" hspace="0"
    vspace="0" border="0"/>
    </DIV>

    </td>
    <td>

    <b>
    <xsl:value-of select="./description"/>
    </b>

    </td>
    </tr>
    </xsl:when>
    <xsl:eek:therwise>
    <tr>
    <td width="16">
    <a id="x{./description}"
    href="javascript:Toggle('{./description}');">
    <img src="../images/openfolder.gif" width="16" height="16"
    hspace="0" vspace="0" border="0"/>
    </a>
    </td>
    <td>
    <a id="x{./description}"
    href="javascript:Toggle('{./description}');">
    <b>
    <xsl:value-of select="./description"/>
    </b>
    </a>
    </td>
    </tr>
    </xsl:eek:therwise>
    </xsl:choose>
    </table>

    <xsl:if test="string-length(./contents/entity)&gt;5">
    <DIV id="{./description}" style="display: none; margin-left: 2em;">
    <xsl:for-each select="./contents/entity">
    <table border="0" cellpadding="1" cellspacing="1">
    <tr>
    <td width="16">

    <DIV id="x{./Programmeid}" style="display:hidden;">
    <img src="../images/doc.gif" width="16" height="16" hspace="0"
    vspace="0" border="0"/>
    </DIV>

    </td>
    <td>
    <b>
    <xsl:value-of select="./description"/>
    </b>

    </td>
    </tr>
    </table>
    </xsl:for-each>
    </DIV>
    </xsl:if>
    </xsl:for-each>
    </DIV>
    </xsl:for-each>
    </DIV>
    </xsl:for-each>

    If any one has easier approach to generate the tree structure kindly
    suggest.

    Regards
    Raghavendra K
    ragha, Nov 23, 2003
    #1
    1. Advertising

  2. "ragha" <> wrote in message
    news:...
    > Dear friends
    >
    > I am emulating thr tree structure mentioned in the article
    > http://www.15seconds.com/issue/010921.htm
    >
    > I have succesfully created the folder structure for level 2 I need
    > this structure till 5 level is there any easier way to generate this
    > using xsl
    >
    > My xml tree node is

    [snipped]
    >
    > xsl code which used to generate


    [snipped]

    >
    > If any one has easier approach to generate the tree structure kindly
    > suggest.


    Yes.

    Read about xsl:template and xsl:apply-templates.

    In your code you need to have a single xsl:template matching "entity". No
    need of using xsl:for-each or repeating the same code fixed number of times.


    =====
    Cheers,

    Dimitre Novatchev.
    http://fxsl.sourceforge.net/ -- the home of FXSL
    Dimitre Novatchev, Nov 23, 2003
    #2
    1. Advertising

  3. ragha

    ragha Guest

    Dear Novatchev,

    Thank you for your response.

    Regards
    Ragha

    "Dimitre Novatchev" <> wrote in message news:<bpquir$1rabv1$-berlin.de>...
    > "ragha" <> wrote in message
    > news:...
    > > Dear friends
    > >
    > > I am emulating thr tree structure mentioned in the article
    > > http://www.15seconds.com/issue/010921.htm
    > >
    > > I have succesfully created the folder structure for level 2 I need
    > > this structure till 5 level is there any easier way to generate this
    > > using xsl
    > >
    > > My xml tree node is

    > [snipped]
    > >
    > > xsl code which used to generate

    >
    > [snipped]
    >
    > >
    > > If any one has easier approach to generate the tree structure kindly
    > > suggest.

    >
    > Yes.
    >
    > Read about xsl:template and xsl:apply-templates.
    >
    > In your code you need to have a single xsl:template matching "entity". No
    > need of using xsl:for-each or repeating the same code fixed number of times.
    >
    >
    > =====
    > Cheers,
    >
    > Dimitre Novatchev.
    > http://fxsl.sourceforge.net/ -- the home of FXSL
    ragha, Nov 24, 2003
    #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. Stub

    B tree, B+ tree and B* tree

    Stub, Nov 12, 2003, in forum: C Programming
    Replies:
    3
    Views:
    10,090
  2. sharan
    Replies:
    4
    Views:
    674
    CBFalconer
    Oct 30, 2007
  3. sharan
    Replies:
    2
    Views:
    819
    SM Ryan
    Oct 31, 2007
  4. sharan
    Replies:
    1
    Views:
    677
    CBFalconer
    Oct 30, 2007
  5. anne001
    Replies:
    1
    Views:
    227
Loading...

Share This Page