Subject: Re: [xsl] Fwd: XSLT 2.0 Determining Position of Sequence Item During "for expression" evaluation From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx> Date: Fri, 16 Mar 2007 13:36:37 -0700 |
I'm doing all this with Saxon 8.8J
I have a simple xpath expression like this
for $x in (10 to 20) return $x
which simply return the sequence of integers between 10 and 20
Now, what if I wanted to return something like this instead from the same sequence
1 2 3 4 ... 11
I want to get access to the "position" of $x in the sequence, and also the total number of items in the sequence.
I tried something like this
for $x in (10 to 20) return $x/position()
which failed because $x was an integer, not a node so it couldn't tell me the position of it... so I tried it out on my "real" code and all it ever outputted was 1's
The real problem I'm trying to tackle is simply treating the last one different than all the others to do some special formatting of the list. I figured it would be easy enough to do a position()=last() type check...
is not absolutely clear what you want to do, something like the following may be useful:
for $k in 1 to 10 return (4 to 13)[$k]
can always be used, regardless of the types of values for the items of the sequence.
-- Cheers, Dimitre Novatchev --------------------------------------- Truly great madness cannot be achieved without significant intelligence. --------------------------------------- To invent, you need a good imagination and a pile of junk ------------------------------------- You've achieved success in your field when you don't know whether what you're doing is work or play
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Fwd: XSLT 2.0 Determining Pos, John McGowan | Thread | Re: [xsl] Fwd: XSLT 2.0 Determining, John McGowan |
RE: [xsl] Variation on adjaceny lis, cknell | Date | RE: [xsl] Variation on adjaceny lis, Simon Shutter |
Month |