XForms 1.0 推荐标准 第3部分
TransWiki - an Open Translation Project(OTP)
目录 | 第1部分 | 第2部分 | 第3部分 | 第4部分 | 第5部分 | 第6部分 | 第7部分 | 第8部分 | 第9部分 | 第10部分 | 第11部分 | 第12部分 | 第13部分 | 附录A | 附录B | 附录C | 附录D | 附录E | 附录F | 附录G | 附录H | 附录I | 附录J |
3 Document Structure 文档结构
XForms 1.0是基于XML[XML 1.0 (http://www.w3.org/TR/2003/REC-xforms-20031014/sliceB.html#ref-xml-1.0)]的应用,其可以在其他的XML词汇中使用,特别是在未来版本的可扩展超文本标记语言[XHTML 1.0 (http://www.w3.org/TR/2003/REC-xforms-20031014/sliceB.html#ref-xhtml-1.0)]中使用。XForms通常需要类似这样的宿主语言host language (http://www.w3.org/TR/2003/REC-xforms-20031014/slice13.html#def-host-language)。本章将要讨论的是XForms的结构,以及XForms支持的其他的文档类型。
XForms 1.0 is an application of XML [XML 1.0 (http://www.w3.org/TR/2003/REC-xforms-20031014/sliceB.html#ref-xml-1.0)] and has been designed for use within other XML vocabularies—in particular within a future version of XHTML [XHTML 1.0 (http://www.w3.org/TR/2003/REC-xforms-20031014/sliceB.html#ref-xhtml-1.0)]. XForms always requires such a host language (http://www.w3.org/TR/2003/REC-xforms-20031014/slice13.html#def-host-language). This chapter discusses the structure of XForms that allow XForms to be used with other document types.
3.1 The XForms Namespace XForms命名空间
XForms的命名空间使用以下统一资源标识符:
http://www.w3.org/2002/xforms。
XForms处理器必须通过XML命名空间机制[XML Names (http://www.w3.org/TR/2003/REC-xforms-20031014/sliceB.html#ref-xml-names)]来识别元素和属性。
The XForms namespace has the URI: http://www.w3.org/2002/xforms.
XForms Processors must use the XML namespaces mechanism [XML Names (http://www.w3.org/TR/2003/REC-xforms-20031014/sliceB.html#ref-xml-names)] to recognize elements and attributes from this namespace.
3.2 XForms Core Attribute Collections XForms核心属性集合
3.2.1 Common Attributes 通用属性
通用属性集合被用于XForms命名空间中定义的每一个元素。
anyAttribute
- 所有的XForms元素都允许使用外部属性。
宿主语言必须允许在每个XForms元素上使用xsd:ID类型的属性。
The Common Attribute Collection applies to every element in the XForms namespace.
anyAttribute
- Foreign attributes are allowed on all XForms elements.
A host language must permit an attribute of type xsd:ID on each XForms element.
3.2.2 Linking Attributes 链接属性
链接属性集合应用于XForms中需要链接到远程资源的元素。
src
- src属性用于指定能够自动获取的URI。
注意:
- 由于链接属性的URI是由XML Schema中数据类型xsd:anyURI所定义的,因此诸如国际化、空白节点提示等在[XML Schema part 2 (http://www.w3.org/TR/2003/REC-xforms-20031014/sliceB.html#ref-xschema-2)]描述的优势均可在XForms中得到应用。
- 虽然[XML Base (http://www.w3.org/TR/2003/REC-xforms-20031014/sliceB.html#ref-xml-base)]处理器被强烈推荐,但是链接中相对URI的行为还是由宿主语言 (http://www.w3.org/TR/2003/REC-xforms-20031014/slice13.html#def-host-language)决定。
注意:
- XForms工作组一直在追踪HTML工作组对链接结构的描述方法。
The Linking Attributes Collection applies to XForms elements which include a link to a remote resource.
src
The src attribute assigns a URI to be automatically retrieved.
Note:
Since linking attribute URIs are defined in terms of the XML Schema datatype xsd:anyURI, the same internationalization benefits and white space cautions apply as discussed in [XML Schema part 2 (http://www.w3.org/TR/2003/REC-xforms-20031014/sliceB.html#ref-xschema-2)].
Behavior of relative URIs in links is determined by the host language (http://www.w3.org/TR/2003/REC-xforms-20031014/slice13.html#def-host-language), although [XML Base (http://www.w3.org/TR/2003/REC-xforms-20031014/sliceB.html#ref-xml-base)] processing is strongly recommended.
Note:
The XForms Working Group is tracking with the HTML Working Group on a method of describing link structures.
3.2.3 Single-Node Binding Attributes 单节点绑定属性
- 下面的属性描述了如何使用XPath表达式去定义一个表单控件或活动与数据实例的绑定关系。
ref
- 绑定表达式 (http://www.w3.org/TR/2003/REC-xforms-20031014/slice13.html#def-binding-expression)通常使用XPath,当使用bind属性时,ref属性将不起作用。
model
- XForms模块选择器。指明与XForms模块相关联的绑定元素的ID。当前绑定的元素使用bind属性时,该属性将不起作用。关于XForms模块上下文定义的规则请参考7.4 Evaluation Context
bind
- 请参考bind元素。
- ref或bind是必需的。当使用bind,节点由被引用的bind所决定。
- 当XForms处理引擎遇到model IDREF的值指向的ID并不是model元素时,或者bind IDREF的值指向的ID并不是bind元素时将会抛出异常(4.5.1 The xforms-binding-exception Event)。
第一节点原则:当单节点绑定属性被用于长度大于1的节点集,起作用的是按照文档顺序,节点集中的第一个节点。
The following attributes define a binding between a form control or an action and an instance data node defined by an XPath expression.
ref
Binding expression (http://www.w3.org/TR/2003/REC-xforms-20031014/slice13.html#def-binding-expression) interpreted as XPath. This attribute has no meaning when a bind attribute is present.
model
XForms Model selector. Specifies the ID of an XForms Model to be associated with this binding element. This attribute has no meaning for the current binding element when a bind attribute is present. Rules for determining the context XForms Model are located at 7.4 Evaluation Context.
bind
Reference to a bind element.
One of ref or bind is required. When bind is used, the node is determined by the referenced bind.
It is an exception (4.5.1 The xforms-binding-exception Event) if the XForms Processor encounters a model IDREF value that refers to an ID not on a model element, or a bind IDREF value that refers to an ID not on a bind element.
First-node rule: When a Single-Node Binding attribute selects a node-set of size > 1, the first node in the node-set, based on document order, is used.
3.2.4 Node-Set Binding Attributes 节点集绑定属性
该属性定义了表单控件或行为与节点集之间通过XPath表达式定义的绑定关系。
节点集
绑定表达式 (http://www.w3.org/TR/2003/REC-xforms-20031014/slice13.html#def-binding-expression)采用XPath作为描述语言。当使用bind属性时,该属性将不起作用。
模型
XForms模型选择器。指定XForms模型的ID与其绑定元素进行关联,但并不需要显示。XForm模型上下文定义规则请参阅7.4 Evaluation Context.
绑定元素参考。
节点集或绑定是必需的。当时使用绑定时,节点集由被引用的绑定决定。
如果模型的IDREF 值引用了id而非模型元素或绑定IDREF 值引用id而非绑定元素则XForm处理器将抛出例外。(4.5.1 The xforms-binding-exception Event)
The following attributes define a binding between a form control or an action and a node-set defined by the XPath expression.
nodeset
Binding expression (http://www.w3.org/TR/2003/REC-xforms-20031014/slice13.html#def-binding-expression) interpreted as XPath. This attribute has no meaning when a bind attribute is present.
model
XForms Model selector. Specifies the ID of an XForms Model to be associated with this binding element. This attribute has no meaning for the current binding element when a bind attribute is present. Rules for determining the context XForms Model are located at 7.4 Evaluation Context.
bind
Reference to a bind element.
One of nodeset or bind is required. When bind is used, the node-set is determined by the referenced bind.
It is an exception (4.5.1 The xforms-binding-exception Event) if the XForms Processor encounters a model IDREF value that refers to an id not on a model element, or a bind IDREF value that refers to an id not on a bind element.
3.2.5 Model Item Property Attributes
此部分主要是对于每个模型项目特性定义一个与其模型项目相同属性6.1 模型项目属性定义。
This collection contains one attribute for each model item property, with an attribute name exactly matching the name of the model item property, as defined in 6.1 Model Item Property Definitions.
3.3 The XForms Core Module
XForms核心模块定义了XForms元素的主要结构,内部的文档结构设计。在这个模块中包含的元素和属性如下:
元素 | 属性 | 可包含模块 |
|---|---|---|
model (http://www.w3.org/TR/2003/REC-xforms-20031014/slice3.html#structure-model) | Common (http://www.w3.org/TR/2003/REC-xforms-20031014/slice3.html#structure-attrs-common), Events (http://www.w3.org/TR/2003/REC-xforms-20031014/slice10.html#action-xmlevents), functions (QNameList), schema (list of xsd:anyURI) | (instance|xsd:schema| submission|bind|Action (http://www.w3.org/TR/2003/REC-xforms-20031014/slice10.html#action-xmlevents))* |
instance (http://www.w3.org/TR/2003/REC-xforms-20031014/slice3.html#structure-model-instance) | Common (http://www.w3.org/TR/2003/REC-xforms-20031014/slice3.html#structure-attrs-common), Linking (http://www.w3.org/TR/2003/REC-xforms-20031014/slice3.html#structure-attrs-link) | (ANY) |
submission (http://www.w3.org/TR/2003/REC-xforms-20031014/slice3.html#structure-model-submission) | Common (http://www.w3.org/TR/2003/REC-xforms-20031014/slice3.html#structure-attrs-common), ref (binding-expression (http://www.w3.org/TR/2003/REC-xforms-20031014/slice13.html#def-binding-expression)), bind (xsd:IDREF), action (xsd:anyURI), method ("post"|"get"|"put"|"form-data-post"|"urlencoded-post"|qname-but-not-ncname), version (xsd:NMTOKEN), indent (xsd:boolean), mediatype (xsd:string), encoding (xsd:string), omit-xml-declaration (xsd:boolean), standalone (xsd:boolean), cdata-section-elements (QNameList), replace ("all"|"instance"|"none"|qname-but-not-ncname), separator (';' | '&'), includenamespaceprefixes (xsd:NMTOKENS) | Action (http://www.w3.org/TR/2003/REC-xforms-20031014/slice10.html#action-xmlevents)* |
bind (http://www.w3.org/TR/2003/REC-xforms-20031014/slice3.html#structure-bind-element) | Common (http://www.w3.org/TR/2003/REC-xforms-20031014/slice3.html#structure-attrs-common), 模型项目属性 (http://www.w3.org/TR/2003/REC-xforms-20031014/slice3.html#structure-attrs-mip), 节点集(model-binding-expression (http://www.w3.org/TR/2003/REC-xforms-20031014/slice13.html#def-model-binding-expression)) | (bind)* |
The XForms Core Module defines the major structural elements of XForms, intended for inclusion in a containing document. The elements and attributes included in this module are:
Element | Attributes | Minimal Content Model |
|---|---|---|
model (http://www.w3.org/TR/2003/REC-xforms-20031014/slice3.html#structure-model) | Common (http://www.w3.org/TR/2003/REC-xforms-20031014/slice3.html#structure-attrs-common), Events (http://www.w3.org/TR/2003/REC-xforms-20031014/slice10.html#action-xmlevents), functions (QNameList), schema (list of xsd:anyURI) | (instance|xsd:schema| submission|bind|Action (http://www.w3.org/TR/2003/REC-xforms-20031014/slice10.html#action-xmlevents))* |
instance (http://www.w3.org/TR/2003/REC-xforms-20031014/slice3.html#structure-model-instance) | Common (http://www.w3.org/TR/2003/REC-xforms-20031014/slice3.html#structure-attrs-common), Linking (http://www.w3.org/TR/2003/REC-xforms-20031014/slice3.html#structure-attrs-link) | (ANY) |
submission (http://www.w3.org/TR/2003/REC-xforms-20031014/slice3.html#structure-model-submission) | Common (http://www.w3.org/TR/2003/REC-xforms-20031014/slice3.html#structure-attrs-common), ref (binding-expression (http://www.w3.org/TR/2003/REC-xforms-20031014/slice13.html#def-binding-expression)), bind (xsd:IDREF), action (xsd:anyURI), method ("post"|"get"|"put"|"form-data-post"|"urlencoded-post"|qname-but-not-ncname), version (xsd:NMTOKEN), indent (xsd:boolean), mediatype (xsd:string), encoding (xsd:string), omit-xml-declaration (xsd:boolean), standalone (xsd:boolean), cdata-section-elements (QNameList), replace ("all"|"instance"|"none"|qname-but-not-ncname), separator (';' | '&'), includenamespaceprefixes (xsd:NMTOKENS) | Action (http://www.w3.org/TR/2003/REC-xforms-20031014/slice10.html#action-xmlevents)* |
bind (http://www.w3.org/TR/2003/REC-xforms-20031014/slice3.html#structure-bind-element) | Common (http://www.w3.org/TR/2003/REC-xforms-20031014/slice3.html#structure-attrs-common), Model Item Properties (http://www.w3.org/TR/2003/REC-xforms-20031014/slice3.html#structure-attrs-mip), nodeset (model-binding-expression (http://www.w3.org/TR/2003/REC-xforms-20031014/slice13.html#def-model-binding-expression)) | (bind)* |
如上表格所显示的内容,它允许使用XForms 行为模块中定义元素(例如model,submission)。
在包含文档中,这些结构化的元素通常不是可视化的。
XForms处理器必须忽略外部命名空间的属性,并根据3.4 The XForms MustUnderstand Module 规则处理不可识别的外部命名空间的元素。
必须记录符合文档内容中定义的符合外部命名规则的元素。
Elements defined in the XForms Actions module, when that module is included, are also allowed in the content model of model and submission, as shown above.
Within the containing document, these structural elements are typically not rendered.
The XForms Processor must ignore any foreign-namespaced attributes that are unrecognized, and must process unrecognized foreign-namespaced elements according to the 3.4 The XForms MustUnderstand Module rules.
Note that the presence of foreign namespaced elements is subject to the definition of the containing document profile.
3.3.1 The model Element模型元素
模型元素是表单的特征说明,并作为其他XForms模型元素的容器。在元素内部并不限定可容纳的元素的数量。
公共属性:公共 (http://www.w3.org/TR/2003/REC-xforms-20031014/slice3.html#structure-attrs-common), 事件 (http://www.w3.org/TR/2003/REC-xforms-20031014/slice10.html#action-xmlevents)
这里可以使用XML事件属性是为了便于creating observers。但此元素并非XForm Action,而且没有预先定义基础事件行为。
特殊属性:
函数
schema
This element represents a form definition and is used as a container for elements that define the XForms Model. No restriction is placed on how many model elements may exist within a containing document.
Common Attributes: Common (http://www.w3.org/TR/2003/REC-xforms-20031014/slice3.html#structure-attrs-common), Events (http://www.w3.org/TR/2003/REC-xforms-20031014/slice10.html#action-xmlevents)
Attributes from XML Events are allowed on this element to facilitate creating observers. This element is not an XForms Action, and has no predefined behavior event-based behavior.
专用属性:
functions:
XForms模型要求使用XPath扩展函数可选列表中的函数(使用QNames表示)。关于如何使用这一属性请参阅7.12扩展函数。
schema:
定义了从模型元素链接到外部XML Schema文档的xsd:anyURI可选列表。XForms处理器必需处理这个属性中列出的所有schema。每个XForms模型中,一个命名空间仅能使用一个schema,不管是内部的还是外部的。
注意:schema可能包含指向位于容器文档其他部位元素的URI片段,例如“#myschema”.
Special Attributes:
functions
Optional space-separated list of XPath extension functions (represented by QNames) required by this XForms Model. Guidance on the use of this attribute is at 7.12 Extension Functions.
schema
Optional list of xsd:anyURI links to XML Schema documents outside this model element. The XForms Processor must process all Schemas listed in this attribute. Within each XForms Model, there is a limit of one Schema per namespace declaration, including inline and linked Schemas.
Note:
The schema list may include URI fragments referring to elements located elsewhere in the containing document; e.g. "#myschema".
下面的例子演示了XForms默认命名空间下模型元素的使用:
This example shows a simple usage of model, with the XForms namespace defaulted:
Example: Model
<model id="Person" schema="MySchema.xsd">
<instance src="http://example.com/cgi-bin/get-instance" />
...
</model>
3.3.2 The instance Element
This optional element contains or references initial instance data.
Common Attributes: Common (http://www.w3.org/TR/2003/REC-xforms-20031014/slice3.html#structure-attrs-common)
Special Attributes:
Linking Attributes
Optional link to externally defined initial instance data. If the link traversal fails, it is treated as an exception (4.5.2 The xforms-link-exception Event).
If both an attribute and inline content are provided, the linked version takes precedence as described at 4.2.1 The xforms-model-construct Event.
If the initial instance data is given by a link, then the instance data is formed by creating an XPath data model of the linked resource.
If the initial instance data is given by inline content, then instance data is obtained by first creating a detached copy of the inline content (including namespaces inherited from the enveloping ancestors), then creating an XPath data model over the detached copy. The detached copy must consist of content that would be well-formed XML if it existed in a separate document. Note that this restricts the element content of instance to a single child element.
Note:
XForms authors who need additional control over the serialization of namespace nodes can use the includenamespaceprefixes attribute on the submission element.
3.3.3 The submission Element
This element represents declarative instructions on what to submit, and how. Details of submit processing are described at 11 Submit.
Common Attributes: Common (http://www.w3.org/TR/2003/REC-xforms-20031014/slice3.html#structure-attrs-common)
Special Attributes:
bind
Optional reference to a bind element. When present, the binding reference on this attribute is used in preference to any binding reference from the ref attribute.
ref
Optional selector binding expression (http://www.w3.org/TR/2003/REC-xforms-20031014/slice13.html#def-binding-expression) enabling submission of a portion of the instance data. The selected node, and all descendants, are selected for submission. The default value is "/".
action
Required destination URI for submitting instance data.
method
Required attribute specifying the protocol to be used to transmit the serialized instance data. There is no default value.
version
Optional attribute specifying the version of XML to be serialized.
indent
Optional attribute specifying whether the serializer should add extra white space nodes for readability.
mediatype
Optional attribute specifying the mediatype for XML instance serialization. Authors should ensure that the type specified is compatible with application/xml.
encoding
Optional attribute specifying an encoding for serialization.
omit-xml-declaration
Optional attribute specifying whether to omit the XML declaration on the serialized instance data.
standalone
Optional attribute specifying whether to include a standalone declaration in the serialized XML.
cdata-section-elements
Optional attribute specifying element names to be serialized with CDATAsections.
replace
Optional attribute specifying how the information returned after submit should be applied. In the absence of this attribute, "all" is assumed.
separator
Optional attribute specifying the separator character between name/value pairs in urlencoding. The default value is ';'.
includenamespaceprefixes
Optional attribute providing control over namespace serialization. If absent, all namespace nodes present in the instance data are considered for serialization. If present, specifies list of namespace prefixes to consider for serialization, in addition to those visibly utilized. As in [Exc-C14N (http://www.w3.org/TR/2003/REC-xforms-20031014/sliceB.html#ref-Exc-C14N)], the special value #default specifies the default namespace.
The following examples show how various options on element submission can affect serialization as application/xml. Given the following XForms fragment:
<xforms:model xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:my="http://ns.example.org/2003">
<xforms:instance>
<qname xmlns="">my:sample</qname>
</xforms:instance>
<xforms:submission method="post" action="..."/>
</xforms:model>
Note that the includenamespaceprefixes attribute is not present, which causes all namespace nodes to be serialized, resulting in the following serialized instance data:
<qname xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:my="http://ns.example.org/2003">my:sample</qname>
In particular, note that the XForms namespace has been serialized. To prevent this example from including the unneeded XForms namespace while maintaining the needed my prefix, includenamespaceprefixes="my" must be added to the submission element. When this attribute is present, the author takes responsibility to list all namespace prefixes not visibly utilized by the submitted instance data.
The following attributes correspond (in spelling, processing, and default values) to attributes on the output element of [XSLT 1.0 (http://www.w3.org/TR/2003/REC-xforms-20031014/sliceB.html#ref-xslt)], with the exception of using xsd:boolean to replace "yes"|"no":
version
indent
encoding
omit-xml-declaration
cdata-section-elements
Note:
The following XSLT attributes have no counterpart in XForms:
doctype-system
doctype-public
Elements defined in the XForms Actions module, when that module is included, are also allowed in the content model of submission.
3.3.4 The bind Element
Element bind selects a node-set selected from the instance data (http://www.w3.org/TR/2003/REC-xforms-20031014/slice13.html#def-instance-data) with a model binding expression (http://www.w3.org/TR/2003/REC-xforms-20031014/slice13.html#def-model-binding-expression) in the nodeset attribute. Other attributes on element bind encode model item properties (http://www.w3.org/TR/2003/REC-xforms-20031014/slice13.html#def-model-item-property) to be applied to each node in the node-set. When bind has an attribute of type xsd:ID, the bind then associates that identifier with the selected node-set.
Common Attributes: Common (http://www.w3.org/TR/2003/REC-xforms-20031014/slice3.html#structure-attrs-common), Model Item Properties (http://www.w3.org/TR/2003/REC-xforms-20031014/slice3.html#structure-attrs-mip)
Special Attributes:
nodeset
A model binding expression (http://www.w3.org/TR/2003/REC-xforms-20031014/slice13.html#def-model-binding-expression) that selects the set of nodes on which this bind operates, as defined in 7.5.2 Model Binding Expressions.
When additional nodes are added through action insert, the newly added nodes are included in any node-sets matched by binding expressions—see action insert in 9.3.5 The insert Element.
See 7.4 Evaluation Context for details on how binding affects the evaluation context.
3.4 The XForms MustUnderstand Module
Certain elements, such as extension or foreign namespaced elements defined in a host language (http://www.w3.org/TR/2003/REC-xforms-20031014/slice13.html#def-host-language) might be critical to the operation of a particular form. To indicate this, the MustUnderstand module defines a single attribute that can be used on any element.
Element | Attributes | Minimal Content Model |
|---|---|---|
ANY | xforms:mustUnderstand (xsd:boolean) | n/a |
It is a terminating error that must be reported to the user if an element is marked mustUnderstand="true", and the XForms Processor does not have an implementation available for processing the element.
3.5 The XForms Extension Module
There are many different ways a host language (http://www.w3.org/TR/2003/REC-xforms-20031014/slice13.html#def-host-language) might include XForms. One approach uses only well-formed processing, disregarding validation. Another case uses strict validation, for example XHTML 1.0, in which only predefined elements are allowed. Another common approach is to allow unregulated content in a few selected places. A host language that chooses this option can use the Extension module.
Element | Attributes | Minimal Content Model |
|---|---|---|
extension (http://www.w3.org/TR/2003/REC-xforms-20031014/slice3.html#structure-extension) | Common (http://www.w3.org/TR/2003/REC-xforms-20031014/slice3.html#structure-attrs-common) | ANY |
3.5.1 The extension Element
Optional element extension is a container for application-specific extension elements from any namespace other than the XForms namespace. This specification does not define the processing of this element.
Common Attributes: Common (http://www.w3.org/TR/2003/REC-xforms-20031014/slice3.html#structure-attrs-common)
For example, RDF metadata could be attached to an individual form control as follows:
<input ref="dataset/user/email" id="email-input">
<label>Enter your email address</label>
<extension>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="#email-input">
<my:addressBook>personal</my:addressBook>
</rdf:Description>
</rdf:RDF>
</extension>
</input>


