473,799 Members | 3,033 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Recursive nested elements woe

Hi every-one,

(Deleted and reposted to avoid sp@m)

I have an XML file that looks like this:

_______________ ______________X ML_____________ _______________ _____

<root>
<nextlevel>
<init>
<element1>
Content
</element1>
<element2>
More content
</element2>
...etc
<message>
<element1>
Content
</element1>
<element2>
More content
</element2>
...etc
<message>
<element1>
Content
</element1>
<element2>
More content
</element2>
...etc
</message>
</message>
</init>
</nextlevel>
</root>

_______________ _______________ _______________ _______________ _____

The <message> nodes may well contain other <message> nodes which could
contain other <message> nodes etc. etc. ad infinitum(well, almost!)

My problem is that when it comes to the XSL, I want to nest these nodes
and indent them and this is what I have so far:

_______________ ______________X SL_____________ _______________ _____
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

<xsl:template match="init">
<xsl:value-of select="element 1"/>
<xsl:value-of select="element 2"/><br />
</xsl:template>

<xsl:template name ="message" match="message" >
<blockquote>
<xsl:value-of select="element 1"/>
<xsl:value-of select="element 2"/>
<xsl:for-each select="message[count(descendan t::message)!='0 ']">
<xsl:call-template name="message"/>
</xsl:for-each>
</blockquote>
</xsl:template>

_______________ _______________ _______________ _______________ _____

However, this only nests up to and including the second <message> node
and no further. Any help appreciated :)

Tom.
Jul 20 '05 #1
3 1707
Cat
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thu, 24 Jun 2004 17:42:08 +0100, GR33DY wrote:
_______________ ______________X SL_____________ _______________ _____
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

<xsl:template match="init">
<xsl:value-of select="element 1"/>
<xsl:value-of select="element 2"/><br />
</xsl:template>

<xsl:template name ="message" match="message" >
<blockquote>
<xsl:value-of select="element 1"/>
<xsl:value-of select="element 2"/>
<xsl:for-each select="message[count(descendan t::message)!='0 ']">
<xsl:call-template name="message"/>
</xsl:for-each>
</blockquote>
</xsl:template>

_______________ _______________ _______________ _______________ _____

Tom,
Wouldn't it be better/simplier to do the recursion with the normal
xsl:apply-templates like so.

============= XSLT =============== =
<?xml version="1.0"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">

<xsl:template match="root">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

<xsl:template match="init|nex tlevel">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="element1 |element2">
<xsl:value-of select="."/>
</xsl:template>

<xsl:template match="message" >
<blockquote>
<xsl:apply-templates/>
</blockquote>
</xsl:template>
</xsl:stylesheet>
=============== =============== =====
Is this what you were looking for?
- --
Cat

http://www.ratrobot.com/writing/tiger/ TradeMark Tiger is an economic
argument for conservation. Why not use nature to save itself?
Fri Jun 25 21:55:01 UTC 2004
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD4DBQFA3J81KHR jYtwQ1QARApozAJ ipLbIw+zFzA5t+B iSYym9dBYYrAKCx dHlc
u12mBgs54ZzHz18 we4IPzA==
=xh+N
-----END PGP SIGNATURE-----

Jul 20 '05 #2
Cat wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thu, 24 Jun 2004 17:42:08 +0100, GR33DY wrote:
_____________ _______________ _XSL___________ _______________ _______
<xsl:templa te match="/">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

<xsl:templa te match="init">
<xsl:value-of select="element 1"/>
<xsl:value-of select="element 2"/><br />
</xsl:template>

<xsl:templa te name ="message" match="message" >
<blockquote >
<xsl:value-of select="element 1"/>
<xsl:value-of select="element 2"/>
<xsl:for-each select="message[count(descendan t::message)!='0 ']">
<xsl:call-template name="message"/>
</xsl:for-each>
</blockquote>
</xsl:template>

_____________ _______________ _______________ _______________ _______


Tom,
Wouldn't it be better/simplier to do the recursion with the normal
xsl:apply-templates like so.

============= XSLT =============== =
<?xml version="1.0"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">

<xsl:template match="root">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

<xsl:template match="init|nex tlevel">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="element1 |element2">
<xsl:value-of select="."/>
</xsl:template>

<xsl:template match="message" >
<blockquote>
<xsl:apply-templates/>
</blockquote>
</xsl:template>
</xsl:stylesheet>
=============== =============== =====
Is this what you were looking for?
- --
Cat

http://www.ratrobot.com/writing/tiger/ TradeMark Tiger is an economic
argument for conservation. Why not use nature to save itself?
Fri Jun 25 21:55:01 UTC 2004
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD4DBQFA3J81KHR jYtwQ1QARApozAJ ipLbIw+zFzA5t+B iSYym9dBYYrAKCx dHlc
u12mBgs54ZzHz18 we4IPzA==
=xh+N
-----END PGP SIGNATURE-----

That's nice and simple!
My solutions tend to get more and more complicated :)
How would I now go about adding some formatting to the element1 &
element2 content?

Thanks for your help, it's very much appreciated.
Jul 20 '05 #3
Cat wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thu, 24 Jun 2004 17:42:08 +0100, GR33DY wrote:
_____________ _______________ _XSL___________ _______________ _______
<xsl:templa te match="/">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

<xsl:templa te match="init">
<xsl:value-of select="element 1"/>
<xsl:value-of select="element 2"/><br />
</xsl:template>

<xsl:templa te name ="message" match="message" >
<blockquote >
<xsl:value-of select="element 1"/>
<xsl:value-of select="element 2"/>
<xsl:for-each select="message[count(descendan t::message)!='0 ']">
<xsl:call-template name="message"/>
</xsl:for-each>
</blockquote>
</xsl:template>

_____________ _______________ _______________ _______________ _______


Tom,
Wouldn't it be better/simplier to do the recursion with the normal
xsl:apply-templates like so.

============= XSLT =============== =
<?xml version="1.0"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">

<xsl:template match="root">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

<xsl:template match="init|nex tlevel">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="element1 |element2">
<xsl:value-of select="."/>
</xsl:template>

<xsl:template match="message" >
<blockquote>
<xsl:apply-templates/>
</blockquote>
</xsl:template>
</xsl:stylesheet>
=============== =============== =====
Is this what you were looking for?
- --
Cat

http://www.ratrobot.com/writing/tiger/ TradeMark Tiger is an economic
argument for conservation. Why not use nature to save itself?
Fri Jun 25 21:55:01 UTC 2004
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD4DBQFA3J81KHR jYtwQ1QARApozAJ ipLbIw+zFzA5t+B iSYym9dBYYrAKCx dHlc
u12mBgs54ZzHz18 we4IPzA==
=xh+N
-----END PGP SIGNATURE-----

That's lovely and simple, my efforts get recursively more complicated ;)
Thanks for your help.
Tom
Jul 20 '05 #4

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

Similar topics

19
2297
by: Carlos Ribeiro | last post by:
Hello all, Here I am using some deeply nested, tree-like data structures. In some situations I need to traverse the tree; the old-style way to do it is to write a recursive method on the node class, as in: def walk(self): """old-style recursive tree traversal""" child.do_something for child in childs:
2
4271
by: rankam | last post by:
Hi There, We have a requirement for recursive elements within a XML document? Is it possible to design it through XML Schema? And what are implications using recursive elements when using DOM Parser in Java? Any samples demonstrating this concept in XSD is helpful? I need a XML structure something like this below : <forms>
2
5301
by: LoserInYourFaceEngineer | last post by:
Hello All: I'm having trouble with a recursive function. The function is supposed to identify nested folders in a hierarchical folder structure. The function "searchForFolders()" is supposed to traverse sibling nodes in each iteration, and for each sibling node, it calls itself again, to see if there are child nodes of the current sibling.
6
1670
by: Phil | last post by:
Hello I'm trying to display all DIV tags of a document : Example : + <DIV id="1"> - <DIV id="1-1"></DIV> </DIV> + <DIV id="2"> - <DIV id="2-1"></DIV>
4
9271
by: Rodusa | last post by:
I am having problem to apply updates into this function below. I tried using cursor for updates, etc. but no success. Sql server keeps telling me that I cannot execute insert or update from inside a function and it gives me an option that I could write an extended stored procedure, but I don't have a clue of how to do it. To quickly fix the problem the only solution left in my case is to convert this recursive function into one recursive...
25
2832
by: Mike MacSween | last post by:
Regular viewers may want to turn off now. This will be an orchestral management system. Musicians and other staff being booked/paid for jobs. A job may contain other jobs, e.g: World Tour contains US leg and Europe leg (and others) US leg contains State tours (and others)
2
7597
by: alexandre_irrthum | last post by:
Hello, I'd like to apply a function to elements of a nested list and wondered if there is anything more idiomatic and/or shorter than this recursive way: >>> def recur_map(f, data): .... if isinstance(data, list): .... mapped_list = .... for i in data:
2
11268
by: Gentr1 | last post by:
Hi everybody! I am presently working on a Genetic Programming API in python. I have a bit of a problem at the moment... For some specific reasons, I am using nested lists data structure to represent a tree. The first element of a list is always the head of the node, while all others represent the tail of the node. e.g. the nested list , E], ] represent the following tree: http://www.csd.abdn.ac.uk/~mkhoury/tree.jpg I need to be able...
10
7177
beacon
by: beacon | last post by:
Hi everybody, This is probably going to sound unorthodox, but I have to log records that are deleted...I know, go figure. Anyway, I have a form with a (continuous) subform, and on the subform I have a command button, called cmdDelete, that launches a dialog form, called frmDeleteCurrentRecord, where the user has to enter their name and a reason. I have managed, through a ton of trial and tribulation, found a way to delete the current...
31
6687
by: matthewslyman | last post by:
I have an unusual design and some very unusual issues with my code... I have forced Access to cooperate on everything except one issue - record deletion. My form design involves a recursively nested form. In other words, the form, m_settings_menueditor_recursive has a single subform; m_settings_menueditor_recursive (both are viewed as datasheets - so the form is its own subdatasheet.) The Form_Open event modifies the form's recordset so...
0
10490
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10259
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10238
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
10030
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
9077
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...
0
5467
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...
0
5589
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4145
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
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.