xsl-list
[Top] [All Lists]

Re: [xsl] position() problem

2006-07-11 06:41:13

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][(_at_)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()&lt;6][(_at_)pos='N'][position()=1]"/>
<xsl:if test="$next">
<xsl:for-each 
select="following-sibling::*[generate-id(following-sibling::*[(_at_)pos='N'])=generate-id($next)"/>


David

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

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