473,655 Members | 3,056 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to compute a node's depth in XSLT?

Hello I have an XML tree of which you can see a mini-version here:

http://paste.uni.cc/11838

(the tree is actually over 30,000 levels deep)

How do I count the depth of a given <NODES><NODE??? ??

The problem is I would like to "color" nodes based on their depth in
the tree - ie, use alternating colors.

A depth, or actually "level" in the logical tree actually comprises two
levels in the XML tree - ie
<NODES><NODE>

There is no depth attribute in the XML tags,
and the position() function applies only to the currently processed
node,

Ideally I want to construct a test like

<xsl:if test="[parent::positio n() &lt; 3]">

of course this is wrong syntax.

and position() doesn't help , since it really computes the position in
the siblings at a given level,
not the level of depth in the tree.

Dec 3 '06 #1
6 7210
This solution is in XSLT 1.0
not very elegant to the time complexity -

I used the function :

count(ancestor: :NODES)

to determine a value for the depth of a given <NODEnode.
datamodel wrote:
Hello I have an XML tree of which you can see a mini-version here:

http://paste.uni.cc/11838

(the tree is actually over 30,000 levels deep)

How do I count the depth of a given <NODES><NODE??? ??

The problem is I would like to "color" nodes based on their depth in
the tree - ie, use alternating colors.

A depth, or actually "level" in the logical tree actually comprises two
levels in the XML tree - ie
<NODES><NODE>

There is no depth attribute in the XML tags,
and the position() function applies only to the currently processed
node,

Ideally I want to construct a test like

<xsl:if test="[parent::positio n() &lt; 3]">

of course this is wrong syntax.

and position() doesn't help , since it really computes the position in
the siblings at a given level,
not the level of depth in the tree.
Dec 3 '06 #2
datamodel wrote:
count(ancestor: :NODES)
That counts the ancestors elements named <NODES>. I think you meant
count(ancestor: :node())
--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Dec 3 '06 #3
datamodel wrote:
Hello I have an XML tree of which you can see a mini-version here:

http://paste.uni.cc/11838

(the tree is actually over 30,000 levels deep)
Thanks for pointing us to this data source.
I actually downloaded the original file here:

http://www.tolweb.org/tree/home.pages/downloadtree.html

I was a bit disappointed by the crude quality
of this data.

xmllint --noout tolskeletaldump .xml
tolskeletaldump .xml:25234: parser error : Input is not proper UTF-8, indicate encoding !
Bytes: 0xE9 0x6B 0x65 0x73
EXTINCT="0" ID="66855"><NAM E><![CDATA[Stichotrema sz?essyi]]></NAME></NOD
^
Whoever created this data, he should insert
a proper XML header indictaing the encoding.
How do I count the depth of a given <NODES><NODE??? ??
I am still interested in this XML file because it
is the only example of real-life data I ever saw
that claimed to contain 30,000 levels of depth.
Last year I created a synthetic file with 10,000
levels (for regression tests) and some people told
me that this is nonsense. They said that data with
so many levels never occur in real-life.

I am interested in using your file for regression tests.
Do you see any chance that your file will be supplied
in an updated and corrected form ?
Dec 3 '06 #4
I also got the file from the same location you cited.
I am not the author of the file, and I agree with you.
I was also disappointed at crudeness / quality of the document.
However I was very happy that TOL made this file available to the
public :)
Jürgen Kahrs wrote:
datamodel wrote:
Hello I have an XML tree of which you can see a mini-version here:

http://paste.uni.cc/11838

(the tree is actually over 30,000 levels deep)

Thanks for pointing us to this data source.
I actually downloaded the original file here:

http://www.tolweb.org/tree/home.pages/downloadtree.html

I was a bit disappointed by the crude quality
of this data.

xmllint --noout tolskeletaldump .xml
tolskeletaldump .xml:25234: parser error : Input is not proper UTF-8, indicate encoding !
Bytes: 0xE9 0x6B 0x65 0x73
EXTINCT="0" ID="66855"><NAM E><![CDATA[Stichotrema sz?essyi]]></NAME></NOD
^
Whoever created this data, he should insert
a proper XML header indictaing the encoding.
How do I count the depth of a given <NODES><NODE??? ??

I am still interested in this XML file because it
is the only example of real-life data I ever saw
that claimed to contain 30,000 levels of depth.
Last year I created a synthetic file with 10,000
levels (for regression tests) and some people told
me that this is nonsense. They said that data with
so many levels never occur in real-life.

I am interested in using your file for regression tests.
Do you see any chance that your file will be supplied
in an updated and corrected form ?
Jan 16 '07 #5
datamodel wrote:
I also got the file from the same location you cited.
I am not the author of the file, and I agree with you.
I was also disappointed at crudeness / quality of the document.
However I was very happy that TOL made this file available to the
public :)
Jürgen Kahrs wrote:
>datamodel wrote:
>>Hello I have an XML tree of which you can see a mini-version here:

http://paste.uni.cc/11838

(the tree is actually over 30,000 levels deep)
Thanks for pointing us to this data source.
I actually downloaded the original file here:

http://www.tolweb.org/tree/home.pages/downloadtree.html

I was a bit disappointed by the crude quality
of this data.

xmllint --noout tolskeletaldump .xml
tolskeletaldum p.xml:25234: parser error : Input is not proper UTF-8, indicate encoding !
Bytes: 0xE9 0x6B 0x65 0x73
EXTINCT="0" ID="66855"><NAM E><![CDATA[Stichotrema sz?essyi]]></NAME></NOD
^
Whoever created this data, he should insert
a proper XML header indictaing the encoding.
>>How do I count the depth of a given <NODES><NODE??? ??
I am still interested in this XML file because it
is the only example of real-life data I ever saw
that claimed to contain 30,000 levels of depth.
Last year I created a synthetic file with 10,000
levels (for regression tests) and some people told
me that this is nonsense. They said that data with
so many levels never occur in real-life.

I am interested in using your file for regression tests.
Do you see any chance that your file will be supplied
in an updated and corrected form ?
if you stick
<?xml version="1.0" encoding="iso-8859-1"?>
at the top of the file extracted from the referenced zip file then it
becomes well formed.

executing the Xquery

max(doc('tolske letaldump2.xml' )//*/count(ancestor: :*))
returns 241 as the maximum depth of an element node, which is rather
less than 30000.

David

Jan 16 '07 #6
David Carlisle wrote:
if you stick
<?xml version="1.0" encoding="iso-8859-1"?>
at the top of the file extracted from the referenced zip file then it
becomes well formed.
Indeed, now it is well formed.
executing the Xquery

max(doc('tolske letaldump2.xml' )//*/count(ancestor: :*))
returns 241 as the maximum depth of an element node, which is rather
less than 30000.
Yes, my software also calculates this value.
I wonder why the OP claimed a depth of 30000.
Jan 16 '07 #7

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

Similar topics

5
2225
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">
4
3243
by: Frederik Sørensen | last post by:
I include a xslt stylesheet with variables for all the error messages in my system. <xsl:variable name="Banner_error_1"> errormessage 1 for banner </xsl:variable> <xsl:variable name="Banner_error_2"> errormessage 2 for banner </xsl:variable>
2
1345
by: FaensenD | last post by:
Can someone explain why of the following two alternative ways to select as specific node the first one doesn't work while the second one does? Variant I: <recordToken> <xsl:value-of select="/Root/Case/RecordToken" /> </recordToken>
6
2501
by: Michiel Kamermans | last post by:
Hi, I need to generate a list based on a sorted nodeset, except duplicates need to be discarded. I initially though of doing a sort on a nodeset and then passing it to a template that iterates over the set and compares the current element it's processing to the previous one, continueing to the next element immediately if it was the same as the previous one. However, quite annoyingly the xsl:sort command cannot "just" be called, I need...
4
3118
by: elsigh | last post by:
I'm wondering if anyone has any ideas about a way to quickly convert an HTML DOM Node into an XML Document. The goal is that I want to perform XSLT on the Node, which is coded correctly as XHTML. In Mozillae, it works to parse the serializeToString output, but this functionality doesn't exist for IE. I've made one function that loops through all the nodes & attributes and constructs a string that can be successfully parsed into xml, but...
7
5653
by: Arancaytar | last post by:
(Note: I am a Javascript newbie. I can handle PHP and Java, but this is unfamiliar territory.) For a wordcount feature, I need to collect the complete text content of a 'div' element inside a variable. Because of the issues with paragraphs and markup, the content is split into different nodes in the DOM. For example:
2
2377
by: Boris | last post by:
I'm making my first steps with XSLT and run into a problem where I didn't find an explanation yet for. Have a look at this very simple XML document (DocBook) ... <?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet type="text/xsl" href="test.xslt"?> <book version="5.0"> <title>Title</title> </book>
10
5746
by: bbembi_de | last post by:
Hello everyone, is it possible to give a transformation a input parameter? I want to use this parameter as a variable in my transformation. thanks. bye bembi
16
2585
by: njsimha | last post by:
Hi, I have the following XML snippet: <root> <template1> <elem1>1000</elem1> <elem2> <subelem1>65</subelem1>
0
8816
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
8710
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
8497
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
8598
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
7310
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
4150
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
4299
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2721
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
2
1928
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.