Re: [docbook-apps] RE: problem with position()

From
Bob Stayton <>
Date
2011-05-07T16:59:04+00:00
ID
009a01cc0cd8$088a4390$6600a8c0@pazu
Thread
Re: [docbook-apps] RE: problem with position()
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



----- Original Message ----- 
From: "Stefan Seefeld" <>
To: <>
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: 
> For additional commands, e-mail: 
>
>
>