XForms: binding to an optional element

2

I asked this on the XSLTForms list, but it’s worth casting a wider net.

Say I have an XML instance like this:
<root>
<format>xml</format>
</root>

Possible values for the format element are “xml”, “text”, “binary”, or a default setting, indicated by a complete absence of the <format> element. I’d like this to attach to a select1 with four choices:

<xf:select1 ref=”format”>…

* xml
* text
* binary
* default

Where the first three set the value of the <format> element, and the fourth omits the element altogether. In XForms 1.0, the difficulty comes from binding to a nonexistent element, which causes it to become non-relevant. Are there features from 1.1, 1.2, or extensions that make this case easier? Anyone have an example?

-m

Related Posts

2 Replies to “XForms: binding to an optional element”

  1. Micah,

    No I don’t think there are any solutions in 1.1. I raised this issue three years ago on the www-forms mailing list . I was editing styles for SVG with XForms where the exact same issue occurs for style properties. For example, the absence of font-weight is the same as font-weight=’normal’, but when it’s absent it is not relevant!

    Have a look at the e-mail thread, it may be of use.

  2. Hi Micah,

    One way (workaround?) to deal with this is to set the value of the element to empty when user select “default” in the select1. When doing the submission, before doing the xforms:send, set a flag in some other instance, and after the xforms:send, reset that flag. Define an xforms:bind that makes the element you want to remove non-relevant if the flag is set and its value is empty. This will make the element temporarily non-relevant just when the submission is done. This way the element won’t be sent to the service you call, without impacting the controls.

    Alex

Comments are closed.

© All Right Reserved
Proudly powered by WordPress | Theme: Shree Clean by Canyon Themes.