允许对可选 XML 元素进行 XForm 控件

发布于 2024-10-10 03:28:00 字数 915 浏览 0 评论 0原文

在设计 XML 数据库的 XForm 接口(使用 eXist 和 XSLTForms)时,我希望包含一个可选元素的输入控件。 XML 数据记录已存在,其中一些包含可选元素,而另一些则不包含。为了更新记录,我使用现有的 XML 记录作为模型实例。问题是,当可选元素不存在时,表单控件不会显示,这是合乎逻辑的,但当用户想要向可选元素添加数据时,就会出现问题。

更明确地说,这里有一个示例数据记录 data.xml:

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

具有 RNC 模式:

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

XForms 模型:

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

和控件:

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

问题在于“Notes”输入控件根本不显示。

一个明显的解决方案是添加一个触发按钮,以允许用户在需要时插入元素,但最好只显示输入控件,并且为空。

我的问题是:是否存在一些鲜为人知的属性/绑定/多个实例/xpath 表达式的微妙组合会导致控件始终显示?

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-known attributes/binds/multiple instances/xpath expressions that will cause the control to always be displayed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

指尖凝香 2024-10-17 03:28:00

老实说,XForms 不能很好地处理这种可选元素的情况。请参阅 Micah 博客上的此相关讨论。一个不太令人满意的解决方法是在从 eXist 检索数据后为这些可选元素添加空元素,并在将数据保存回 eXist 之前删除它们。

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.

羞稚 2024-10-17 03:28:00

W3C 表单小组已讨论过这种情况:http://www .w3.org/2010/07/07-forms-mines.html
使用新的 MIP 有助于在 XSLTForms 中实现这一点。

-阿兰

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文