xsl-list
[Top] [All Lists]

RE: position() returns what?

2003-10-24 02:58:45
When position() returns 2,4,6,8 it is because you are processing the
whitespace text nodes between the elements, as well as the elements
themselves. Use xsl:strip-space to get rid of the whitespace nodes, or
use <xsl:apply-templates select="*"> to avoid processing them.

But you might find that generate-id() is a better solution to your
problem than position() - I can't tell from your description.

Michael Kay

-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com 
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of 
Morten Andersen
Sent: 24 October 2003 09:38
To: XSL-List(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] position() returns what?


ksI want to iterate through a list of elements and bewteen 
these elements 
put a link that indicates where in the xml-document we are.

For instance I want to transform:

<page>
   <part name="title-1" text="This is the text"></part>
   <part name="title-2" text="This is the text of the second 
part"></part> </page>

Into something like:

<html><body>
<a href="editPart.action?number=0">Edit</a>
<h2>title-1</h2>
This is the text
....

My problem is how do I get the position / index of the part I'm 
transforming. I tryed with:

<xsl:template match="part">
     <xsl:value-of select="position()"/>

But this outputs equal numbers: 2,4,6,8,10,...
I did expect that it would output 0,1,2,3,4,5

I'm sure this comes down to the fact that I lack some background 
information, but I have a hard time finding that. What I'm 
looking for is a 
JavaDoc alike information preferably with good examples.




Thanks


Morten Andersen
Master of applied mathematics and computer science
Amanuensis (in e-learning)

The Maersk Institute of Production technology at Southern 
Danish University 
www.mip.sdu.dk
Campusvej 55
DK-5230 Odense M
Denmark
+45 6550-3654
+45 6171-1103
Jabber id: hat(_at_)jabber(_dot_)dk


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>