473,401 Members | 2,146 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,401 software developers and data experts.

Recursive nested elements woe

Hi every-one,

(Deleted and reposted to avoid sp@m)

I have an XML file that looks like this:

_____________________________XML__________________ _______________

<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:

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

<xsl:template match="init">
<xsl:value-of select="element1"/>
<xsl:value-of select="element2"/><br />
</xsl:template>

<xsl:template name ="message" match="message">
<blockquote>
<xsl:value-of select="element1"/>
<xsl:value-of select="element2"/>
<xsl:for-each select="message[count(descendant::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 1691
Cat
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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

<xsl:template match="init">
<xsl:value-of select="element1"/>
<xsl:value-of select="element2"/><br />
</xsl:template>

<xsl:template name ="message" match="message">
<blockquote>
<xsl:value-of select="element1"/>
<xsl:value-of select="element2"/>
<xsl:for-each select="message[count(descendant::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:stylesheet 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|nextlevel">
<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)

iD4DBQFA3J81KHRjYtwQ1QARApozAJipLbIw+zFzA5t+BiSYym 9dBYYrAKCxdHlc
u12mBgs54ZzHz18we4IPzA==
=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:template match="/">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

<xsl:template match="init">
<xsl:value-of select="element1"/>
<xsl:value-of select="element2"/><br />
</xsl:template>

<xsl:template name ="message" match="message">
<blockquote>
<xsl:value-of select="element1"/>
<xsl:value-of select="element2"/>
<xsl:for-each select="message[count(descendant::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:stylesheet 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|nextlevel">
<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)

iD4DBQFA3J81KHRjYtwQ1QARApozAJipLbIw+zFzA5t+BiSYym 9dBYYrAKCxdHlc
u12mBgs54ZzHz18we4IPzA==
=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:template match="/">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

<xsl:template match="init">
<xsl:value-of select="element1"/>
<xsl:value-of select="element2"/><br />
</xsl:template>

<xsl:template name ="message" match="message">
<blockquote>
<xsl:value-of select="element1"/>
<xsl:value-of select="element2"/>
<xsl:for-each select="message[count(descendant::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:stylesheet 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|nextlevel">
<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)

iD4DBQFA3J81KHRjYtwQ1QARApozAJipLbIw+zFzA5t+BiSYym 9dBYYrAKCxdHlc
u12mBgs54ZzHz18we4IPzA==
=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
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...
2
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...
2
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...
6
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
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...
25
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...
2
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...
2
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...
10
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...
31
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...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...
0
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...

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.