XForms教程 [转]

XForms教程

XForm是下一代HTML表单。在我们的XForm教程中,你将学习如何在程序中使用XForms。

内容目录

XFroms 介绍
This chapter explains what XForms is and how it differs from HTML forms.
解释了什么是XForms已经它与HTML里form的区别

XForms 模型
This chapter describes the XForms model.
这章介绍了XForms模型

XForms 命名空间
This chapter describes the XForms namespace.
描述XForms的命名空间

XForms 实例
This chapter demonstrates an XForms example.
演示XForms举例

XForms 和 XPath
This chapter describes how XForms uses XPath to address data.
怎样在XForms中使用XPath来应对数据

XForms Input
This chapter describes the XForms user interface controls.
XForms的用户控件界面

XForms Data types
This chapter describes the data types used in XForms.
在XForms中的数据类型

XForms 属性
This chapter describes XForms properties..
XForms的相关属性

XForms Actions
This chapter describes XForms actions..

XForms 函数
XForms has some predefined functions. But you can also call functions defined in scripts.
XForm有一些预先确定的函数。但你还是可以调用脚本中定义的函数

XForms 介绍
w3pop.com / 2006-09-19

p.gif XForms 模型 n.gif

XForms is the next generation of HTML forms.
XForms是HTML窗口的下一代

XForms uses XML to create input forms on the Web.
XForms使用XML语言创建在网页上的输入窗口


What You Should Already Know
你应该已经了解的是

Before you continue you should have a basic understanding of the following:
在继续之前你应该对以下概念有个基本认识:

  • HTML
  • HTML Forms
  • XHTML
  • XML

If you want to study these subjects first, find the tutorials on our Home Page.
如果想先学这些内容,可以在我们主页找到相关教程


What Is XForms?
什么是XForms?

  • XForms is the next generation of HTML forms
    • XForms是HTML窗口的“下一代”
  • XForms is richer and more flexible than HTML forms
    • XForms比HTML窗口更加丰富和灵活
  • XForms will be the forms standard in XHTML 2.0
    • XForms将会在XHTML 2.0 里成为窗口标准
  • XForms is platform and device independent
    • XForms是平台而且是部件独立的
  • XForms separates data and logic from presentation
    • XForms在将从表达中分离出数据和逻辑值
  • XForms uses XML to define form data
    • XForms用 XML语言定义窗口数据
  • XForms stores and transports data in XML documents
    • XForms在XML文档中储存和传送数据
  • XForms contains features like calculations and validations of forms
    • XForms容纳像窗口的计算和确认特征。
  • XForms reduces or eliminates the need for scripting
    • XForms可以减少或免除编写脚本的需要
  • XForms is a W3C Recommendation
    • XForms是W3C的参考标准

XForms Is The Successors Of HTML Forms
XForms是HTML窗口的接替者

Forms are an important part of many web applications today. An HTML form makes it possible for web applications to accept input from a user. 
窗口是如今许多网页应用软件中重要的一部分。一个HTML窗口使网页应用软件可以接受使用者的输入。

Today, ten years after HTML forms became a part of the HTML standard, web users do complex transactions that are starting to exceed the limitations of standard HTML forms.
今天,也就是HTML窗口变成HTML标准一部分的十年之后,网页使用者做了复杂的处理,开始突破标准HTML窗口的局限。

XForms provides a richer, more secure, and device independent way of handling web input. We should expect future web solutions to demand the use of XForms-enabled browsers (All future browsers should support XForms).
XForms提供了更丰富,更可靠以及部件独立的方式来处理网页输入。我们应该期待将来的网页处理会要求所有的浏览器都应该支持XForms


XForms Separate Data From Presentation
XForms从表达中分离出数据

XForms uses XML for data definition and HTML or XHTML for data display. XForms separates the data logic of a form from its presentation. This way the XForms data can be defined independent of how the end-user will interact with the application.
XForms用XML进行数据定义,用HTML或XHTML进行数据展示。XForms 从窗口的表达中分离出数据逻辑值。这样XForms数据就可以被单独定义,不管最后的使用者怎样和应用程序进行交互。


XForms Uses XML To Define Form Data
XForms使用XML定义窗口数据

With XForms, the rules for describing and validating data are expressed in XML.
XForms里,描述和检验数据的规则是以XML形式表达的。


XForms Uses XML To Store And Transport Data
XForms用XML储存和传送数据。

With XForms, the data displayed in a form are stored in an XML document, and the data submitted from the form, are transported over the internet using XML.
XForms里,展示在窗口里的数据是储存在一份XML文档里的,并且由窗口递交的数据是以XML形式在网络上被传送的。

The data content is coded in, and transported as Unicode bytes.
数据内容是统一字符编码的,并以统一字符编码(Unicode bytes)传送的。


XForms Is Device Independent
XForms是部件独立的

Separating data from presentation makes XForms device independent, because the data model can be used for all devices. The presentation can be customized for different user interfaces, like mobile phones, handheld devices, and Braille readers for the blind.
从表达中分离数据使得XForms部件独立,因为数据模式可以被所有部件使用。表达可以用户化为不同的使用者界面,像手机,掌上部件,和为盲人设计的盲人阅读器。

Since XForms is device independent and based on XML, it is also possible to add XForms elements directly into other XML applications like VoiceXML (speaking web data), WML (Wireless Markup Language), and SVG (Scalable Vector Graphics).
因为XForms是部件独立而且是以XML为基础的,所以可以直接把XForms元素添加给像VoiceXML(语音网页数据speaking web data)。WML(无线标记语言Wireless Markup Language),和SVG(可升级矢量图形Scalable Vector Graphics)这类的XML应用软件。


XForms Is A W3C Recommendation
XForms是W3C的参考标准

XForms 1.0 became a W3C Recommendation in October 2003.
XForms 1.0在2003年10月成为W3C的参考标准。

The official W3C recommendation can be found at this link:
在这个链接上可以找到官方XForms 1.0参考标准

http://www.w3.org/TR/xforms/

XForms 模型
w3pop.com / 2006-09-21

p.gifXForms 介绍 XForms 命名空间 n.gif

The XForms model defines a  template for the data to be collected in a form.
XForms模型为窗口数据的采集定义了模板。


The XForms Framework
XForms框架

The purpose of an HTML form is to collect data. XForms has the same purpose.
HTML窗口用于采集数据。XForms也有相同的作用。

With XForms, input data is described in two different parts:
在XForms里,输入数据在两个不同部分里被描述

  • The XForm model (to describe the data and the logic)
    XForm模型(为了描述数据和逻辑值)
  • The XForm user interface (to display and input the data)
    • XForm使用者界面(为了展示和输入数据)

The XForms model defines what the form is, what data it contains, and what it should do.
XForms model(XForms模型)定义了窗口是什么,数据里有什么和数据该干些什么。

The XForms user interface defines the input fields and how they should be displayed. 
XForms user interface(XForms使用者界面)定义了输入区域以及它们该怎样被展示。


The XForms Model

The XForms model is used to describe the data.
XForms模型用于描述数据

The data model is an instance (a template) of an XML document.
数据模式是一份XML文档的一个情景(一块模板)

The XForms model defines a data model inside a <model> element:
XForms模型在<model>元素里定义了一个数据模式:

<model>
<instance>

<person>
<fname/>
<lname/>
</person>
</instance>
<submission id="form1"

action="submit.asp"
method="get"/>
</model>

From the example above, you can see that the XForms model uses an <instance> element to define the XML template for data to be collected, and a <submission> element to describe how to submit the data.
上述例子中,你可以看到XForms模型使用<instance>元素为将采集的数据定义了XML模板,还有用<submission>元素来描述怎样提交数据。

The XForms model does not say anything about the visual part of the form (the user interface).
XForms没有描述任何关于窗口的可视部分(使用者界面)。


XForms Namespace
XForms名称空间(namespace)

If you are missing the XForms namespace in these examples, or if you don't know what a namespace is, it will be introduced in the next chapter.
如果在这些例子里你错过了学习XForms名称空间,或者你不知道什么是名称空间,在接下来的例子里将有介绍。


The <instance> Element
<instance>元素

The XForms model uses an <instance> element to define the data to be collected.
XForms模型用<instance>元素定义将被采集的数据

XForms is always collecting data for an XML document. The <instance> element in the XForms model defines the XML document.
XForms总是为一份XML文档采集数据。XForms模型的<instance>元素定义了XML文档

In the example above the "data instance" (the XML document) the form is collecting data for looks like this:
上述例子里的"data instance"(XML文档)里,窗口是像这样采集数据的:

<person>
<fname/>
<lname/>
</person>

After collecting the data, the XML document might look like this:
采集数据之后,XML文档也许会看起来像这样:

<person>
<fname>John</fname>
<lname>Smith</lname>

</person>


The <submission> Element
<submission>元素

The XForms model uses  a <submission> element to describe how to submit the data.
XForms模型用<submission>元素描述怎样提交数据。

The <submission> element defines a form and how it should be submitted. In the example above, the id="form1" attribute identifies the form, the action="submit.asp" attribute defines the URL to where the form should be submitted, and the method="get" attribute defines the method to use when submitting the data.
<submission>元素定义了窗口以及窗口该怎样提交数据。在上述例子中,id="form1"属性识别窗口,action="submit.asp"属性定义了窗口应提交的地址URL,method="get"属性定义了提交数据用的方法。


The XForms User Interface
XForms使用者界面

The XForms user interface is used to display and input the data.
XForms使用者界面用于展示和输入数据。

The user interface elements of XForms are called controls (or input controls):
XForms的使用者界面元素称为控制(或输入控制)

<input ref="fname"><label>First Name</label></input>
<input ref="lname"><label>Last Name</label></input>

<submit submission="form1"><label>Submit</label></submit>

In the example above the two <input> elements define two input fields. The ref="fname" and ref="lname" attributes point to the <fname> and <lname> elements in the XForms model.
上述例子中两个<input>元素定义了两个输入区域,ref="fname" 和ref="lname"属性指向的是XForms模式的<fname> 和 <lname> 元素

The <submit> element has a submission="form1" attribute which refers to the <submission> element in the XForms model. A submit element is usually displayed as a button.
<submit>有个submission="form1"属性,指的是XForms模式的<submission>元素,提交元素总是展示成为一个按钮。

Notice the <label> elements in the example. With XForms every input control element has a required <label> element.
注意例子里的<label>元素。在XForms里每个输入控制元素都有一个必须的<label>元素。


You'll Need A Container
你会需要一个“容器”

XForms is not designed to work alone. There is no such thing as an XForms document.
XForms并不是单独工作的,再没有像XForms 文档这样的东西了。

XForms has to run inside another XML document. It could run inside XHTML 1.0, and it will run inside XHTML 2.0.
XForms必须在另一份XML文档里运行。它可以在XHTML 1.0里运行,也将来的XHTML 2.0.里也可以运行。


All Together Now
现在全部合起来

If we put it all together the document will look like this:
如果我们把所有的都合起来,文档看上去会是这样:

<xforms>
<model>
<instance>
<person>
<fname/>
<lname/>

</person>
</instance>
<submission id="form1"
action="submit.asp"
method="get"/>
</model>
<input ref="fname"><label>First Name</label></input>
<input ref="lname"><label>Last Name</label></input>
<submit submission="form1"><label>Submit</label></submit>
</xforms>

And the page will display pretty much like this:
页面会展示成这样:

First Name
Last Name
  
 


The XForms Processor
XForms处理器

An XForms Processor built into the browser will be responsible for submitting the XForms data to a target.
植入浏览器的XForms处理器可以提交XForms数据给目标对象。

The data can be submitted as XML and could look something like this:
数据可以以XML形式提交,并会看起来像这样

<person>
<fname>Hege</fname>
<lname>Refsnes</lname>

</person>

Or it can be submitted as text, looking something like this:
或者它可以文本形式提交,看起来像这样:

fname=Hege;lname=Refsnes

XForms 命名空间
w3pop.com / 2006-09-21

p.gifXForms 模型 XForms 实例 n.gif

You should use an XForms namespace in HTML and XHTML 1.0.
在HTML 和 XHTML 1.0.里你应该使用XForms名称空间
But hopefully not in XHTML 2.0.
但在XHTML 2.0里就别指望能用了。


The XForms Namespace
XForms 名称空间

The official namespace for XForms is: http://www.w3.org/2002/xforms
XForms的官方名称空间是http://www.w3.org/2002/xforms

If you want to use XForms in HTML (or XHTML 1.0), you should declare all XForms elements with an XForms namespace.
如果你想在HTML (或 XHTML 1.0)里使用XForms,你应该用XForms名称空间声明所有的XForms元素。

XForms is expected to be a standard part of XHTML 2.0, eliminating the need for the XForms namespace.
XForms被期待成为XHTML 2.0的标准部分,XForms 名称空间却被排除在外。

This example uses the XForms namespace:
下面的例子用到了XForms名称空间:

<html xmlns:xf="http://www.w3.org/2002/xforms">
<head>
<xf:model>
<xf:instance>
<person>
<fname/>

<lname/>
</person>
</xf:instance>
<xf:submission id="form1" method="get"
action="submit.asp"/>

</xf:model>
</head>

<body>
<xf:input ref="fname">
<xf:label>First Name</xf:label></xf:input>
<br />

<xf:input ref="lname">
<xf:label>Last Name</xf:label></xf:input>
<br />
<br />
<xf:submit submission="form1">
<xf:label>Submit</xf:label></xf:submit>

</body>
</html>

In the example above we have used the xf: prefix for the XForms namespace, but you are free to call the prefix anything you want.
上面的例子里我们给XForms名称空间使用了前缀xf:,但其实你可以自由的起前缀名。

XForms 实例
w3pop.com / 2006-09-21

p.gifXForms 命名空间 XForms XPath n.gif

Test It With Internet Explorer
用IE浏览器检验:

You can test the example on this page using Internet Explorer 5 or later.
你可以用IE5或更高版的浏览器检验这页上的案例

Just click on the link below the example.
只须点击案例下面的链接


An XForms Example
XForms案例

Take a look at this document using XForms:
请看下面使用XForms的文档:

<xforms>

<model>
<instance>
<person>
<fname/>
<lname/>
</person>

</instance>
<submission id="form1" method="get"
action="submit.asp"/>
</model>

<input ref="fname">
<label>First Name</label></input><br />

<input ref="lname">
<label>Last Name</label></input><br /><br />

<submit submission="form1">
<label>Submit</label></submit>
</xforms>

The page will display pretty much like this:
这页大致会展示成这样:

First Name
Last Name
  
 

Try the example on your own computer
在你自己电脑上试着使用这个案例

XForms XPath
w3pop.com / 2006-09-21

p.gifXForms 实例 XForms Input n.gif

XForms uses XPath to address data. This is called binding."
XForms用XPath传送数据。这叫做绑定(binging)


XForms Binding
XForms绑定

XForms uses two sections to define data: The XForms model and the XForms user interface.
XForms用两部分定义数据:XForms模式和XForms用户界面。

The XForms model is an XML template (instance) for the data, and the XForms user interface is a description of the input and display of the data.
XForms模式是数据的XML模板(实例),XForms用户界面是数据输入和显示的描述。

XForms uses XPath to define the connection between the two sections. This is called binding.
XForms 用XPath定义两部分的联系。这叫做绑定


XPath

XPath is a W3C standard syntax for defining parts of XML documents.
XPath是定义XML文档部分的W3C的标准语法。

XPath uses path expressions to identify nodes in an XML document. These path expressions look much like the expressions you see when you work with a computer file system.
XPath用路径表达式识别XML文件中的节点。这些路径表达式与你使用的电脑文件系统的表达式相象。

This XPath expression:
XPath表达式:

/person/fname

addresses the fname node in the XML document:
传送XML文档中的fname节点:

<person>
<fname>Hege</fname>

<lname>Refsnes</lname>
</person>

Learn more about XPath in our XPath tutorial
在我们的XPath教程里了解更多内容


Binding Using Ref
用Ref绑定

With an XForms model instance like this:
一个XForms模式实例就像这样:

<instance>
<person>
<name>
<fname/> <lname/> </name> </person> </instance>

The XForms user interface can bind <input> elements using the ref attribute:
XForms用户界面可以用ref属性绑定<input>元素

<input ref="name/fname">
<label>First Name</label>
</input>
<input ref="name/lname">

<label>Last Name</label>
</input>

The ref="name/fname" attribute in the example above is an XPath expression pointing to the <fname> element in the instance model. This binds the input field to the <fname> element in the XML document (instance) that is collecting data from the form.
上述例子中的ref="name/fname"属性是指向实例模式里的<fname>元素的XPath表达式。它把从窗口采集数据的输入区域绑定给XML文档里的 <fname>元素。

The XForms user interface could also use a reference like this:
XForms用户界面也可以使用像这样的一个参考:

<input ref="/person/name/fname">
<label>First Name</label>

</input>
<input ref="/person/name/lname">
<label>Last Name</label>
</input>

In the example above, the slash (/) at the beginning of the XPath expression indicates the root of the XML document.
上述例子里,XPath 表达式开头的斜杠(/)指示了XML文档的根目录


Binding Using Bind
用“Bind”绑定

With an XForms model instance like this:
用XForms模式的例子会像这样:

<model>
<instance>
<person>

<name>
<fname/> <lname/> </name> </person> </instance> <bind nodeset="/person/name/fname" id="firstname"/> <bind nodeset="/person/name/lname" id="lastname"/> </model>

The XForms user interface can bind <input> elements using the bind attribute:
XForms用户界面可以用bind属性绑定<input>元素。

<input bind="firstname">
<label>First Name</label>
</input>
<input bind="lastname">
<label>Last Name</label>
</input>

Why two different ways to bind input control elements to instance data?
为什么用两种不同方式把输入控制元素绑定给实例数据?

Well, when you start using XForms in complex applications, you will find binding using bind to be a more flexible way to deal with multiple forms and multiple instance models.
当你在复杂的应用程序下开始使用XForms时,你会发现当处理多重窗口或多重例子模式时,使用“bind”进行绑定是更灵活的好方法。

XForms Input
w3pop.com / 2006-09-21

p.gifXForms XPath XForms Selections n.gif

The user interface of XForms uses XForms controls.
XForms的用户界面是用来控制XForms的。


XForms Controls
XForms控制

The user interface elements in XForms are called XForms Controls.
XForms中的用户界面元素称为XForms Controls(XForms控制)

The most commonly used control elements are <input> and <submit>.
最常用的控制元素是<input> 和<submit>元素

Each control element has a ref attribute pointing back to the XForms data model.
每个控制元素都有一个指向XForms数据模式的ref属性


Device Independent Controls
设备独立控制

It is important to know that the XForms user interface does not describe exactly how to display the XForms controls.
所应了解的重要的一点是:XForms用户界面并不是确切地描述了怎样显示XForms控制

Because XForms is platform and device independent, XForms leaves it up to the browser to decide how to display the controls.
因为XForms是平台而且是部件独立的,XForms让浏览器决定怎样显示控制

This way XForms can be used for all types of devices, personal computers, cell phones, hand held computers and much more. XForms is also the perfect solution for defining user interfaces for people with disabilities (handicapped, blind). 
这样XForms可以被任何类型的部件所使用,个人计算机,手机,掌上电脑等等。XForms也是为残疾人定义用户界面的完美解决方案(身体缺陷的,失明的)


The Input Control
输入控制

The input control is the most common XForms control. It is used for input one line of text:
输入控制是最常见的XForms控制。它用于输入一行文本:

<input ref="name/fname">
<label>First Name</label>
</input>

Most often the input control will display as an input field like this:
输入控制经常展示成这样的输入区域:

First Name:

Try it yourself
请自己试试


The <label> Element
<label>元素

The <label> element is a mandatory child element for all XForms input controls.
<label>元素是所有XForms输入控制一定要有的子元素。

The reason for this is to secure that the form can be used for all types of devices (because labels can be treated in different ways). For voice software the label has to be spoken, and for some hand held computers the label has to follow the input, screen by screen.
这样做的原因是为了确保窗口可以被所有类型的部件使用(因为标签可以被不同的方式处理),对于声音软件,标签必须被念出来,对于掌上电脑,标签必须一幕接一幕的跟在输入之后。


The Secret Control
保密控制

The secret control is a special variant of the input control, designed to input passwords or other hidden information:
保密控制是输入控制的一项特殊变量,用于密码输入或其他隐藏信息:

<secret ref="name/password">
<label>Password:</label>

</secret>

Most often the secret control will display as an input field like this:
保密控制经常展示成这样的输入区域:

Password:


The Textarea Control
文本区域控制

The textarea control is used for multi-line input:
文本区域控制用于多行文本输入:

<textarea ref="message">
<label>Message</label>
</textarea>

The textarea control might display as an input field like this:
文本区域控制也许展示成像这样的输入区域:

Message:


The Submit Control
提交控制

The submit control is used for submitting the data:
提交控制用于提交数据:

<submit submission="form1">
<label>Submit</label>
</submit>


The Trigger Control
触发控制

The trigger is used to trigger an action:
触发控制用于触发行为:

<trigger ref="calculate">
<label>Calculate!</label>
</trigger>


The Output Control
输出控制

The output control is used to display XForms data:
输出控制用于展示XForms形式的数据:

<p>First Name: <output ref="name/fname" /></p>

<p>Last Name: <output ref="name/lname" /></p>

The example above will simply output the content of the <fname> and <lname> node in the XForms XML document (XForms instance):
上述例子会简单输出在XForms XML文档里的<fname> 和 <lname>节点的内容(XForms 实例)

<instance>
<person>
<name>
<fname>Hege</fname> <lname>Refsnes</lname> </name> </person> </instance>

And display it like this:
它会展示成这样:

First Name: Hege

Last Name: Refsnes

Try it yourself
自己试试


The Upload Control
上传控制

The upload control is designed for uploading files to a server:
上传控制用于把文件上传给服务器:

<upload bind="name">
<label>File to upload:</label>
<filename bind="file"/>

<mediatype bind="media"/>
</upload>

XForms Selections
w3pop.com / 2006-09-21

p.gifXForms Input XForms Datatypes n.gif

The user interface of XForms uses XForms controls.
XForms的使用者界面使用了XForms控制


The Select1 Control
Select1控制

The select1 control is used for selecting one item from a list of items:
Select1控制用于从一系列项中选择一项

<select1 ref="status">

  <label>Status:</label>
  <item>
    <label>Male</label>
    <value>M</value>

  </item>
  <item>
    <label>Female</label>
    <value>F</value>
  </item>

</select1>

In the example above, the user can choose one of to values, Male or Female. The data stored in the XForms instance (XML document) will be M or F.
在上述例子中,使用者可以选择两个值中一个,男性或女性。在XForms实例里(XML文档)里储存的数据将是M或F

Try it yourself
自己试试吧


The Select Control
选择控制(the select control)

The select control is used for selecting items (one or many) from a list of items:
选择控制(the select control)用于在一系列项中选择项(一项或多项)

<select ref="languages">
  <label>Languages:</label>
  <item>

    <label>English</label>
    <value>E</value>
  </item>
  <item>
    <label>French</label>

    <value>F</value>
  </item>
  <item>
    <label>Spanish</label>
    <value>S</value>

  </item>
  <item>
    <label>German</label>
    <value>G</value>
  </item>

</select>

In the example above, the user can choose one or many of the values.
上述例子里,使用者可以选择一个或多个值


The Range Control
范围控制(The Range Control)

The range control is used for selecting a value from a range of values:
范围控制用于范围之内的值中选择一个:

<range ref="length" start="0" end="100" step="5">

  <label>Length:</label>
</range>

In the example above, the user can choose a value between 0 and 100 in steps of 5.
上述例子中,使用者可以在0到100(步长为5)的一系列数中选择一个。

XForms Datatypes
w3pop.com / 2006-09-21

p.gifXForms Selections XForms 属性 n.gif

The XForms model supports XML Schema data types.
XForms模型支持XML Schema数据类型


XML Schema Data Types
XML Schema数据类型

The XForms model supports XML Schema data types. This feature allows the XForms processor to check the data for correct input values.
XForms模型支持XML Schema数据类型这个特点允许XForms处理器检查输入的数据值是否正确。

You can learn more about XML Schema in our XML Schema tutorial.
在XML Schema 教程里你可以学习更多有关XML Schema

To use XML Schema data types, you must add the XML Schema namespaces to your namespace declaration like this:
为使用XML Schema数据类型,你必须在名称空间(namespace)声明中添加XML Schema名称空间,就像这样:

<html
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

After adding the XML Schema namespaces, you can add type attributes to your XForms instance elements like this:
在添加XML Schema名称空间之后,你可以给XForms实例元素添加类型属性,就像这样:

<xf:instance>
<person xmlns="">
<fname xsi:type="xsd:string"/>

<lname xsi:type="xsd:string"/>
<born xsi:type="xsd:date>"/>
<size xsi:type="xsd:integer"/>
</person>

</xf:instance>

XForms supports all XML Schema data types except for the following:
XForms支持所有XML Schema数据类型,除了以下这些:

  • duration
    时间段
  • ENTITY
    实体
  • ENTITIES
    实体
  • NOTATION
    符号

For a complete reference to XForms data types:
了解关于XForms数据类型的全部:

Complete XForms Data Type Reference全部的数据类型参数

Try it yourself 自己试一试吧^_^


Binding Datatypes
值入数据类型

In XForms you can also use the <bind> element to associate data types with instance data:
在XForms里你也可以使用<bind>元素将实例元素与元素类型结合起来。

<xf:bind nodeset="/person/size" type="xsd:integer"/>

XForms 属性
w3pop.com / 2006-09-21

p.gifXForms Datatypes XForms Actions n.gif

XForms properties define data restrictions, types and behaviors.
XForms属性定义了数据约束,数据类型和数据行为。


XForms Properties
XForms属性

XForms uses properties to define restrictions (or other attributes) that can affect the behavior of XForms controls.
XForms用属性定义了可以影响XForms控制行为的约束(或其他属性)

Examples:

A required="true()" property will not allow the specified instance data to be submitted as an empty value.
required="true()"属性不允许指定的实例数据提交时为空值。

A type="decimal" property will only allow a decimal value to be submitted.
type="decimal"属性只允许小数数值被提交。

A calculate property can calculate a value for the instance data.
Calculate属性可以计算实例数据的值。

Please refer to the properties reference at the bottom of this page.
请参照本页底部的属性参考


Binding Properties To Data
把属性值入数据

XForms uses the <bind> element to bind XForms properties to XForms data:
XForms用<bind>元素把XForms属性植入XForms数据:

<model>
<instance>

<person>
<fname/> <lname/> </person> </instance> <bind nodeset="person/lname" required="true()"/>

</model>

In the example above, the attribute nodeset="person/lname" binds the property required="true()" to the instance data element <lname>.
上述例子中,nodeset="person/lname"属性把required="true()"的属性植入实例数据元素<lname>.


XForms Properties Reference
XForms属性参考

Name
名称
Description
描述
calculateDefines a calculation to be performed on the item
定义在项上将被完成的一个计算
constraintDefines a constraint for the item
给项定义一个约束
p3ptypeDefines a P3P data type for the item
给项定义一个P3P数据类型
readonlyDefines an edit restriction for the item (cannot be changed)
给项定义一个编辑约束(不能被改变)
relevantDefines how relevant the data is (for display or submission)
定义数据相关内容(数据用于显示还是提交)
requiredDefines if data item is required (cannot be blank)
定义数据项是否有要求(不能空白)
typeDefines the data type for the item
给项定义数据类型

XForms Actions
w3pop.com / 2006-09-21

p.gifXForms 属性 XForms 函数 n.gif

XForms Actions are handling response to events.
XForms Action(行为)的作用是处理事件响应的。


The Message Action
信息行为(action)

The XForms element <message> defines a message to be displayed in the XForms user interface.
XForms元素<message>定义了一条将在XForms用户界面展示的信息

Look at this simplified example:
请看下面简化了的例子

<input ref="fname">
<label>First Name</label>
<message level="ephemeral" event="DOMFocusIn">

Input Your First Name
</message>
</input>

In the example above, the message "Input Your First Name" should be displayed as a tool tip when the user focus in on the input field.
在上述例子里,当使用者注意于输入区域时,信息"Input Your First Name"会以工具提示的形式展现

The event="DomFocusIn" defines the event to trigger the action.
event="DomFocusIn"定义了事件将触发行为(action)

The level="ephemeral" defines the message to be displayed as a tool tip.
level="ephemeral"定义了信息将以工具提示形式展现

Other values for the level attribute are modal and modeless, defining different types of message boxes.
Level属性的其他值是模式和非模态的,定义了信息提示框的不同类型。


The Setvalue Action
设置值行为(action)

The XForms element <setvalue> defines a value to be set in response to an event.
XForms元素<setvalue>定义了在事件回应里所设的值

Look at this simplified example:
看下面的简化例子

<input ref="size">
<label>Size</label>
<setvalue value="50" event="xforms-ready"/>

</input>

In the example above, the value 50 will be stored in the instance element <size> when the form opens.
在上述例子里,当窗口打开时,50这个值会储存在实例元素<size>里。

XForms 函数
w3pop.com / 2006-09-21

p.gifXForms Actions Xforms 数据类型 n.gif

XForms has some predefined functions. But you can also call functions defined in scripts.
XForms有一些已经预定的函数,同样地你也可以调用脚本中的函数。


XForms Functions
XForms函数

The XForms function library includes the entire XPath 1.0 core function library.
XForms函数库包括了所有XPath 1.0中心函数库的函数

XPath 1.0中心函数库的函数可在这里找到:http://www.w3pop.com/tech/school/xpath/xpath_functions.asp

The following table lists the additional functions within XForms:
下面的表格列举了在XForms里的别的函数:

Function
函数
Description
描述
boolean-from-string(string)
逻辑值—字符串(字符串)
Returns true if the parameter string is "true" or "1" and false if the parameter string is "false" or "0"
参数字符串为"true" 或"1"则返回“真”,参数字符串为"false" 或"0"则返回“假”
if(booleantest, string1, string2)
(逻辑测试值,字符串1,字符串2)
Evaluates the Booleantest parameter and returns string1 if the test is true, and string2 if the test is false
逻辑测试值(Booleantest)参数,如果参数为真,则返回string1(字符串1),如果文本为假,则返回string2(字符串2)
avg(node-set)
平均值(节点组)
Returns the average of all the nodes in the specified node-set. The value of each node is converted to a number. If the node-set is empty it returns NaN
 返回在指定的节点组里所有节点的平均值。每个节点的值被转化成一个数字。如果节点组为空就返回NaN

<values>
<value>10</value>
<value>50</value>
<value>0</value>
</values>

avg(/values/value)

Returns: 20
返回:20
min(node-set)
最小(节点组)
Returns the minimum value of all the nodes in the specified node-set. The value of each node is converted to a number. If the node-set is empty it returns NaN
返回在指定的节点组里所有节点的最小值,每个节点的值被转化成一个数字。如果节点组为空就返回NaN

<values>
<value>10</value>
<value>20</value>
<value>0</value>
</values>

min(/values/value)

Returns: 0
返回:0
max(node-set)
最大(节点组)
Returns the maximum value of all the nodes in the specified node-set. The value of each node is converted to a number. If the node-set is empty it returns NaN
 返回在指定的节点组里所有节点的最大值,每个节点的值被转化成一个数字。如果节点组为空就返回NaN

<values>
<value>10</value>
<value>20</value>
<value>0</value>
</values>

max(/values/value)

Returns: 20
返回:20
count-non-empty(node-set)
非空节点个数(节点组)
Returns the number of non-empty nodes in the specified node-set
 返回在指定的节点组里的非空节点的个数

<values>
<value>10</value>
<value>20</value>
<value>0</value>
<value />
</values>

count-non-empty(/values/value)

Returns: 3
返回:3
index(string)
索引(字符串)
Returns the current index for a given repeat set
为给定的恢复属性设置一个当前索引值
property(string)
性质(字符串)
Returns the property named by the string parameter
 输出以字符串参数命名的性质
  • property("version") - returns the XForms version number
    property("version")返回XForms的版本数目
  • property("conformance-level") - returns the XForms conformance level ("basic" or "full")
    一致程度("basic"(基本)或"full"(全部))
now()
当前时间()
Returns the current system date and time in xs:dateTime format
以xs:dateTime格式返回当前的系统日期和时间
instance(string)
情况(字符串)
An XForms Model can contain more than one instance. This function returns the root node of the specified instance data
XForms模式可以包含多个实例。函数返回指定的实例数据的根节点

<xforms:instance id="orderform">
<firstName>John</firstName>
</xforms:instance>

ref="instance('orderform')/firstName"

This example returns a node-set that consists of the firstName element node from the instance named "orderform"
这个例子返回了一个在"orderform"情况下的由firstName元素组成的节点组

days-from-date(string)
天数(字符串)
If the string parameter represents a legal xs:date or xs:dateTime, it returns the number of days between the specified date and 1970-01-01, otherwise it returns NaN
 如果字符串参数形式是正确的xs:date 或xs:dateTime,那返回的则是指定日期到1970-01-01之间的天数,否则返回NaN

days-from-date("2002-01-02") returns 11689
返回:11689
days-from-date("1969-12-29") returns -3
返回:3

seconds-from-dateTime(string)
If the string parameter represents a legal xs:dateTime, it returns the number of seconds between the specified dateTime and 1970-01-01T00:00:00Z, otherwise it returns NaN
如果字符串参数形式是正确的xs:dateTime,则返回的是指定的时间日期到1970-01-01T00:00:00Z的秒数,否则返回NaN
seconds(string)
秒数(字符串)
If the string parameter represents a legal xs:duration, it returns the number specified in the seconds component plus 60 * the number specified in the minutes component, plus 60 * 60 * the number specified in the hours component, plus 60 * 60 * 24 * the number specified in the days component, otherwise it returns NaN
如果字符参数形式是正确的xs:duration,返回的值是:秒数+分钟数*60+小时数*60*60+天数*60*60*24,否则返回NaN 

seconds("P1Y2M") returns 0
返回0
seconds("P3DT10H30M1.5S") returns 297001.5
返回297001.5
seconds("3") returns NaN
返回NaN

months(string)
月数(字符串)
If the string parameter represents a legal xs:duration, it returns the number specified in the months component plus 12 * the number specified in the years component, otherwise it returns NaN
 如果字符参数的形式是正确的xs:duration,则返回的值是:月数+年数*12,否则返回NaN

months("P1Y2M") returns 14
返回14
months("-P19M") returns -19
返回-19


Xforms 数据类型
w3pop.com / 2006-09-21

p.gifXForms 函数 n.gif

Complete XForms Data Types Reference:
完整的XForms数据类型参数:


String Data Types
字符数据类型

Name
名称
Description
描述
IDA string that represents the ID attribute
表现ID属性的字符串
IDREFA string that represents the IDREF attribute
表现IDREF属性的字符串
IDREFS 
languageA string that contains a valid language id (e.g. en, en-US)
含有一种有效语言id的字符串(例如,en, en-US)
NameA string that contains a valid XML name
含有一个有效XML名称的字符串
NCName 
NMTOKENA string that represents the NMTOKEN attribute
表现NMTOKEN属性的字符串
NMTOKENS 
normalizedStringA string that does not contain new line characters or tabs
不含新行字符或制表符的字符串
QName 
stringA string. This is the default data type XForms will use if no data type is specified.
一个字符串。没有指定数据类型,默认使用的数据类型为XForms

Note: string may contain tab characters and new line characters
注意:字符串包含新行字符与制表符

tokenA string that does not contain line feeds, carriage returns, tabs, leading or trailing spaces, or multiple spaces
不含有换行符,回车符,制表符,头尾空格,或重复空格的字符串。

All string data types are derived from the string data type itself.
所有字符串数据类型都是由字符串数据类型本身派生出来的。


Date and Time Data Types
日期和时间数据类型

Name
名称
Description
描述
dateDefines a date value
定义日期值
dateTimeDefines a date and time value
定义日期和时间值
gDayDefines a part of a date - the day (DD)
定义了日期的部分——日部分(DD)
gMonthDefines a part of a date - the month (MM)
定义了日期的部分——月部分(MM)
gMonthDayDefines a part of a date - the month and day (MM-DD)
定义了日期的部分——月和日部分(MM-DD)
gYearDefines a part of a date - the year (CCYY)
定义了日期的部分——年部分(CCYY)
gYearMonthDefines a part of a date - the year and month (CCYY-MM)
定义了日期的部分——年和月部分(CCYY-MM)
timeDefines a time value
定义了时间值


Numeric Data Types
数值数据类型

Name
名称
Description
描述
byteA signed 8-bit integer
8位带符号整数
decimalA decimal value
小数数值
intA signed 32-bit integer
32位的带符号整数
integerAn integer value
整数值
longA signed 64-bit integer
64位的带符号整数
negativeIntegerAn integer containing only negative values (..,-2,-1)
只含有负值的整数(..,-2,-1)
nonNegativeIntegerAn integer containing only non-negative values (0,1,2,..)
只含有非负值的整数(0,1,2,..)
nonPositiveIntegerAn integer containing only non-positive values (..,-2,-1,0)
只含有非正整数值的整数(..,-2,-1,0)
positiveIntegerAn integer containing only positive values (1,2, ..)
只含有正值的整数(1,2, ..)
shortA signed 16-bit integer
16位的带符号整数
unsignedLongAn unsigned 64-bit integer
64位的不带符号整数
unsignedIntAn unsigned 32-bit integer
32位的不带符号的整数
unsignedShortAn unsigned 16-bit integer
16位的不带符号的整数
unsignedByteAn unsigned 8-bit integer
8位的不带符号的整数

All numeric data types are derived from the decimal data type.
所有数值数据类型都是从小数数据类型里派生出来的。


Miscellaneous Data Types
混合数据类型

Name
名称
Description
描述
anyURIRepresents a URI, which includes web page addresses
代表一个URI,它包含一个网地
base64BinaryAllows characters, including control characters, that otherwise aren't representable in XML
允许字符,包括control符号,否则其他的是不能在XML里被描述的。
booleanDefines a true/false or 1/0 value
定义了true/false 或1/0值
double 
float 
hexBinary 


XForms Data Types
XForms数据类型

Name
名称
Description
描述
listItemsRepresents a whitespace-separated list
描绘了空格分离的列表
listItemRepresents only non-whitespace characters. An excellent base type for a whitespace-separated list
只描绘非空白字符,是空格分离列表不错的基本类型
dayTimeDurationRepresents a duration of a certain number of seconds
描绘了一定秒数的持续时间
yearMonthDurationRepresents a duration of a certain number of months
描绘了一定月数的持续时间

转载于:https://www.cnblogs.com/caoxch/archive/2006/11/18/564374.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值