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

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
text.

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

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

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

<xforms:instance id="insert-template">
   <Element>
     <ItemName/>
     <ItemCode/>
   </Element>
</xforms:instance>

<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"
                    if="not(Element)"
                    origin="instance('insert-template')"/>
     <!-- Set item name -->
     <xforms:setvalue ref="/where/you/want/to/insert/Element/ItemName"
                      value="instance('items')/Item[. = 
instance('selected-values')/colors]/@Code"/>
     <!-- Set item code -->
     <xforms:setvalue ref="/where/you/want/to/insert/Element/ItemCode"
                      value="instance('selected-values')/colors"/>
   </xforms:action>
</xforms:select1>

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
builds).

-Erik

-- 
Orbeon - XForms Everywhere:
http://www.orbeon.com/blog/

Received on Monday, 24 July 2006 14:45:32 UTC