XSLT : hierarchy recursive problem...help

P

poofpoof

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
 
P

Peter Gerstbach

poofpoof said:
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
 
P

poofpoof

Peter Gerstbach a écrit :
poofpoof said:
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! ;)
 

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,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top