473,395 Members | 1,574 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,395 software developers and data experts.

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.

Dec 3 '06 #1
6 7183
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::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.
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"><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 ?
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"><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 ?
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
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

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('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.
Jan 16 '07 #7

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

Similar topics

5
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
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...
2
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...
6
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...
4
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....
7
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...
2
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"...
10
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
by: njsimha | last post by:
Hi, I have the following XML snippet: <root> <template1> <elem1>1000</elem1> <elem2> <subelem1>65</subelem1>
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...

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.