- From: Mark Birbeck <mark.birbeck@x-port.net>
- Date: Mon, 2 Oct 2006 11:16:31 +0100
- To: www-forms@w3.org
Swithum, This works in all the XForms processors that I've used, and is a clever technique that I first saw used by David Landwehr a good few years ago. (And of course, I now use everywhere!) Note however that if we were following to the letter the XForms specification, your code should *not* work. The 'group' with @ref is ok, but 'repeat' is only supposed to operate across nodesets where each node is of the same type--in other words, you can't mix cats and dogs. However, most implementations ignore this limitation. Just for the historical context, the original motivaters of this rule thought they were doing implementers a favour by having such a restriction, but most implementers have found it is easier to allow anything, than to enforce the rule. All the best, Mark PS It's not always necessary to have multiple 'types' across the 'repeat', if all that is changing is the label. XForms allows 'output' to be used in the 'label' element, so for the cats and dogs in your example one could easily construct the relevant labels with a couple of 'output's or even one 'output' which uses the 'concat' function. However, the 'group' technique comes into its own when the data 'footprint' is different--in this case, rats use @id whilst cats and dogs use @Name. On 02/10/06, Swithun Crowe <swithun@swithun.servebeer.com> wrote: > > Hello > > AB Is there anyway where we can use a switch statement where we can display > AB the data, based on condition? Like Xsl:Choose? Ok here is what my model > AB is: > > AB Now I need to list animals in sequence, each type of animal have to be > AB shown in different format. I can have any number of animals, animals can > AB be in any order. > > This works in Firefox. I use xf:group elements and the @ref attribute does > the job of case toggling. > > <xf:model> > <xf:instance id="animals"> > <data xmlns=""> > <Animals> > <Cat Name="cat 1"/> > <Cat Name="cat 2"/> > <Dog Name="My Dog 1" CanBark="false"/> > <Dog Name="Your 1" CanBark="true"/> > <Rat id="Something" whatever="Something"/> > </Animals> > </data> > </xf:instance> > </xf:model> > <xf:repeat nodeset="Animals/*"> > <xf:group ref=".[name()='Cat']"> > <xf:output ref="@Name"> > <xf:label>Cat is </xf:label> > </xf:output> > </xf:group> > <xf:group ref=".[name()='Dog' and @CanBark='false']"> > <xf:output ref="@Name"> > <xf:label>Non-barking dog is </xf:label> > </xf:output> > </xf:group> > <xf:group ref=".[name()='Dog' and @CanBark='true']"> > <xf:output ref="@Name"> > <xf:label>Barking dog is </xf:label> > </xf:output> > </xf:group> > <xf:group ref=".[name()='Rat']"> > <xf:output ref="@id"> > <xf:label>Rat is </xf:label> > </xf:output> > </xf:group> > </xf:repeat> > > Swithun. > > > -- Mark Birbeck CEO x-port.net Ltd. e: Mark.Birbeck@x-port.net t: +44 (0) 20 7689 9232 w: http://www.formsPlayer.com/ b: http://internet-apps.blogspot.com/ Download our XForms processor from http://www.formsPlayer.com/
Received on Monday, 2 October 2006 10:16:43 UTC