Re: [xsl] finding position() in xpath 1.0

Subject: Re: [xsl] finding position() in xpath 1.0
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Mon, 19 Mar 2007 15:16:58 +0100
David Carlisle wrote:

//CELL[position() = count(../following-sibling::ROW[1]/CELL[@test='yes']/preceding-sibling::CELL)]/following-sibling::CELL[1]



yes that's simpler, but I think it needs to be

//CELL[position() = 1 +
count(../following-sibling::ROW[1]/CELL[@test='yes']/preceding-sibling::CELL)]



as if the test node is a first child you want the first child (that is position()=1) rather than the first sibling of the node with position()=0 (as there is no such node).


No, not exactly, because that will also select the first CELL of each block (the '+ 1', which in your original solution could safely be used, but not here, because now it is always at least one, and never zero).


But you are right as well for the corner case where the test is on position=1, which means that unfortunately I have to put in the self-test again (darn, why do they have ancestor:: | ancestor-of-self | descendant:: | descendant-or-self but not preceding-sibling:: | preceding-silbing-or-self:: etc ?).

//CELL[count(../following-sibling::ROW[1]/CELL[@test='yes']/preceding-sibling::CELL | ../following-sibling::ROW[1]/CELL[@test='yes'])]

And what happens if we have multiple @tst='yes'? Can that happen? In that case, all our predicates, in either solution should be changed, i.e. each:

CELL[@test='yes']

must be then changed in

CELL[@test='yes'][1]

or whichever number the OP prefers

-- Abel

Current Thread