Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old December 3rd, 2006, 01:45 AM
datamodel
Guest
 
Posts: n/a
Default 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::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.

  #2  
Old December 3rd, 2006, 02:05 AM
datamodel
Guest
 
Posts: n/a
Default Re: How to compute a node's depth in XSLT? -- Solved

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:
Quote:
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.
  #3  
Old December 3rd, 2006, 08:25 AM
Joe Kesselman
Guest
 
Posts: n/a
Default Re: How to compute a node's depth in XSLT? -- Solved

datamodel wrote:
Quote:
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
  #4  
Old December 3rd, 2006, 04:55 PM
Jürgen Kahrs
Guest
 
Posts: n/a
Default Re: How to compute a node's depth in XSLT?

datamodel wrote:
Quote:
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.
Quote:
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 ?
  #5  
Old January 16th, 2007, 03:25 PM
datamodel
Guest
 
Posts: n/a
Default Re: How to compute a node's depth in XSLT?

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:
Quote:
datamodel wrote:
>
Quote:
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.
>
Quote:
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 ?
  #6  
Old January 16th, 2007, 09:15 PM
David Carlisle
Guest
 
Posts: n/a
Default Re: How to compute a node's depth in XSLT?

datamodel wrote:
Quote:
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:
Quote:
>datamodel wrote:
>>
Quote:
>>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.
>>
Quote:
>>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

  #7  
Old January 16th, 2007, 09:25 PM
=?ISO-8859-1?Q?J=FCrgen_Kahrs?=
Guest
 
Posts: n/a
Default Re: How to compute a node's depth in XSLT?

David Carlisle wrote:
Quote:
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.
Quote:
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.
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles