Subject: Re: position() problem
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 11 Jul 2006 14:40:30 +0100
|
> I have a problem with position(). I know that its value is the position
> of the context node.
not really, the number returned by position() is not a property of the
node, the same node will have different position() depending on how it
was selected. For example if it is selected with select="." it will have
position()=1.
> Having selected a token/@pos='N' I'd like to select its
> following sibling token/@pos='N' if and only if it is in a specified
> distance (e.g., 5 tokens away).
select="following-sibling::*[position()<6]"
selects the following six elements, so
select="following-sibling::*[position()<6][@pos='N'][position()=1]"
selects the first of those (if there is one) with @pos='N' (note how
position() changes value for a given node even within the same path
expression0
> If both tokens are in the specified distance all tokens should be
> displayed (starting from N1 up to N2 with all other tokens between them).
a bit easier to say that in xpath 2 than xpath 1, but in xpath 1
probably you's do something like
<xsl:variable name="next"
select="following-sibling::*[position()<6][@pos='N'][position()=1]"/>
<xsl:if test="$next">
<xsl:for-each select="following-sibling::*[generate-id(following-sibling::*[@pos='N'])=generate-id($next)"/>
David
|