我正在开发一个嵌入Orbeon XForms渲染器的应用程序。我用它来生成XHTML而不是HTML。我们有一个使用2个自定义XBL组件的表单。
我们传递给orbeon的XHTML似乎是正确的。但是Orbeon生成的XHTML包含<body>
元素上xbl名称空间的定义两次。这可以防止它被解析为有效的XML。
这实际上是一个非常复杂的形式,我不能在这里发布,但这个问题的重要部分是:
<xhtml:html
xmlns:exf="http://www.exforms.org/exf/1-0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:f="http://orbeon.org/oxf/xml/formatting"
xmlns:fw="http://orionhealth.com/forms/widgets" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<xhtml:head>
<!-- Lots of stuff -->
<xbl:xbl xmlns:xbl="http://www.w3.org/ns/xbl">
<xbl:script src="...."/>
<xbl:binding id="fw-autocomplete" element="fw|autocomplete">
<xbl:template>
<!-- Lots of stuff -->
</xbl:template>
</xbl:binding>
</xbl:xbl>
<xbl:xbl xmlns:xbl="http://www.w3.org/ns/xbl">
<xbl:script src="...."/>
<xbl:binding id="fw-datetime" element="fw|datetime">
<xbl:template>
<!-- Lots of stuff -->
</xbl:template>
</xbl:binding>
<xbl:binding id="fw-date" element="fw|date">
<xbl:template>
<!-- Lots of stuff -->
</xbl:template>
</xbl:binding>
<xbl:binding id="fw-partial-date" element="fw|partial-date">
<xbl:template>
<!-- Lots of stuff -->
</xbl:template>
</xbl:binding>
</xbl:xbl>
</xhtml:head>
<xhtml:body id="body">
<!-- Lots of stuff -->
</xhtml:body>
</xhtml:html>
值得注意的是,虽然两个XBL组件都已定义,但它们实际上都没有在文档正文中使用。 Orbon产生的XHTML(再次简化)是:
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns:exf="http://www.exforms.org/exf/1-0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:f="http://orbeon.org/oxf/xml/formatting"
xmlns:fw="http://orionhealth.com/forms/widgets"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xxforms:noscript="true">
<head>
<!-- Lots of Stuff -->
</head>
<body xmlns:xbl="http://www.w3.org/ns/xbl" xmlns:xbl="http://www.w3.org/ns/xbl"
id="body"
class="yui-skin-sam">
<!-- Lots of Stuff -->
</body>
</html>
请注意正文标记上的重复xmlns:xbl="http://www.w3.org/ns/xbl"
。
谷歌搜索我还没有发现任何关于这个问题的内容,是否有人知道会导致这个问题以及我能解决什么问题?
我注意到如果我在<xhtml:html>
元素而不是每个<xbl:xbl>
元素上定义xbl前缀,这似乎不是问题,而且Orbeon产生的XHTML只有这个前缀在<xhtml:html>
元素上定义一次。
答案 0 :(得分:1)
Orbeon使用XSLT将XForms文档转换为XHTML。 XSLT spec说:
创建的元素节点还将具有样式表树中元素节点上存在的命名空间节点的副本,但字符串值为XSLT命名空间URI(http://www.w3.org/1999/XSL/Transform)的任何命名空间节点除外,声明为扩展名称空间的名称空间URI(请参阅[14.1扩展元素]),或指定为排除名称空间的名称空间URI。
这意味着源文档中的两个名称空间声明必须按照规范进行复制,而不管它们在结果文档中的相关性。
an unrelated question中还讨论了在根节点上定义命名空间时遇到的解决方案。
在XSLT 2.0中,您可以将属性copy-namespaces="no"
添加到xsl:copy
或xsl:copy-of
元素。