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

Strange problem with count

Hello,

My last few posts have been revolving aroung the same problem, and I
still cant solve it and I would be really appreciate if anyone could
spot a problem.

a section of my XML goes like

.....
<parent>
<child>
<grandchild1>
<grandchild2>
<child>
<parent>

/...

I need to describe a numeric link between grandchild elements and the
child elements.

I have been using count(preceding::*) to id the cells numerically:
<xsl:template select="grandchild1|grandchild2">
<MyID>
Child: <xsl:value-of select="count(../preceding::*)"/>
Grandchild: <xsl:value-of select="count(./preceding::*)"/>
</MyID>
</xsl:template>
However, the first grandchild1 element that runs this has the same
count as the child element. (35 and 35). The second grandchild element
that runs is incremented by one as expected, 35 and 36, meaning it
seems 1 too low. The obvious problem is the first counts are returned
the same, negating the idea of unique numeric ID's.

Are these results to be expected? I do not know why/how the ../ and ./
return the same value (surely the ../preceding has come back a node in
that first case and therefore should be -1 of the grandchild1?)

I know a simple fix is just to add one onto all of the grandchilds
(count(./preceding::*)+1) but it seems slight dodgey, i.e. a fix to a
potential problem in my XSL.

I would really appreciate is anyone could help me understand why this
does not work, so that I can fix it properly.

Any help will again be most appreciated.

Thanks, Rob.

Aug 2 '05 #1
3 1719

<ro************@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hello,

My last few posts have been revolving aroung the same problem, and I
still cant solve it and I would be really appreciate if anyone could
spot a problem.

a section of my XML goes like

....
<parent>
<child>
<grandchild1>
<grandchild2>
<child>
<parent>

/...

I need to describe a numeric link between grandchild elements and the
child elements.

I have been using count(preceding::*) to id the cells numerically:
It is not possible to identify a node uniquely using only one axis.


<xsl:template select="grandchild1|grandchild2">
<MyID>
Child: <xsl:value-of select="count(../preceding::*)"/>
Grandchild: <xsl:value-of select="count(./preceding::*)"/>
</MyID>
</xsl:template>
However, the first grandchild1 element that runs this has the same
count as the child element. (35 and 35). The second grandchild element
that runs is incremented by one as expected, 35 and 36, meaning it
seems 1 too low. The obvious problem is the first counts are returned
the same, negating the idea of unique numeric ID's.

Are these results to be expected?
Yes.

The "preceding" and "ancestor" axis are non-overlapping and can be thought
of as the X and Y axis in a two-dimensional space (plane).

To quote the XPath 1.0 spec:

"the preceding axis contains all nodes in the same document as the context
node that are before the context node in document order, excluding any
ancestors and excluding attribute nodes and namespace nodes"

http://www.w3.org/TR/xpath#axes

I do not know why/how the ../ and ./
return the same value (surely the ../preceding has come back a node in
that first case and therefore should be -1 of the grandchild1?)

I know a simple fix is just to add one onto all of the grandchilds
(count(./preceding::*)+1) but it seems slight dodgey, i.e. a fix to a
potential problem in my XSL.

I would really appreciate is anyone could help me understand why this
does not work, so that I can fix it properly.
An unique ID can be constructed taking both the "ancestor" and "preceding"
axis into account and generating a *pair* of numbers.

Another way is to use xsl:number
Cheers,
Dimitre Novatchev

Any help will again be most appreciated.

Thanks, Rob.

Aug 2 '05 #2
Another quote from the XPath 1.0 Spec, which describes this topic even more
precisely:

"NOTE: The ancestor, descendant, following, preceding and self axes
partition a document (ignoring attribute and namespace nodes): they do not
overlap and together they contain all the nodes in the document."
Cheers,
Dimitre Novatchev
"Dimitre Novatchev" <x@yyy.com> wrote in message
news:42***********************@authen.white.readfr eenews.net...

<ro************@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hello,

My last few posts have been revolving aroung the same problem, and I
still cant solve it and I would be really appreciate if anyone could
spot a problem.

a section of my XML goes like

....
<parent>
<child>
<grandchild1>
<grandchild2>
<child>
<parent>

/...

I need to describe a numeric link between grandchild elements and the
child elements.

I have been using count(preceding::*) to id the cells numerically:


It is not possible to identify a node uniquely using only one axis.


<xsl:template select="grandchild1|grandchild2">
<MyID>
Child: <xsl:value-of select="count(../preceding::*)"/>
Grandchild: <xsl:value-of select="count(./preceding::*)"/>
</MyID>
</xsl:template>
However, the first grandchild1 element that runs this has the same
count as the child element. (35 and 35). The second grandchild element
that runs is incremented by one as expected, 35 and 36, meaning it
seems 1 too low. The obvious problem is the first counts are returned
the same, negating the idea of unique numeric ID's.

Are these results to be expected?


Yes.

The "preceding" and "ancestor" axis are non-overlapping and can be thought
of as the X and Y axis in a two-dimensional space (plane).

To quote the XPath 1.0 spec:

"the preceding axis contains all nodes in the same document as the context
node that are before the context node in document order, excluding any
ancestors and excluding attribute nodes and namespace nodes"

http://www.w3.org/TR/xpath#axes

I do not know why/how the ../ and ./
return the same value (surely the ../preceding has come back a node in
that first case and therefore should be -1 of the grandchild1?)

I know a simple fix is just to add one onto all of the grandchilds
(count(./preceding::*)+1) but it seems slight dodgey, i.e. a fix to a
potential problem in my XSL.

I would really appreciate is anyone could help me understand why this
does not work, so that I can fix it properly.


An unique ID can be constructed taking both the "ancestor" and "preceding"
axis into account and generating a *pair* of numbers.

Another way is to use xsl:number
Cheers,
Dimitre Novatchev

Any help will again be most appreciated.

Thanks, Rob.


Aug 2 '05 #3
Ah, that makes real sense. Thanks! That last quote was a good one.

Thanks again, Rob

Dimitre Novatchev wrote:
Another quote from the XPath 1.0 Spec, which describes this topic even more
precisely:

"NOTE: The ancestor, descendant, following, preceding and self axes
partition a document (ignoring attribute and namespace nodes): they do not
overlap and together they contain all the nodes in the document."
Cheers,
Dimitre Novatchev
"Dimitre Novatchev" <x@yyy.com> wrote in message
news:42***********************@authen.white.readfr eenews.net...

<ro************@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hello,

My last few posts have been revolving aroung the same problem, and I
still cant solve it and I would be really appreciate if anyone could
spot a problem.

a section of my XML goes like

....
<parent>
<child>
<grandchild1>
<grandchild2>
<child>
<parent>

/...

I need to describe a numeric link between grandchild elements and the
child elements.

I have been using count(preceding::*) to id the cells numerically:


It is not possible to identify a node uniquely using only one axis.


<xsl:template select="grandchild1|grandchild2">
<MyID>
Child: <xsl:value-of select="count(../preceding::*)"/>
Grandchild: <xsl:value-of select="count(./preceding::*)"/>
</MyID>
</xsl:template>
However, the first grandchild1 element that runs this has the same
count as the child element. (35 and 35). The second grandchild element
that runs is incremented by one as expected, 35 and 36, meaning it
seems 1 too low. The obvious problem is the first counts are returned
the same, negating the idea of unique numeric ID's.

Are these results to be expected?


Yes.

The "preceding" and "ancestor" axis are non-overlapping and can be thought
of as the X and Y axis in a two-dimensional space (plane).

To quote the XPath 1.0 spec:

"the preceding axis contains all nodes in the same document as the context
node that are before the context node in document order, excluding any
ancestors and excluding attribute nodes and namespace nodes"

http://www.w3.org/TR/xpath#axes

I do not know why/how the ../ and ./
return the same value (surely the ../preceding has come back a node in
that first case and therefore should be -1 of the grandchild1?)

I know a simple fix is just to add one onto all of the grandchilds
(count(./preceding::*)+1) but it seems slight dodgey, i.e. a fix to a
potential problem in my XSL.

I would really appreciate is anyone could help me understand why this
does not work, so that I can fix it properly.


An unique ID can be constructed taking both the "ancestor" and "preceding"
axis into account and generating a *pair* of numbers.

Another way is to use xsl:number
Cheers,
Dimitre Novatchev

Any help will again be most appreciated.

Thanks, Rob.



Aug 2 '05 #4

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

Similar topics

4
by: hall | last post by:
Hi. I've come across someting strange. I was trying to make a for-loop execute repetadly until the function called inside it does not return true during the entire loop (see program below). ...
2
by: Piotr Kurpiel | last post by:
Hello, I am using MS Access 2003 with VBScript. I have quite strange column names which are: 1,2,3,4,etc... Data Types of the columns are Yes/No and formats True/False. The first thing I want to...
0
by: Marc Robitaille | last post by:
Hello group I have a strange problem. I have a panel. On this panel, I can drop custom Textbox that I create at runtime. I have a toolbar on witch a delete button exist. When I click on this...
10
by: Henk Ernst Blok | last post by:
Hi Posgres users/developers, Can anyone explain why PosgreSQL (version 7.4.5 on Linux) does a full table scan to compute a count(*) on a base table after a vacuum analyze has been done with no...
3
by: Michael Meckelein | last post by:
Hello, I run into trouble move down a selected item in a listbox. The code moving down the item is the following one: for (int j = lv.SelectedItems.Count-1; j >=0; j--) { ListViewItem...
10
by: Bernard Liang | last post by:
Consider the following excerpt below, with the included relevant declarations. Firstly, the lines marked with **, ***, **** at the beginning are not supposed to have those stars at the...
10
by: John Kraft | last post by:
Hello all, I'm experiencing some, imo, strange behavior with the StreamReader object I am using in the code below. Summary is that I am downloading a file from a website and saving it to disk...
1
by: Blackstar | last post by:
I have a website I am trying to download a file from. This website is strange in the fact that there is no direct link to the URL of the file. The way the site works is as follows: 1) Enter in...
2
by: djpaul | last post by:
Hello, I have this program and when i want to load pictures it crashes at the form.showdialog()....??? Here it goes: Private Sub CmbPath_SelectedIndexChanged(ByVal sender As Object, ByVal e As...
12
by: Gilles Ganault | last post by:
Hello I'm getting some unwanted result when SELECTing data from an SQLite database: ====== sql = 'SELECT id FROM master' rows=list(cursor.execute(sql)) for id in rows: sql = 'SELECT...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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...

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.