Allowing Xform controls for optional XML elements

Posted by Cam on Stack Overflow See other posts from Stack Overflow or by Cam
Published on 2011-01-05T10:40:04Z Indexed on 2011/01/06 16:53 UTC
Read the original article Hit count: 177

Filed under:
|

Hi,

In designing an XForm interface to an XML database (using eXist and XSLTForms), I'd like to include an input control for an optional element. The XML data records already exist and while some contain the optional element, others don't. To update a record, I'm using the existing XML record as the model instance. The problem is that the form control is not displayed when the optional element is not present, which is logical, but presents a problem when a user wants to add data to the optional element.

To be more explicit, here's an example data record, data.xml:

<a>
  <b>content</b>
</a>

with RNC schema:

start =
  element a {
    element b { text },
    element notes { text }?
  }

XForms model:

<xf:model>
    <xf:instance xmlns="" src="data.xml"/> 
    <xf:submission id="save" method="post" action="update.xq" />
</xf:model>

And control:

<xf:input ref="/a/notes">
  <xf:label>Notes (optional): </xf:label>
</xf:input>  

The problem is that the 'Notes' input control is simply not displayed.

An obvious solution is to add a trigger button to allow the user to insert the element if needed, but it is preferable to just have the input control appear, and be empty.

My question is: is there some subtle combination of lesser-know attributes/binds/multiple instances/xpath expressions that will cause the control to always be displayed?

Thanks

© Stack Overflow or respective owner

Related posts about xforms

Related posts about exist