Hi,
As Rob said, the position() function is sometimes tricky to use. If you refer to
Michael Kay's XSLT Programmer's Reference (2nd Edition) page 533 says:
"When <xsl:apply-templates> is called to process a set of nodes, the current node list
is the list of nodes being processed, in the order in which they are processed."
In the case of mode="xref-to", the template matching on <xref> first selects the
target element by matching the linkend to the xml:id. Then that template does
xsl:apply-templates in mode="xref-to" on that single target element. So when the
processing arrives at your template, the node list is a single element, and so
position() always produces "1".
The solution Rob suggested does work, but he left out the namespace prefix in the
select statement:
select="count(preceding-sibling::d:listitem) + 1"
The <xsl:number> element works as well. Both operate in the context of the source
document, not a list of current nodes as is used in position(). So the answer to your
last question is no, they do not operate in the same context.
I generally avoid using position() unless the current node list is specified in the
same template, as in an xsl:for-each statement. Otherwise you are never sure what you
are working with.
Bob Stayton
Sagehill Enterprises
[email protected]
----- Original Message -----
From: "Stefan Seefeld" <[email protected]>
To: <[email protected]>
Sent: Friday, May 06, 2011 1:42 PM
Subject: Re: [docbook-apps] RE: problem with position()
Rob,
thanks for the quick reply. I tried your suggestion but observed the exact same
behavior. And indeed, I don't understand how the two could differ. After all both
operate on the same context, don't they ?
Thanks,
Stefan
--
...ich hab' noch einen Koffer in Berlin...
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]