Allowing XForm controls for optional XML elements
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 (opti开发者_如何学Conal): </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-known attributes/binds/multiple instances/xpath expressions that will cause the control to always be displayed?
To be honest, XForms doesn't handle this optional element situation very well. See this related discussion on Micah's blog. A not-so-satisfying workaround is to add empty elements for those optional elements after you retrieve the data from eXist, and to remove them before saving the data back to eXist.
This situation has already been discussed by the W3C Forms Group: http://www.w3.org/2010/07/07-forms-minutes.html Using new MIP could help to implement this in XSLTForms.
-Alain
精彩评论