Advertisements

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.

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

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 ?

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"><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 ?

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
>> 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 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('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.

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!