W3C home > Mailing lists > Public > www-forms@w3.org > July 2006

Re: set value for more than one element in select1?

From: Erik Bruchez <ebruchez@orbeon.com>
Date: Mon, 24 Jul 2006 16:45:25 +0200
Message-ID: <44C4DD05.2090102@orbeon.com>
To: www-forms@w3.org

Andrew S. Townley wrote:

 >>> However, once the value is selected from the select1, I need to include
 >>> it in the following XML instance document:
 >>> <Element>
 >>>   <ItemName/>
 >>>   <ItemCode/>
 >>>   ...
 >>>   <OtherElement/>
 >>> </Element>
 >> The above is not clear: what do you mean by "include it"?
 > Apologies.  It seemed perfectly clear when I wrote it yesterday. :)
 > The root of the problem is that I need to convert a single element with
 > attributes into two elements within my model based on whatever the
 > current selection happens to be.
 > So, if in the above, I have selected the following in the select1
 > <Item Code="Fred">Yellow</Item>
 > I need this to end up in the instance document as:
 > <Element>
 >   <ItemName>Yellow</ItemName>
 >   <ItemCode>Fred</ItemCode>
 >   ...
 >   <OtherFormElements/>
 > </Element>
 > I realize that ideally the value from the select could be used "as
 > is" in the final instance document

No, that's ok, you don't always have control over the format of your
document, and XForms should provide you with enough flexibility to
address such cases.

 > but I'm trying to populate an instance with what might as well be an
 > external schema.

As I said ;-)

 > As I said, I suspect the only viable option is to create a new,
 > intermediate instance that allows me to embed the original <Item>
 > element as is, and the post-process the resulting instance to
 > generate the instance that I eventually need to create, but I wanted
 > to make sure there wasn't a better way.

If you use xforms:select1, you are right, you have to bind that
control to a node in an instance, where the selected value remains as

Once you are there, you can post-process, but you should be able to do
that with XForms.

<xforms:instance id="selected-values">

<xforms:instance id="items">
     <Item Code="Fred">Yellow</Item>

<xforms:instance id="insert-template">

<xforms:select1 ref="instance('selected-values')/colors">
   <xforms:action ev:event="xforms-value-changed">
     <!-- Insert element if not present -->
     <xforms:insert context="/where/you/want/to/insert"
     <!-- Set item name -->
     <xforms:setvalue ref="/where/you/want/to/insert/Element/ItemName"
                      value="instance('items')/Item[. = 
     <!-- Set item code -->
     <xforms:setvalue ref="/where/you/want/to/insert/Element/ItemCode"

I did not check the above code, but you get the idea. Note that this
uses some XForms 1.1 features (supported by current OPS nightly


Orbeon - XForms Everywhere:
Received on Monday, 24 July 2006 14:45:32 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:36:18 UTC