|
Subject: RE: [xsl] Use pure XPath to test a sequence for being a valid Fibonacci sequence From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Wed, 31 Jan 2007 17:25:42 -0000 |
Not sure why you are using index-of (or some, for that matter). It looks to
me like
$fib[1] = 0 and $fib[2] = 1 and
every $i in 2 to count($fib) satisfies
$fib[$i] = $fib[$i - 1] + $fib[$i - 2]
Michael Kay
http://www.saxonica.com/
> -----Original Message-----
> From: Abel Braaksma [mailto:abel.online@xxxxxxxxx]
> Sent: 31 January 2007 17:13
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Use pure XPath to test a sequence for being a
> valid Fibonacci sequence
>
> Hi Xslt'ers,
>
> I was wondering about the following: using some/every XPath
> expressions, is it possible to test values in a sequence
> against preceding values?
> The requirement pops up when you want to test pairs of
> values, where, say, the even indexed value must be greater
> than the odd indexed value, etc. I often have this
> requirement, and although it is resolvable with for-each
> and/or nested for-in-return, I was looking for a simpler solution.
>
> Since many people understand the requirements of Fibonacci
> numbers, I think it is a good example use case and represents
> my actual use case pretty well (without the blur):
>
> 0, 1, 1, 2, 3, 5, 8, 13, 21...
>
> Now, for each given Fibonacci number, it is correct if:
>
> F(n) = F(n-1) + F(n-2)
>
> For positions 1 and 2, if the value for F(n-1) and F(n-2) are zero.
>
> This is what I could think of. It is not working, because
> index-of() function return two indices for the the number '1'
> (because it appears twice). It works if I omit these numbers,
> but then I cannot apply the 'every'. Does someone know of a
> way to use some/every instructions in a way that it satisfies
> the Fibonacci series above with 'every'? Perhaps it is simply
> not possible (or requires an awkward construction)?
>
> some $i in $fib satisfies
> $fib[index-of($fib, $i) - 1] + $fib[index-of($fib, $i) - 2] = $i
>
> $fib was defined as:
> <xsl:variable name="fib" as="xs:integer*" select="(0, 1, 1,
> 2, 3, 5, 8, 13, 21)" />
>
> Cheers,
> -- Abel Braaksma
> http://www.nuntia.nl
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] Use pure XPath to test a sequ, Abel Braaksma | Thread | Re: [xsl] Use pure XPath to test a , Abel Braaksma |
| [xsl] Use pure XPath to test a sequ, Abel Braaksma | Date | Re: [xsl] Use pure XPath to test a , Abel Braaksma |
| Month |