xforms“实例命名空间”问题
我正在创建一个 Xform,它读取 XML 文档并创建一个用于更新文档的输入表单。但是,显然由于命名空间问题,我的 Xpath 表达式都无法解析。当实例文件没有命名空间时,我的表单在简单实例上工作正常。 但是,我需要命名空间支持。
我的实例文件有一个命名空间“ai:inventory”。
我正在引用实例数据
我应该在哪里声明我的命名空间的前缀“ai”,以便我的 XPath 表达式可以找到适当的元素? /ai:库存/产品?
我尝试在 html 开始标记中创建前缀...但这没有帮助。
谢谢,
I am creating an Xform that reads an XML document and creates an input form for updating the document. However, apparently due to a namespace issue none of my Xpath expressions resolve.My form works fine on a simple instance when the instance file has no namespace.
However, I need the namespace support.
My instance file has a namespace "ai:inventory."
I am referencing the instance data
Where should I be declaring the prefix "ai" for my namespace so that my XPath expressions can find the appropriate elements? /ai:inventory/products ?
I've tried creating the prefix in the html opening tag... that didn't help.
thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
XForms 实例本身就是一个 XML 文档,因此您应该为表单中的每个实例包含适当的名称空间声明:
如果您的实例是内联的(而不是外部资源),有些处理器将正确评估 XPath,但是我不建议依赖这种行为。
An XForms instance is an XML document in its own right, so you should include appropriate namespace declarations for every instance in your form:
There are some processors that will evaluate the XPath correctly if your instance is inline (rather than an external resource), but I wouldn't recommend relying on that behaviour.
一般来说,命名空间声明适用于当前元素和所有降序元素。如果您需要在模型和视图中使用相同的命名空间,那么 html 标签是一个不错的选择。像这样的事情:
请记住,如果您在实例中使用非命名空间元素并且还使用 XHTML 作为默认命名空间,那么您需要使用 xmlns="" 重新声明默认命名空间,如示例所示。
Generally namespace declaration applies to current element and all descending elements. If you need to use the same namespace both in model and view, then html tag is a good choice. Something like this:
Keep in mind that if you use non-namespaced elements in instance and also use XHTML as your default namespace, then you need to redeclare default namespace with xmlns="", as in example.
两个答案均已更正。但是,我发现我的问题与使用 xsltforms xsl 样式表呈现我的 xform 有关。当我切换到 Orbeon 时,一切正常。
Both answers were corrected. However, I found that my issue was related to using the xsltforms xsl stylesheet to render my xform. when i switched to orbeon, everything worked fine.