How to compute a node's depth in XSLT?

D

datamodel

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::position() &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.
 
D

datamodel

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 <NODE> node.
 
?

=?ISO-8859-1?Q?J=FCrgen_Kahrs?=

datamodel said:
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"><NAME><![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 ?
 
D

datamodel

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 said:
datamodel said:
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"><NAME><![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 ?
 
D

David Carlisle

datamodel said:
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 said:
datamodel said:
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"><NAME><![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('tolskeletaldump2.xml')//*/count(ancestor::*))


returns 241 as the maximum depth of an element node, which is rather
less than 30000.

David
 
?

=?ISO-8859-1?Q?J=FCrgen_Kahrs?=

David said:
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('tolskeletaldump2.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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top