XSL /XML replication of tree folder structure

R

ragha

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
 
D

Dimitre Novatchev

ragha said:
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
 
R

ragha

Dear Novatchev,

Thank you for your response.

Regards
Ragha

Dimitre Novatchev said:
ragha said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top