- From: Mark Birbeck <mark.birbeck@x-port.net>
- Date: Mon, 20 Dec 2004 15:25:09 -0000
- To: <popescu@cs.helsinki.fi>
- Cc: <www-forms@w3.org>
Hi Andrei, The first thing to note is that *all* your current bind statements are wrong: > <bind nodeset="thumbnail[1]/@src" calculate="image[1]/@src"/> > <bind nodeset="thumbnail[2]/@src" calculate="image[2]/@src"/> > <bind nodeset="thumbnail[3]/@src" calculate="image[3]/@src"/> The MIP attributes (calculate, readonly, relevant, etc.) are relative to the nodeset iterated by @nodeset, so your first bind statement says: set /photoalbum/thumbnails/thumbnail[1]/@src to the value of: /photoalbum/thumbnails/thumbnail[1]/@src/image[1]/@src which is obviously incorrect. Since you obviously want this: set /photoalbum/thumbnails/thumbnail[1]/@src to the value of: /photoalbum/images/image[1]/@src then you need to do this: <bind nodeset="thumbnail[1]/@src" calculate="../../../images/image[1]/@src" /> or this: <bind nodeset="thumbnail[1]/@src" calculate="/photoalbum/images/image[1]/@src" /> Anyway, on to the main point of your question -- how to insert new nodes and still maintain this calculation. XForms already supports what you want, since <bind> operates over nodesets. All you need to do is change your @nodeset value to: <bind nodeset="thumbnail/@src" ... /> and the rule will apply to all @src attributes or all thumbnail elements. If a new one is inserted, or one deleted, then the list of nodes in the nodeset is recreated (which is why a rebuild is triggered when you do insert or delete). The actual calculation to perform for each node would be something like this: <bind nodeset="thumbnail/@src" calculate="../../../images/image[ count(current()/../preceding-sibling::*) ]/@src" /> I don't have time to check this but I'll explain what it's doing in case you need to tweak it: 1. Get a list of the thumbnail elements prior to the current one: current()/../preceding-sibling::* Note that this works because @nodeset uses @calculate multiple times for each node in the list created by @nodeset. 2. Count the 'preceding' nodes: count( ... ) 3. Use that value to offset into the list of image elements, and get the src attribute: ../../../images/image[ ... ]/@src Regards, Mark Mark Birbeck CEO x-port.net Ltd. e: Mark.Birbeck@x-port.net t: +44 (0) 20 7689 9232 w: http://www.formsPlayer.com/ Download our XForms processor from http://www.formsPlayer.com/
Received on Monday, 20 December 2004 15:25:18 UTC