XSL: func position: reports wrong position - counts by two

RESOLVED INVALID

Status

()

--
major
RESOLVED INVALID
15 years ago
13 years ago

People

(Reporter: pods, Assigned: peterv)

Tracking

Trunk
x86
Linux
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(URL)

Attachments

(4 attachments)

(Reporter)

Description

15 years ago
User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031007 Firebird/0.7
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031007 Firebird/0.7

Appears in Firebird 7 (linux) and latest release of Mozilla (1.6 on Windows)
Have not tested with anything else.

At a point within the XSL document, position is called and it reports the wrong
position of the elements. It seems to be counting in two. Ie position() returns
'2' on the first element, 4 on the second and 6 on the 3rd. There are only 3
elements. It only seems to happen at this depth, and on these elements. I am
sure there is nothing wrong with my code, as it seems to work well in IE,
although i know that doesnt neccessary mean its ok. Although, i have looked at
this code for long enough to know it should be alright.

XML file: resume.xml
XML nodes: document/body/topic/skills
XSL stylesheet: xslinclude/skills.xsl

Reproducible: Always

Steps to Reproduce:
1. Open URL in Mozilla 

Actual Results:  
Down the bottom of the page, under the heading SKills (in greeny colour) the
possition function has been called and it reports "2 4 6" as it goes through the
skills nodes of which there are 3.

Expected Results:  
The actualy results, should be "1 2 3"

The server of the URL i have given above may have HUGE problems with bandwidth.
I'll be very pleased to email the files with installation instructions (very
minimal) if needed.
(Reporter)

Comment 1

15 years ago
Created attachment 139564 [details]
main file to run in browser

I'll upload 5 files in total.

Instructions:
1) Add all files to a directory
2) Within that directory, create another directory named "xslinclude"
3) move common.xsl and skills.xsl into "xslinclude"
4) open, resume.xml with your browser (mozilla)

Directory contents should looks as follows:

$dir/resume.xml
$dir/resume.xsl
$dir/xslinclude/common.xsl
$dir/xslinclude/skills.xsl
(Reporter)

Comment 2

15 years ago
Created attachment 139565 [details]
main xml style sheet for resume.xml
(Reporter)

Comment 3

15 years ago
Created attachment 139566 [details]
this stylesheet is included by ../resume.xsl

move file to xslinclude/
(Reporter)

Comment 4

15 years ago
Created attachment 139567 [details]
this stylesheet is included via ../resume.xsl

move file to xslinclude/
This works according to spec.

When you do <xsl:apply-templates/> is the same as <xsl:apply-templates
select="node()"/> which will select and process all childnodes of the current
node, both textnodes and elements.

When you inside a template then do <xsl:value-of select="position()"/> that will
select the position in the current list of nodes being processed. Again, that
list contains both textnodes and elements. And in your example you have
whitespace between all <skills> elements which means that all skills elements
will have an even position.

To fix this either remove the whitespace between the <skills> elements, or
change <xsl:apply-templates/> to <xsl:apply-templates select="*"/>.

And in the future, please include a much smaller testcase. This one happened to
be easy since i pretty much knew what the problem would be by just reading your
first comment
Status: UNCONFIRMED → RESOLVED
Last Resolved: 15 years ago
Resolution: --- → INVALID
*** Bug 303855 has been marked as a duplicate of this bug. ***
*** Bug 274544 has been marked as a duplicate of this bug. ***
*** Bug 267292 has been marked as a duplicate of this bug. ***
You need to log in before you can comment on or make changes to this bug.