473,588 Members | 2,549 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3702
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:styleshe et 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:attribut e name="id"><xsl: value-of
select="text()"/></xsl:attribute>
<xsl:variable name="current" select="@curren t"/>
<xsl:apply-templates select="//node[@parent=$curren t]"/>
</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:styleshe et 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:attribut e name="id"><xsl: value-of
select="text()"/></xsl:attribute>
<xsl:variable name="current" select="@curren t"/>
<xsl:apply-templates select="//node[@parent=$curren t]"/>
</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
6759
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" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5
2224
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
2902
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 this, and came across a problem that I haven't been able to solve elegantly. The problem is to find "linker" vertexes that a pair of verteces from a pre-defined set. For example, if the graph verteces represent cities and edges represent flights...
1
1439
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 hierarchy level, the M tag for a physical macro and the p tag for a pin of the macro which has to be bound to a Net ( named by @Net). The existing netlist is described without the Hierarchy. Hence, I must know which nets I have to pass trough...
3
3079
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> <OPTION>3<OPTION> </FIELD>
6
1813
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 quite answer all my questions. How would one create a 3 level TOC when each item level / node was differently named (They used Template match and for-each, but the template match worked as on a 3 level structure they usedf the same named xml...
3
1999
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 processor input. The basic class hierarchy is:
0
1162
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
1389
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 Shared Function InjectFieldValues(ByVal p_def As T, ByVal p_properties As PropertyMaps) As T
0
7929
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
7984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8223
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6634
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5726
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5398
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3847
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2371
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1458
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.