[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Use pure XPath to test a sequence for being a valid F

Subject: Use pure XPath to test a sequence for being a valid Fibonacci sequence
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Wed, 31 Jan 2007 18:12:44 +0100
 Use pure XPath to test a sequence for being a valid  F
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.