iterating over multi-value field

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

iterating over multi-value field

FParsons
Hi! I've been looking for info on this: say I have a field that is a delimited multi value field (created by a select), for example:
 <selected-items>two four five eight ten</selected-items>

Is there a way to perform an action for each value in the field? For that matter, is there a syntax for referring to a single value in a delimited multi value field?

I've not been able to find mention of this anywhere, so any help would be appreciated. Basically, what I'm trying to do is to insert various nodes based on the value generated by the <select>, without having to create an individual action for each.
-- Francis
Reply | Threaded
Open this post in threaded view
|

Re: iterating over multi-value field

Louis Ratzesberger-2


Hi Francis,

You can use XPath 2.0 functions in many ways in Orbeon,
for example, to create elements from a space separated
string:

<xforms:repeat nodeset="for $s in
   tokenize(instance('selected-items'),'\s')
return xxforms:element('text',$s)">
...
</xforms:repeat>

And you may now actually be able to repeat over
sequences ... trouble finding that post.

Cheers,
Hank


Quoting FParsons <[hidden email]>:

>
> Hi! I've been looking for info on this: say I have a field that is a
> delimited multi value field (created by a select), for example:
>  <selected-items>two four five eight ten</selected-items>
>
> Is there a way to perform an action for each value in the field? For that
> matter, is there a syntax for referring to a single value in a delimited
> multi value field?
>
> I've not been able to find mention of this anywhere, so any help would be
> appreciated. Basically, what I'm trying to do is to insert various nodes
> based on the value generated by the <select>, without having to create an
> individual action for each.
>
> -----
> -- Francis
> --
> View this message in context:  
> http://orbeon-forms-ops-users.24843.n4.nabble.com/iterating-over-multi-value-field-tp2245381p2245381.html
> Sent from the Orbeon Forms (ops-users) mailing list archive at Nabble.com.
>


--
Hank Ratzesberger
[hidden email]



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Re: iterating over multi-value field

FParsons
Hank - thanks so much for your reply! But as a newbie to XForms, I have
another question about this:
Do you mean that to create an action for each element created by the
XPath expression, I should do something like this:

<xforms:repeat nodeset="for $s in
tokenize(instance('selected-items'),'\s') return  
xxforms:element('text',$s)">
<xforms:action while="text">
     ....
</xforms:action>
</xforms:repeat>

--- Francis

On 6/7/2010 6:41 PM, Louis Ratzesberger wrote:

>
>
> Hi Francis,
>
> You can use XPath 2.0 functions in many ways in Orbeon,
> for example, to create elements from a space separated
> string:
>
> <xforms:repeat nodeset="for $s in
>   tokenize(instance('selected-items'),'\s')
> return xxforms:element('text',$s)">
> ...
> </xforms:repeat>
>
> And you may now actually be able to repeat over
> sequences ... trouble finding that post.
>
> Cheers,
> Hank



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
-- Francis
Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: iterating over multi-value field

Louis Ratzesberger-2
Francis,

Well, sort of.  I suppose you would use <insert> or <setvalue> elements.

<xforms:repeat nodeset="...">
   <insert context="instance('my-instance')/" nodeset="." position="after"/>
</xforms:repeat>

The above would (I  hope) add the elements created from the list
to the end of 'my-instance' .

Perhaps you are trying to do something in a complicated way
that XForms can actually do in a simpler way.  I can think of some
scenarios, but remind us why you need to perform an action
for each item in space separated string?

--Hank

Quoting Francis Parsons <[hidden email]>:

> Hank - thanks so much for your reply! But as a newbie to XForms, I  
> have another question about this:
> Do you mean that to create an action for each element created by the  
> XPath expression, I should do something like this:
>
> <xforms:repeat nodeset="for $s in  
> tokenize(instance('selected-items'),'\s') return    
> xxforms:element('text',$s)">
> <xforms:action while="text">
>     ....
> </xforms:action>
> </xforms:repeat>
>
> --- Francis
>
> On 6/7/2010 6:41 PM, Louis Ratzesberger wrote:
>>
>>
>> Hi Francis,
>>
>> You can use XPath 2.0 functions in many ways in Orbeon,
>> for example, to create elements from a space separated
>> string:
>>
>> <xforms:repeat nodeset="for $s in
>>  tokenize(instance('selected-items'),'\s')
>> return xxforms:element('text',$s)">
>> ...
>> </xforms:repeat>
>>
>> And you may now actually be able to repeat over
>> sequences ... trouble finding that post.
>>
>> Cheers,
>> Hank
>
>
>


--
Hank Ratzesberger
[hidden email]



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: iterating over multi-value field

FParsons
Louis Ratzesberger-2 wrote
Perhaps you are trying to do something in a complicated way that XForms can actually do in a simpler way. I can think of some scenarios, but remind us why you need to perform an action for each item in space separated string?
Hank - I was wondering if those "created" elements had to be "put" somewhere! It just seemed to me that doing something with the "multi-value" produced by a select control would be something useful. If it wasn't possible, wouldn't only an "external" application be able to do something with that data? (parse it) I was looking for an alternative to using a separate triggers to insert nodes. If a select control has 5 choices, generating values 'val1 through 'val5, it can produce a value like "val1 val3 val5". I'd like the user to be able to insert different nodes (to a node in the main instance) via a menu. To do this, instead of having 5 triggers: trigger1: insert node1; trigger2: insert node2, trigger3: insert node3... I was wondering if it's possible to have something the equivalent of: for each $value in multivalue ("val1 val3 val5"): action: if $value=val1, insert node1; if $value=val2, insert node2; if $value=val3, insert node3; if $value=val4, insert node4; if $value=val5, insert node5; I don't know if this would actually be simpler in every case, it just seems like it would allow a select control to actually act on the data just created. Would the answer be something simple like this: if (multivalue) "val1 val3 val5" contains('val1'), insert node1; if "val1 val3 val5" contains('val2'), insert node2; .... I forget what the XPath equivalent to "contains()" would be. Is it xforms:action or xforms:insert that can take an "if" attribute (my memory's foggy on this?)
-- Francis
Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: Re: iterating over multi-value field

Louis Ratzesberger-2

Hi Francis,

Iterating over the values of a select is the one scenario I
can think of for all this effort. The values are already
"somewhere" since they are in the instance the select control
is bound to or references. With Orbeon or another server/service
as the target to submit to, it can parse the text etc., as
needed.

However, if you want to iterate
over them within the form, as opposed to submitting the data,
then you have to put them into a nodeset, because the repeat
element only works on nodesets.  (still cannot find the docs
saying that Orbeon repeats will support a sequence...).  Note
that there is also the bind attribute "calculate" that can
be used to update an instance whenever another changes
value -- no need for any action elements.

So there are a few options, but again the server will get
the select data, if only as a string of space separated
tokens.

--Hank


Quoting FParsons <[hidden email]>:

>
>
> Louis Ratzesberger-2 wrote:
>>
>> Perhaps you are trying to do something in a complicated way
>> that XForms can actually do in a simpler way.  I can think of some
>> scenarios, but remind us why you need to perform an action
>> for each item in space separated string?
>>
> Hank - I was wondering if those "created" elements had to be "put"
> somewhere!
>
> It just seemed to me that doing something with the "multi-value" produced by
> a select control would be something useful. If it wasn't possible, wouldn't
> only an "external" application be able to do something with that data?
> (parse it)
>
>
> I was looking for an alternative to using a separate triggers to insert
> nodes.  If a select control has 5 choices, generating values 'val1 through
> 'val5, it can produce a value like "val1 val3 val5". I'd like the user to be
> able to insert different nodes (to a node in the main instance) via a menu.
>
>
> To do this, instead of having 5 triggers: trigger1: insert node1; trigger2:
> insert node2, trigger3: insert node3... I was wondering if it's possible to
> have something the equivalent of:
>
> for each $value in multivalue ("val1 val3 val5"):
> action: if $value=val1, insert node1;
> if $value=val2, insert node2;
> if $value=val3, insert node3;
> if $value=val4, insert node4;
> if $value=val5, insert node5;
>
> I don't know if this would actually be simpler in every case, it just seems
> like it would allow a select control to actually act on the data just
> created.
>
> Would the answer be something simple like this:
> if (multivalue) "val1 val3 val5" contains('val1'), insert node1;
> if "val1 val3 val5" contains('val2'), insert node2;
> ....
>
> I forget what the XPath equivalent to "contains()" would be. Is it
> xforms:action or xforms:insert that can take an "if" attribute (my memory's
> foggy on this?)
>
>
>
> -----
> -- Francis
> --
> View this message in context:  
> http://orbeon-forms-ops-users.24843.n4.nabble.com/iterating-over-multi-value-field-tp2245381p2247271.html
> Sent from the Orbeon Forms (ops-users) mailing list archive at Nabble.com.
>


--
Hank Ratzesberger
[hidden email]



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: iterating over multi-value field

Alessandro  Vernet
Administrator
In reply to this post by FParsons
Francis, Hank,

Just to clarify:

* You use the <xforms:repeat> to iterate over nodes to generate markup
(XHTML, XForms...). <xforms:repeat> can change the way its content is
rendered, like say <xforms:case> or <xforms:group>. If you put an
action inside a <xforms:repeat>, that action will run only if it has a
ev:event="gaga" and a "gaga" event happens. (And I should note that it
is pretty rare to put event handlers directly inside a
<xforms:repeat>.)
* You use the xxforms:iterate attribute on an action to do an
iteration when that action runs. See:
http://www.orbeon.com/orbeon/doc/reference-xforms-extensions#exforms-iterate

Alex

On Mon, Jun 7, 2010 at 6:00 PM, Francis Parsons <[hidden email]> wrote:

> Hank - thanks so much for your reply! But as a newbie to XForms, I have
> another question about this:
> Do you mean that to create an action for each element created by the XPath
> expression, I should do something like this:
>
> <xforms:repeat nodeset="for $s in tokenize(instance('selected-items'),'\s')
> return   xxforms:element('text',$s)">
> <xforms:action while="text">
>    ....
> </xforms:action>
> </xforms:repeat>
>
> --- Francis
>
> On 6/7/2010 6:41 PM, Louis Ratzesberger wrote:
>>
>>
>> Hi Francis,
>>
>> You can use XPath 2.0 functions in many ways in Orbeon,
>> for example, to create elements from a space separated
>> string:
>>
>> <xforms:repeat nodeset="for $s in
>>  tokenize(instance('selected-items'),'\s')
>> return xxforms:element('text',$s)">
>> ...
>> </xforms:repeat>
>>
>> And you may now actually be able to repeat over
>> sequences ... trouble finding that post.
>>
>> Cheers,
>> Hank
>
>
>
>
> --
> You receive this message as a subscriber of the [hidden email] mailing
> list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> OW2 mailing lists service home page: http://www.ow2.org/wws
>
>


--
Orbeon Forms - Web forms, open-source, for the Enterprise -
http://www.orbeon.com/
My Twitter: http://twitter.com/avernet


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet