473,408 Members | 2,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

XSLT : hierarchy recursive problem...help

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
Jul 20 '05 #1
2 3690
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:output 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
Jul 20 '05 #2
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:output 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! ;)

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Bernd Fuhrmann | last post by:
Hi! I have some trouble with some simple stupid XSLT-stuff. My stylesheet: ------------- <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0"...
5
by: Ruthless | last post by:
hello. All XML and XSLT are processed by preprocessor as a trees. How can i simply display my XML as some kind of tree. given xml: <struct> <node level="1" no="1">
6
by: Ramon M. Felciano | last post by:
Helo all -- I'm trying to gain a deeper understand for what type of semi-declarative programming can be done through XML and XPath/XSLT. I'm looking at graph processing problems as a testbed for...
1
by: Rolf Kemper | last post by:
Dear All, may be some one has a good idea for the follwoing problem. In the xml data below you see a kind of abstract netlist as we use it for chip design. Where the H tag stands for a logical...
3
by: Ian Roddis | last post by:
Hello, I want to embed SQL type queries within an XML data record. The XML looks something like this: <DISPLAYPAGE> <FIELD NAME="SERVER" TYPE="DROPDOWN"> <OPTION>1<OPTION> <OPTION>2<OPTION>...
6
by: Neal | last post by:
Hi All, I used an article on XSLT and XML and creating a TOC written on the MSDN CodeCorner. ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/dncodecorn/html/corner042699.htm However, it did'nt...
3
by: thomas.porschberg | last post by:
Hi, I want to read records from a database and export it in an arbitrary format. My idea was to feed a class with a String array fetched from the database and let this class fire SAX events as...
0
by: pr33tz | last post by:
Hi all, I have the following XSL file: <xsl:template match="/"> <HTML> <BODY> <font face="Arial" size="4">Purchase Order Details</font> <xsl:apply-templates />
11
by: Simon Woods | last post by:
Hi I have this recursive function and I want to walk the inheritance hierarchy to set field values .... the generic T is constrainted as the base class of the inheritance hierarchy Friend...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.