Altova Mailing List Archives


Re: [xsl] position() problem

From: David Carlisle <davidc@--------->
To:
Date: 7/11/2006 1:41:00 PM
> 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()&lt;6]"
selects the following six elements, so
select="following-sibling::*[position()&lt;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()&lt;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

Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.