You are reading O'Reilly XForms Essentials by Micah Dubinko. (What is this?) - Buy XForms Essentials Online
Table of Contents
List of Figures
List of Tables
List of Examples
Copyright � 2003 Micah Dubinko
Printed in the United States of America.
Published by O'Reilly & Associates, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O'Reilly & Associates books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://safari.oreilly.com). For more information, contact our corporate/institutional sales department: (800) 998-9938 or <corporate@oreilly.com>.
Nutshell Handbook, the Nutshell Handbook logo, and the O'Reilly logo are registered trademarks of O'Reilly & Associates, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O'Reilly & Associates, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps. The association between the image of a vulturine guinea fowl and the topic of XForms is a trademark of O'Reilly & Associates, Inc.
While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein.
Table of Contents
The book in your hands introduces you to XForms, a combination of two of the most successful experiments ever performed with the Web: XML and forms.
2003 marks the 10-year anniversary of forms on the Web. During that time, the Web grew from a loose collection of technical research sites to the livelihood of millions, browser empires have risen and fallen, and the tech economy went through an inflationary period of cosmic proportions only to collapse back in upon itself. The addition of forms to the otherwise static HTML language in 1993 was a revolutionary step forward, making possible Yahoo!, Google, Amazon, Hotmail, and countless other interactive sites.
During the mid-nineties, the World Wide Web Consortium (W3C) began work on XML, a uniform way to represent structured text and data, in an attempt to simplify an earlier language called SGML. XML became a W3C Recommendation in 1998, and has since gained momentum, becoming the foundation for XHTML, SVG, the Universal Business Language (UBL), syndication formats such as RSS, and DocBook (which was used to write this book). Nearly every data format that consists primarily of human-readable data has been influenced by XML.
At last, XForms—officially described at http://www.w3.org/TR/xforms—provides a way for web forms to serve as XML data collection tools. Increasingly, IT departments are using XML and native XML databases to store mission-critical data. Workflow and routing systems rely on XML for data representation. Web services, which are growing immensely in popularity, are the final piece of the puzzle—making it easy (and providing needed tool support) to send and receive XML data and documents.
You should read this book if you want to:
Create XForms files in a text or XML editor
Convert existing forms (electronic or paper) to XForms
Collect XML data from users in a user-friendly way
Reduce the amount of JavaScript needed within browser interfaces
Increase the security and reliability of your current information system by combining client-side and server-side checks into a common code base
Understand how to create interactive web sites using the latest standard technology
If you simply want to fill out a form, you need only acquire the appropriate software or browser plug-in. There's no need for you to know what's going on behind the scenes unless you wish to satisfy your commendable intellectual curiosity.
If you wish to create forms with a designer program that has XForms export capability, just read that program's documentation to learn how to use that program feature. XForms goes to great lengths to make the fill-out experience intuitive; reading instructions is not required.
Form designers tend to come from one of two camps: either graphical design people who find themselves thrust into a world of databases, or technical folks who face the challenge of creating a suitable (and aesthetically pleasing) frontend for their data. This book tends to lean mainly toward the technical side and, in fact, offers very little advice on purely aesthetic issues involved in laying out forms. Some basic knowledge of XML will come in handy, though other W3C technologies used by XForms will be introduced and covered in separate chapters. If you are completely unfamiliar with XML, you will likely benefit by first reading through some of the introductory XML material on the Web, such as at http://www.xml.com.
All the examples in this book have been tested with both a commercial and an open source XForms browser, typically Novell XForms Explorer (http://www.novell.com/xforms), X-Smiles (http://www.x-smiles.org)(from the Helsinki University of Technology), and the FormsPlayer plug-in from X-Port (http://www.formsplayer.com).
This book is organized into three divisions. The first gives a general introduction to web forms, including information on the history and basic construction of forms. The second section serves as a kind of reference manual to the XForms specification. The third section offers additional hints, guidelines, and techniques for working with XForms.
This chapter gives a brief history of HTML forms and XForms, the design philosophy behind XForms, and some necessary terminology and concepts.
Unlike some XML-based languages, XForms is not defined as a standalone document type. This design decision has ramifications that are necessary to understand in order to make effective use of XForms. This chapter discusses issues that come up in the process of defining a markup language (such as XHTML or SVG) that includes XForms.
XPath is another W3C standard that isn't used by itself but in concert with other specifications. XForms is a first-class application of XPath, joining the ranks of XSLT and XPointer. This chapter serves as a complete reference to all of XPath, with particular attention to the parts that are most useful in forms or defined within the XForms specification itself.
XML Schema is another W3C technology leveraged by XForms. This chapter gives an overview of the parts of XML Schema that are important for forms and describes the new datatypes introduced by XForms.
A powerful feature in XForms is the ability to declaratively specify that a form control is required, read-only, calculated, or relevant to the form. The combined definitions of these properties are called the XForms Model, which is the subject of this chapter.
The user interface is the most immediately recognizable part of a form. This chapter discusses the user interface, including details on how the conceptual level of XForms form controls differs from that of HTML form controls.
This chapter discusses a topic of critical importance to XForms: XML Events. Observing, catching, dispatching, and responding to events remains among the chief reasons for using script with HTML forms. With the advent of XML Events (a separate W3C specification that is finding use in XForms, XHTML, and other places), many functions that used to require script can be written declaratively in XML.
Nearly every form is intended to submit data at some point. In addition to introducing XML data into forms, XForms defines backward-compatible data submission, as well as a few new tricks. This chapter guides you through all the options, including hints on how to select the appropriate options to match your specific needs.
XForms forces authors to think about the separation between content and presentation. As a result, specifying style information becomes more important with XForms. This chapter discusses new and existing stylesheet syntax that applies to forms.
This chapter includes lots of tips for designing forms for accessibility, so that different users can make full use of the form. Additionally, this chapter includes different techniques and useful design patterns for forms.
This chapter covers the many ways in which XForms can be extended, including in a future version of XForms that is now underway.
Microsoft has developed an application called InfoPath that is frequently compared to XForms. This appendix compares some technical aspects of XForms implementations with InfoPath.
This book is being made available under the GNU Free Documentation License, which provides certain freedoms related to copying, modifying, and distributing this book. This appendix contains pointers to the online version of the book (which includes additional examples and errata), as well as the text of the license.
Constant width is used for code examples, code fragments, XML elements, and attributes.
Constant width bold is used to highlight a section of code being discussed in the text.
Constant width italic is used for replaceable elements in code examples.
In examples that involve XML Namespaces, the following conventions are used for namespace prefixes:
A prefix that represents an arbitrary user-defined namespace
Please address comments and questions concerning this book to the publisher:
| O'Reilly & Associates, Inc. |
| 101 Morris Street Sebastopol, CA 95472 |
| 1-800-998-9938 (in the United States or Canada) |
| 1-707-829-0515 (international/local) |
| 1-707-829-0104 (fax) |
To comment or ask technical questions about this book, send email to:
For more information about our books, conferences, software, Resource Centers, and the O'Reilly Network, see our web site at:
http://www.oreilly.com
Foremost, thanks to my wife, Ann, and my daughter, Anita, both of whom put up with great stretches of my writing time away from them. Without their support, I never could have made it through the tough times.
I'd also like to thank Simon St.Laurent, the editor of this book, and Edd Dumbill, the editor of xml.com—two of the sharpest XML geeks I've had the pleasure of knowing. Support and encouragement from both of them have helped me improve as a writer and gain the confidence to take on this challenging and rewarding project.
The members of the XForms Working Group have been a tremendous resource, especially the chair, Steven Pemberton, and one of the founders and former chair, Sebastian Schnitzenbaumer. Also, Mikko Honkala from the Helsinki University of Technology and Kenneth Sklander and David Landwehr from Novell have been noteworthy in their sharing of implementation experience on the public mailing list at www-forms@w3.org. Countless other implementers, too many to name, have likewise made valuable contributions.
I also need to thank Richard Stallman: even though I don't agree with him on many things, I do agree that the GNU Free Documentation License that he helped create is a great way to release a technical book such as this one.
One advantage of putting early versions of a book on the Web is the huge amount of feedback you get, even from the earliest stages. Even before formal review, I had the following notice, absolutely true even then, in the preface: "The technical reviewers for this book were amazingly helpful. It was a humbling experience to see just how many mistakes I had inserted into the earlier drafts." Once the formal technical review started, the volume of quality comments I received blew away my high expectations. I owe a debt of gratitude to my team of expert reviewers, including Jelks Cabaniss, St�phane Chauvin, David Ezell, Leigh Klotz, Shane McCarron, Roland Merrick, Mark Seaborne, Jeni Tennison, Eric van der Vlist, and everyone who participated in the xforms-essentials mailing list.
Table of Contents
"In the beginning...the earth was without form, and void."
—Genesis 1:1, 2
How common are forms on the Web? Well, on a recent visit to the news site http://www.cnn.com, I counted six separate forms:
A navigation list
A search tool
A stock quote tool
A language picker
A community poll
A weather forecast tool
As a general rule, the more interactive a web site is, the more heavily the site's designers rely on web forms, a general term for all different kinds of technologies used to gather information from users. It is easy to see why this is the case—without forms, web sites are far less interesting. Form-less web sites were the norm in the early days of the Web and provided a one-way deluge of static information, similar to the Sunday newspaper, which requires lots of navigation to get to any specific part and contains countless pages that get printed but never read.
The addition of forms to Hypertext Markup Language (HTML), the primary language used in web pages, launched an entirely new way of surfing the Web. In this book, I use the term HTML forms to refer to the form element and related markup from either HTML or XHTML. Using HTML forms, searching for information became possible on a worldwide scale. Sites such as Yahoo! quickly became the most popular "portals" of entry on the Web. Later, as developers pushed the limits of forms technology farther, web sites became even more interactive and customizable. In return for a small piece of information, such as a postal code, the browsing experience could be reshaped to include what specific information visitors were looking for—leaving out the rest. HTML forms have proven so successful in this regard that newer web technologies, such as PDF forms and Flash, have been unable to make a significant dent in their popularity.
Scientists and science fiction writers have long predicted many of the things now being made possible by web forms. For example, in a 1945 article in The Atlantic Monthly, Vannevar Bush wrote about a hypertext network he dubbed a "Memex." Even at this conceptual stage, the thought of using forms to access data came naturally, particularly in terms of drilling down through vast stores of information: "One might, for example, speak to a microphone, in the manner described in connection with the speech-controlled typewriter, and thus make his selections." How did such a technology come to be in real life?
Shortly after the initial tempering of HTML, various individuals began considering the usefulness of forms alongside hypertext. HTML Version 2.0, as presented in a document called Request for Comments (RFC) 1866, was the first time that web forms were seriously considered for standardization. That RFC captured HTML as found in common use prior to June 1994. At this point, HTML already included forms, thanks to a 1993 proposal called HTML+.
Care and maintenance of the HTML family of specifications have since been handed over to the World Wide Web Consortium, or W3C. The last non-XML-based version of HTML was version 4.01, which didn't change forms processing much. New development of the standard is taking place on a closely related technology called XHTML, where the X indicates an XML foundation. XHTML 1.0 and 1.1 were largely concerned with details of the transition to XML and ways to combine vocabularies, not with major changes to the language.
XHTML 2.0, in contrast, is making some improvements that aren't compatible with earlier flavors of HTML. The largest such change is the adoption of XForms as a replacement for the older HTML forms technology. As of August 2003, XHTML 2.0 is still under development, though it's clear that XForms will play a major role in the future of XHTML. Before we discuss XForms, however, a review of the older HTML forms technology will be helpful.
The introduction of the forms chapter in HTML 4.01 reads: "An HTML form is a section of a document containing normal content, markup, special elements called controls (checkboxes, radio buttons, menus, etc.), and labels on those controls. Users generally 'complete' a form by modifying its controls (entering text, selecting menu items, etc.), before submitting the form to an agent for processing (e.g., to a web server, to a mail server, etc.)."
The defining element for HTML forms is named, not too surprisingly, form. This element describes some important aspects of the form, including where and how to submit data. The content of this element consists of regular HTML markup, as well as controls.
Forms represent a structured exchange of data. In HTML forms, the structure of the collected data, called a form data set, is a set of name/value pairs. The names and values that are included in this set are solely determined by the controls present within the form, so that adding a new control element, as well as adding to the user interface, also adds a new name/value pair to the data set. Many authors take for granted this basic violation of the separation between the data layer and the user interface layer—a problem that XForms has gone to considerable lengths to alleviate.
Which control types are available in HTML forms? The following sections will answer this question.
The workhorse of HTML forms, this control permits the entry of any character data. Text input controls accept a string value and contribute it to the form data set. Example 1.1 shows the XHTML code needed to produce a basic single-line text control, and Figure 1.1 shows the result.
A more complex variation of text entry is when multiple lines of text need to be entered. For this purpose, HTML forms includes a separate form control that is typically larger than standard text input controls and offers special handling of multiple-line text. Multi-line text input controls contribute to the form data set exactly as do single-line text input controls. Example 1.2 shows the XHTML code for a multi-line text control, and Figure 1.2 shows the result.
Another variation of text entry is for sensitive data, such as a password, that could be harmful to display on the screen where someone could "shoulder surf," or covertly observe, and thus compromise security measures. It is important to note that this control provides only a casual level of security in the presentation: it does not, for example, provide any data encryption. Password text input controls contribute to the form data set exactly as do text input controls. Example 1.3 shows the XHTML code needed for a password control, and Figure 1.3 shows the result.
These controls are similar to buttons, but when activated have the effect of built-in processing (to submit or reset the form, respectively). Reset controls aren't supposed to contribute to the form data set, but up to one submit button can. This can be useful, when there are multiple submit buttons, in determining which one initiated the submission process. Example 1.4 shows the XHTML code needed for submit and reset controls, and Figure 1.4 shows the result.
The effect of activating a button is to invoke a call in a scripting language. A button can be specified in two slightly different ways, with the button syntax being slightly more expressive. If a value is assigned to the button, it will be contributed unchanged to the form data set (not the most useful functionality, but there if you need it). Example 1.5 shows the XHTML code for a button control, and Figure 1.5 shows the result.
Named after the mechanical controls on old radios, this common control requires that a single option always be selected, and thus is almost always used as a group of controls with the same name. The HTML specification encourages authors to ensure that a particular choice is initially selected, but in practice authors usually don't select a particular choice, resulting in "undefined" behavior. (One common implementation choice is to provide a temporary exception to the one-thing-must-always-be-selected rule, but it isn't safe to rely on this behavior.) A group of radio buttons provides a single value representing the current selection to the form data set. Example 1.6 shows the XHTML code for a radio button group, and Figure 1.6 shows the result.
Example 1.6. XHTML code for a radio button group
<input type="radio" name="car" value="0"/> None<br/> <input type="radio" name="car" value="1"/> 1 car<br/> <input type="radio" name="car" value="2"/> 2 cars<br/> <input type="radio" name="car" value="3"/> 3 cars<br/> <input type="radio" name="car" value="4"/> 4 cars<br/> <input type="radio" name="car" value="many"/> 5 or more<br/>
This simple on/off control has become familiar to computer users everywhere. Often, this control is used in a group which uses the same name, which allows for a select-zero-or-more behavior, though solo checkboxes are common as well. Only checkboxes that are checked contribute to the form data set. In cases where multiple checkboxes share the same name and are checked, the form data set will contain multiple entries with the same name and each selected value. Example 1.7 shows the XHTML code for a checkbox group, and Figure 1.7 shows the result.
Example 1.7. XHTML code for a checkbox group
<input type="checkbox" name="referBy" value="td"/> Test driven a vehicle<br/> <input type="checkbox" name="referBy" value="dlr"/> Visited an autotmotive dealer<br/> <input type="checkbox" name="referBy" value="veh"/> Purchased/Leased a vehicle<br/> <input type="checkbox" name="referBy" value="ins"/> Purchased automobile insurance<br/>
Commonly called a listbox or drop-down menu, this control enforces a single selection out of several options. In effect, this control provides another way to achieve the same function as radio buttons, but with a different visual presentation. As is the case with radio buttons, an initial state that doesn't explicitly select some initial choice is "undefined," though existing implementations usually allow an initial nothing-selected state. Single-select menus use one option child element for each option, which can include both a display value and a storage value. The storage value representing the current selection is provided to the form data set. Example 1.8 shows the XHTML code for a single-select control, and Figure 1.8 shows the result.
Adding an attribute to the select element enables the control to accept multiple selections, or even to select nothing at all. In this configuration, this control can achieve the same function as a group of checkbox controls, but with a different presentation. As with checkboxes, if any options are selected, this control provides the display value of each selection to the form data set. Example 1.9 shows the XHTML code for a multiple-select control, and Figure 1.9 shows the result.
Example 1.9. XHTML code for a multiple-select control
<select multiple="multiple"> <option value="0">UNCONFIRMED</option> <option selected="selected" value="1">NEW</option> <option selected="selected" value="2">ASSIGNED</option> <option selected="selected" value="3">REOPENED</option> <option value="4">RESOLVED</option> <option value="5">VERIFIED</option> <option value="6">CLOSED</option> </select>
A more recent addition to HTML was the ability to select a local file to submit along with the rest of the form data. This control contributes binary data into the form data set, which has implications on the wire format used to submit data, as discussed later. The filename selected is also included, in a secondary way, in the submitted data. Example 1.10 shows the XHTML code for a file select control, and Figure 1.10 shows the result.
Often, a form needs to hold more data than what is visible, in order to track state or earlier interactions. This control has no user interface effect, but contributes to the form data set. Example 1.11 shows the XHTML code for a hidden control.
Finally, the HTML specification defines a way for additional controls, such as plug-ins or Java applets, to participate in forms. This approach, however, never gained popularity, although clever programmers have used scripting and dynamic HTML to accomplish many of the same goals.
Printed forms make extensive use of labels as directions for filling out the document, which is good, since most people don't read the regular instructions, anyway. HTML forms are no different. A label element can be associated with any control, either by wrapping the label around the control, or by referencing an ID unique to the form control. When connected this way, the label becomes an extension of the control, which helps make forms more usable. For example, a radio button label is a much easier target to click on than the tiny circular control itself. When the label is properly connected, clicking it has the same effect as clicking the related control.
Nobody is sure exactly why, but the simple practice of using label elements has failed to catch on with authors. As a result, many HTML forms still use tables and other inaccessible techniques where text associated with a form control might visually appear nearby the control, but is actually defined in some unrelated markup structure, such as a different table cell. That kind of document is a major obstacle for non-visual users to figure out, since the visual proximity of items is the only connection between form controls and labels.
Groups of radio buttons pose another problem for labeling. Each radio button can have an individual label, but what about labeling the overall group? For this purpose, HTML forms include a general-purpose grouping element called fieldset, the first child of which may be legend, which is another kind of label. Example 1.12 shows the XHTML code for a fieldset, and Figure 1.11 shows the result.
Using a keyboard to get around in a form is not only an accessibility feature, but also a convenience for people who need to fill large numbers of forms or lengthy forms. All controls accept two attributes to help define a keyboard interface:
Often it is necessary in an electronic form to have a control that displays, but doesn't allow changes to, a piece of data. This can be accomplished through an attribute called readonly, which unfortunately only applies to text input controls. When a control is read-only, it is still possible to navigate to it, and any data present will still be submitted.
The disabled attribute enforces a stronger prohibition. Any control, even lists, radio buttons, or checkboxes, can be disabled, in which case the browser gives the control a distinctive "grayed out" appearance, indicating its unavailability. It is not possible to navigate to a disabled control, nor will it participate in data submission. Effectively, the control is not part of the form anymore (although it is still available to scripting).
Except for the file upload control, it's possible to provide initial data for all form controls, but keeping track of the differing form control types is complicated. Here are some of the different control types and the data they accept:
Inserting initial data is a major bottleneck in large-scale projects involving forms, both in terms of processing time and in opportunities for bugs to appear. The typical approach is to have a template language that is processed by an application server, effectively doing a large search-and-replace operation before delivering every page containing forms. Workflow and routing scenarios, where submitted data is sent from one user's desktop to another, are similarly burdened with large amounts of templating and tricks to populate forms in advance.
Usually, the primary purpose of a form is to submit data. The original, and still most popular, encoding for this is called urlencoded, and is represented by the Internet media type application/x-www-form-urlencoded. In this encoding, spaces become plus signs, and any other reserved characters become encoded as a percent sign and hexadecimal digits, as defined in RFC 1738. One unfortunate aspect of this definition is that it doesn't describe how to encode anything beyond simple ASCII characters. Some implementations have used the document encoding to control this process, but interoperability has remained elusive.
A second encoding became necessary with the introduction of the file upload control and the binary data this introduced into the form data set. This is called multipart/form-data, and is based on the MIME format defined in RFC 2388. This format allows for much more efficient representation of binary and non-ASCII data.
One final consideration in form submission is how the data gets submitted. The HTML specification defines submission through the HTTP methods GET and POST and also includes an example of email, through the mailto: URI scheme. The HTTP specification gives some specific advice on when to use GET versus POST, which we will consider later.
Example 1.13 shows a simple, but typical, HTML form. Figure 1.12 shows how this form is rendered.
Example 1.13. XHTML code for a typical XHTML form
<form action="http://example.com/cgi-bin/submit-here" name="shake-poll"> <p>Poll: to be or not to be?</p> <input type="radio" name="thequestion" id="radio1" value="b"/> <label for="radio1">To Be<label><br/> <input type="radio" name="thequestion" id="radio2" value="n"/> <label for="radio2">Not To Be<label><br/> <input type="radio" name="thequestion" id="radio3"/> <label for="radio3">Other (please specify)<label><br/> <input type="text" name="othersel"/> </form>
According to developers, the most commonly cited problem with HTML forms is their dependency on scripting languages. Real-world HTML forms are reliant on script to accomplish many common tasks such as marking controls as required, performing validations and calculations, displaying error messages, and managing dynamic layout. This dependency results in complex documents, which are expensive and time-consuming to maintain, since a full-time programmer is practically necessary when dealing with that much script.
XForms helps reduce the need for script in several ways: by defining a framework for simple, XPath-based calculations and validations, by providing better user feedback on the status of the form, through dynamic features such as repeating tables and optional sections, and through a system of XForms Actions—elements that cause commonly needed actions such as setting focus or changing a data value.
A second limitation of HTML forms is the difficulty of initializing form data, as commonly happens when web sites "remember" past users and provide them the courtesy of not having to repeatedly enter information. As shown earlier, each form control has its own unique way of defining initial data, with small bits of initialization data spread all across the document. This means that in order to process a blank form into a filled form, either a new document needs to be constructed piece by piece, or an existing document needs to be patched in numerous places—one of the reasons why template-replacement facilities are commonly found in application servers. Constructing such forms is CPU-intensive and leads to bottlenecks on high-volume servers.
In XForms, form data is provided from an initial XML file, which can be external to the form definition. Since XForms is also flexible enough to deal directly with most XML data formats, piping initial data into a form is typically a simple matter of pointing a src attribute to an existing XML data source.
A third limitation of HTML forms is that the encoding formats, urlencoded or multipart, represent only "flat" data, or name/value pairs. Many types of forms, including purchase orders, would benefit from a richer data representation.
XML is a better foundation for most business documents than a flattened set of names and values. Since it has XML support as a fundamental requirement, XForms excels at helping users create those kinds of documents.
More subtle, but still serious, is a fourth fundamental design flaw in HTML forms: a hidden assumption of a one-step process—from a client to a server—with processing finishing there. In the real world, forms often travel in more complicated paths. For example, a vacation request form might go to a supervisor for approval, then to the human resources department, and finally to accounting for final processing. Managing HTML forms in such a workflow scenario involves reinterpreting the data format at every stage. Perhaps this is one reason why HTML forms aren't commonly seen in use for workflow.
XForms enables a different pattern: it allows form data, as an XML file, to be routed to various workstations, as needed. At each stop, the data is loaded into a form, which provides a viewport into editing all or parts of the document, and submitted again. This process can be repeated as many times as necessary, with any number of participants.
As the HTML Working Group became increasingly aware of the limitations inherent in HTML forms, they decided that they needed to develop a new, non-backward-compatible specification for web forms. To do this, they formed a subgroup (which later became a full Working Group) to define the requirements and begin the initial design work of XForms. They set out to produce a system that would fulfill the following requirements:
XForms should use XML, both for initial data and submitted data.
The difference between a blank form and a filled-out form should be minimal and representable as an XML document.
Forms should be easy to route to multiple users and locations.
XForms should separate purpose, presentation, and form data. Earlier, each section describing an HTML form control had to define two things: how the control looked, and how it affected the form data set. XForms should cleanly separate these two aspects.
XForms should provide the 20 percent of functionality needed to avoid 80 percent of all forms scripting.
Popular features such as calculations and validations should be included in the language.
XForms should be designed in such a way to encourage those using HTML forms to switch over by making sure that all the commonly used features in HTML forms are still possible in XForms.
After a number of internal and published requirements documents, the first XForms draft specification was published on April 6, 2000. The title of this document, "Datamodeling Proposal for XForms," gave a strong hint about how undeveloped this initial effort was. In fact, the final versions of the XForms specification bear no resemblance at all to this first attempt.
Why was this? At the time the initial XForms Working Draft was under development, another W3C specification called "XML Schema" was gradually progressing through the W3C channels. In what later proved to be a costly diversion, the XForms Working Group initially decided to make the XForms data types differ from the ones in XML Schema, "due to different usage scenarios and target audiences." As an alternative, the specification spelled out a "simple syntax," which consisted of a number of XML tags such as string, money, and group, where the tags needed to be nested in a structure that mirrored the desired shape of the final XML that would be submitted. For example, to submit XML that looked like:
<poll> <vote>Vanilla</vote> </poll>
You would have needed an XForms "data model" such as this:
<xform>
<group name="poll">
<string name="vote">
</group>
</xform> Although avoiding all traces of XML Schema was attractive to some, it proved to be more trouble than it was worth for a W3C specification. Thus, on August 15, 2000, a very brief Working Draft was published, containing not the XForms specification but, rather, the message: "The Working Group is currently studying how to support forms where the data model is defined by an XML Schema plus form specific properties. The previous version of the XForms Data Model is being obsoleted while this work is underway."
The December 2000 and February 2001 Working Drafts expanded on this new direction, and rolled into the document the XForms User Interface and other pieces that were initially conceived as separate specifications. (The final version of the specification defines modules that have much the same effect.) One other notable aspect of these documents is that they contain the first reference to the XForms Model, or the core definition of a form independent of any user interface. And, of course, XML Schema datatypes made their appearance, though simple syntax clung on as an extra section.
By the publication of the June 2001 Working Draft, people were starting to gain more experience with XForms authoring. With this experience came the realization that the simple syntax wasn't actually simplifying matters. The core problem was that the simple syntax was required to redundantly mirror the structure of the instance data, or initial XML used as form data, forcing authors in many cases to create the same structure twice in slightly different ways. Even worse, it created interoperability problems between XML-Schema-XForms and simple-syntax-XForms. So out went the simple syntax. XML Schema datatypes turned out to not be that bad after all, and the initial instance data itself held all the structural information needed. Things were starting to look up. In short, this Working Draft was the first to strongly represent the final XForms specification.
A few more publication cycles followed in August and December 2001. These updates consisted mostly of editorial work, though a few notable new features included script interfaces to interact with instance data and a cleaned-up processing model. This led the way for the January 2002 "Last Call" Working Draft, and the associated call for public review of XForms. In five weeks, the public mailing list for comments received around 150 substantive comments—each of which needed to be discussed and given a response. Comments ranged from the aesthetic ("please use only lowercase tag names") to the technical ("don't deprecate the HTTP GET method") to the political ("don't publish again until you have a test suite"). Often different submitters made contradictory requests. All in all, it took several months, and an additional publication in August 2002, for the XForms Working Group to sort through all of the advice, make the necessary changes, and send responses to each comment, as required by the W3C process.
Finally, in November 2002, the XForms Candidate Recommendation was released, along with a call for implementations. Strong support from business and open source implementers, collected at a meeting in February 2003, helped identify pieces of the specification that were hard to implement. As of this writing in August 2003, XForms has reached the Proposed Recommendation stage, and is poised to become a final W3C Recommendation shortly thereafter.
The XForms "simple syntax" mentioned earlier served a worthy purpose: to make authors of existing HTML forms comfortable enough to consider making the jump to XForms. So, when the "simple syntax" went away, what replaced it? Literally nothing. Instead of trying to simplify form authoring by adding an additional layer of markup, the designers made XForms remain useful when removing a layer of markup. This extra layer is what needs to be written for the XForms Model, which can be safely omitted in forms of roughly the same complexity as an HTML form with no script. Unofficially, this became known as "lazy author" processing, in deference to the time-honored concept in software engineering of "constructive laziness," or the ability to recognize and actively bypass unnecessary work.
Example 1.14 shows a form that accomplishes the same goals as the earlier HTML form: a poll.
Example 1.14. A poll form implemented in XForms,"lazy author" style
<select1 ref="mainsel" appearance="radio" selection="open">
<label>Poll: to be or not to be?</label>
<item>
<label>To Be</label>
<value>b</value>
</item>
<item>
<label>Not To Be</label>
<value>n</value>
</item>
</select1>Note that no specific choice is needed for an "Other, please specify" selection, since XForms supports the concept of "open selection" lists, where the user is allowed to freely enter additional list values.
Additionally, to make the form submittable, a small bit of markup is required in the head section of the document, as seen in the following code.
<model> <submission action="http://example.info/xml-submit"/> </model>
Unlike the proposed simple syntax, only a minimal amount of keyboard typing is needed for the XForms Model; in fact, little more than a URL to accept submitted data. The main part of the form is specified as user interface form controls: here, select1. Note, too, that the "Other, please specify" choice isn't needed, since XForms supports open selection lists natively. If the user manually entered both as a choice, the resulting XML submitted would look like this:
<instanceData> <mainsel>both</mainsel> </instanceData>
On the other hand, if the user accepted the initial choice, the shorter storage value given in the value attribute would be used:
<instanceData> <mainsel>b</mainsel> </instanceData>
While the lazy author syntax saves typing, it also is severely limited in power, lacking any kind of calculation or validation structure. For this reason, the XForms specification encourages form authors to use the full capacity of XForms. The following chapters describe how to do this.
Table of Contents
"What the world really needs is more love and less paperwork."
-Pearl Bailey
"XML lets organizations benefit from structured, predictable documents. Thus, XML breeds forms. QED."
-David Weinberger
The previous chapter ended with a look at the simple syntax of XForms. This chapter goes into greater detail on the concepts underlying the design of XForms, as well as practical issues that come into play, including a complete, annotated real-world example.
A key concept is the relationship between forms and documents, which will be addressed first. After that, this chapter elaborates on the important issue of host languages and how XForms integrates them.
Despite the name, XForms is being used for many applications beyond simple forms. In particular, creating and editing XML-based documents is a good fit for the technology.
A key advantage of XML-based documents over, say, paper or word processor templates, is that an entirely electronic process eliminates much uncertainty from form processing. Give average "information workers" a paper form, and they'll write illegibly, scribble in the margins, doodle, write in new choices, and just generally do things that aren't expected. All of these behaviors are manually intensive to patch up, in order to clean the data to a point where it can be placed into a database. With XForms, it is possible to restrict the parts of the document that a user is able to modify, which means that submitted data needs only a relatively light double-check before it can be sent to a database. (One pitfall to avoid, however, is a system that is excessively restrictive, so that the person filling the form is unable to accurately provide the needed data. When that happens, users typically give bad information or avoid the electronic system altogether.)
Various efforts are underway to define XML vocabularies for all sorts of documents. Perhaps one of the most ambitious is UBL, the Universal Business Language, currently being standardized through OASIS (the Organization for the Advancement of Structutured Information Standards). The goal of UBL is to represent all different sorts of business documents—purchase orders, invoices, order confirmations, and so on—using a family of XML vocabularies. XForms is a great tool with which to create and edit UBL documents.
As an example, this section will develop an XForms solution for creating and editing a UBL purchase order. The first step is to define the initial instance data, which is a skeleton XML document that contains the complete structure of the desired final document, but with only initial data. This document serves as a template for newly-created purchase orders, and provides a framework on which to hang the rest of the form.
Example 2.1 shows what a UBL purchase order document looks like. Figure 2.1 shows, in the X-Smiles browser, an XForms document capable of creating such a document.
Example 2.1. An XML purchase order using UBL
<Order xmlns="urn:oasis:names:tc:ubl:Order:1.0:0.70"
xmlns:cat="urn:oasis:names:tc:ubl:CommonAggregateTypes:1.0:0.70">
<cat:ID/>
<cat:IssueDate/>
<cat:LineExtensionTotalAmount currencyID="USD"/>
<cat:BuyerParty>
<cat:ID/>
<cat:PartyName>
<cat:Name/>
</cat:PartyName>
<cat:Address>
<cat:ID/>
<cat:Street/>
<cat:CityName/>
<cat:PostalZone/>
<cat:CountrySub-Entity/>
</cat:Address>
<cat:BuyerContact>
<cat:ID/>
<cat:Name/>
</cat:BuyerContact>
</cat:BuyerParty>
<cat:SellerParty>
<cat:ID/>
<cat:PartyName>
<cat:Name/>
</cat:PartyName>
<cat:Address>
<cat:ID/>
<cat:Street/>
<cat:CityName/>
<cat:CountrySub-Entity/>
</cat:Address>
</cat:SellerParty>
<cat:DeliveryTerms>
<cat:ID/>
<cat:SpecialTerms/>
</cat:DeliveryTerms>
<cat:OrderLine>
<cat:BuyersID/>
<cat:SellersID/>
<cat:LineExtensionAmount currencyID=""/>
<cat:Quantity unitCode="">1</cat:Quantity>
<cat:Item>
<cat:ID/>
<cat:Description>Enter description here</cat:Description>
<cat:SellersItemIdentification>
<cat:ID>Enter part number here</cat:ID>
</cat:SellersItemIdentification>
<cat:BasePrice>
<cat:PriceAmount currencyID="">0.00</cat:PriceAmount>
</cat:BasePrice>
</cat:Item>
</cat:OrderLine>
</Order> The markup used by UBL seems slightly verbose, but this is necessary to capture all the small variations that occur in the purchase orders used by different organizations. Note that the cat:OrderLine element can repeat as many times as necessary, though only a single occurrence is needed for the initial instance data. Also note that the root element uses a different XML namespace than the rest of the document. Thanks to the context node rules in XForms, the root element never needs to be directly referred to, and thus form authors can happily ignore this minor detail.
The next step is to create an XForms document that will serve to edit the initial instance data. XForms itself does not define a document format. Instead, a host language such as XHTML or SVG, combined with XForms, needs to be used. As of this writing, XHTML 2.0, which natively includes XForms, is progressing through the W3C Recommendation track. This example, however, uses the established XHTML 1.1, with XForms elements inserted in the appropriate places. As a result, this example will not validate against any XHTML DTD. Even so, it is still XML well-formed, and browsers that understand XForms presently do a good job rendering this document.
The latter part of this chapter describes complications that occur when combining vocabularies; the opening lines of the XForms document shown in Example 2.2 provide a foregleam, using an arcane XML syntax called an internal DTD subset to declare certain attributes as document-unique IDs.
Example 2.2. Opening lines of an XForms document
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="style.css" ?>
<!-- the following extremely ugly code is necessary
to make ID attributes behave as expected -->
<!DOCTYPE html [
<!ATTLIST object id ID #IMPLIED>
<!ATTLIST model id ID #IMPLIED>
<!ATTLIST bind id ID #IMPLIED>
<!ATTLIST instance id ID #IMPLIED>
<!ATTLIST submission id ID #IMPLIED>
<!ATTLIST group id ID #IMPLIED>
<!ATTLIST repeat id ID #IMPLIED>
<!ATTLIST case id ID #IMPLIED>
]>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:u="urn:oasis:names:tc:ubl:CommonAggregateTypes:1.0:0.70"
xmlns:xforms="http://www.w3.org/2002/xforms">
<head>
<title>Create a Purchase Order</title>After the usual XML declaration, the document starts out with a reference to a CSS file to provide style information. Next, the DOCTYPE declaration and the several ATTLIST statements are necessary to make sure that the several ID-typed attributes that will be used are actually treated as IDs.
Following that is the beginning of a normal html element, with several namespace declarations that will be used later in the document. Last is the standard HTML head element, with a title.
The next several lines, in Example 2.3, make up the XForms Model—essentially everything there is to know about the form other than how it will look or otherwise be rendered.
Example 2.3. Starting the XForms Model
<xforms:model id="default">
<!-- schema="schema.xsd" -->
<xforms:instance src="ubl_samp.xml"/>
<xforms:submission action="file://tmp/ubl.xml" method="put" id="submit"/>
<!-- a few things are always required -->
<xforms:bind nodeset="u:IssueDate" required="true( )" type="xs:date"/>
<xforms:bind nodeset="u:OrderLine/u:Quantity" required="true( )"
type="xs:nonNegativeInteger"/>
<xforms:bind nodeset="u:OrderLine/u:Item/u:BasePrice/u:PriceAmount"
required="true( )" type="xs:decimal"/>
<xforms:bind nodeset="u:OrderLine/u:Item/u:SellersItemIdentification/u:ID"
required="true( )"/>
<!-- a few basic calculations -->
<xforms:bind nodeset="u:OrderLine/u:LineExtensionAmount" type="xs:decimal"
calculate="../u:Quantity * ../u:Item/u:BasePrice/u:PriceAmount"/>
<xforms:bind nodeset="u:LineExtensionTotalAmount" type="xs:decimal"
calculate="sum(../u:OrderLine/u:LineExtensionAmount)"/>The xforms:model element is the container for the entire XForms Model. In a document with only one such element, an id attribute isn't strictly needed, though it is good practice to always include one. With the addition of the attribute schema="UBL_Library_0p70_Order.xsd" it would be possible to associate a pre-existing XMLSchema with this form, though that option is commented out here. XML Schema processing would add significant overhead, and the few places that require additional datatype information can be easily specified separately. The xforms:instance element, with the src attribute, points to the initial instance data that was listed earlier. The xforms:submission element indicates that activating submit on this form will write XML to the local file system.
The next several lines contain xforms:bind elements, each of which selects a specific part or parts of the instance data, applying various XForms properties to the selection. The language used to select the XML parts, or nodes, is called XPath, which is perhaps better known as the selection language used in XSLT, XPointer, and XML Signature. The next chapter describes XPath in detail. XForms includes defaulting rules that simplify most of the XPath selection expressions, declared on the nodeset attribute, and called model binding expressions. The first model binding expression selects the one-and-only u:IssueDate instance data node, marking it as required and of the XML Schema datatype date, which provides the hint that this particular data should be entered with a date-optimized form control, such as a calendar picker. The second model binding expression applies to however many u:Quantity elements happen to exist at any given time, and marks all of them as requiring user entry, along with the XML Schema datatype xs:nonNegativeInteger.
The next few model binding expressions set up the two calculations that are fundamental to a purchase order: calculating the total amount for a line item (price times quantity), and the total for the whole order (sum of all line items). The calculate attribute holds an XPath expression that gets evaluated to determine a new value for the node to which it is attached. The calculation for line items is ../u:Quantity * ../u:Item/u:BasePrice/u:PriceAmount, where the asterisk means multiply, and the operands on either side of it are path expressions, relative to the u:LineExtensionAmount element. In turn, the calculation for the grand total is sum(../u:OrderLine/u:LineExtensionAmount), which uses the function sum( ) to add up all the values from individual u:LineExtensionAmount nodes. Like a spreadsheet, recalculations will occur whenever needed, and dependencies among calculations will automatically be handled in the correct order. For example, individual line items will always be multiplied out before the overall total is summed up.
The definition of the XForms Model continues with the lines in Example 2.4.
Example 2.4. The rest of the XForms Model
<!-- a second instance, temporary data not to be submitted -->
<xforms:instance id="scratchpad">
<temp xmlns="">
<currencyOptions>
<option value="EUR">Euro</option>
<option value="GBP">Pound</option>
<option value="USD">Dollar</option>
</currencyOptions>
</temp>
</xforms:instance>
<!-- global setting of currencyID -->
<xforms:bind nodeset="u:OrderLine/u:LineExtensionAmount/@currencyID"
calculate="../../u:LineExtensionTotalAmount/@currencyID"/>
<xforms:bind nodeset="u:OrderLine/u:Item/u:BasePrice/u:PriceAmount/
calculate="../../../../u:LineExtensionTotalAmount/@currencyID"/>
</xforms:model>
</head>An XForms Model can have more than one xforms:instance element. The usual reason for this is to hold temporary, non-submittable data that is used in the form. In this example, various currency codes, and the longer descriptions of each, are kept in a separate location for maintainability. This is also a good example of initial instance data occurring inline in the XForms Model, though it could easily also be another external XML document. The instance data XML itself is not defined in any namespace, so the xmlns="" declaration is essential to turn off the default XHTML namespace that would otherwise be in effect at this point.
The last two xforms:bind elements set up a mapping across the several currencyID attributes that can occur in a UBL document. The form is set up to include a form control that selects the current currency, placing it in the node at u:LineExtensionTotalAmount/@currencyID. The two bind elements in this section then copy the value to the appropriate two places in each line item. In theory, each line item could use a different currency type but, for simplicity, this example sets up two calculations that copy the main selection, which is kept on the u:LineExtensionTotalAmount element, to every other currencyID attribute (the number of which will depend on how many line items are in the order). With this, the XForms Model and the head section of the XHTML document come to a close.
From here on out, the rest of the code is the visible user interface to construct an UBL purchase order. Example 2.5 continues with the definition. Figure 2.2 shows the user interface that results from this portion of the XForms code.
Example 2.5. XForms markup for date, currency type, and total amount
<body>
<xforms:group>
<xforms:input ref="u:IssueDate">
<xforms:label>Order Date</xforms:label>
</xforms:input>
<xforms:select1 ref="u:LineExtensionTotalAmount/@currencyID"
appearance="minimal" selection="open">
<xforms:label>Currency to use throughout this form</xforms:label>
<xforms:itemset nodeset="instance('scratchpad')/currencyOptions/option">
<xforms:label ref="."/>
<xforms:value ref="@value"/>
</xforms:itemset>
</xforms:select1>
<xforms:output ref="u:LineExtensionTotalAmount">
<xforms:label>Order Total: </xforms:label>
</xforms:output>
</xforms:group>The opening of the XHTML body element marks the start of the content that is intended to be rendered. The rest of the content in this section is organized inside an xforms:group element. The first form control is a basic input control, though due to the XML Schema datatype set up in the XForms Model, most implementations will provide a date-specific entry control, such as a pop-up calendar.
The second form control is a single select control, with a hint attribute appearance="minimal" to suggest that this part of the interface should be given minimal screen estate when not activated—in other words, a pop-up list. Another attribute selection="open" indicates that the user should be able to enter arbitrary values not on the list, in which case the entered value would have to be a three-letter currency code, not the friendlier text description that comes with the built-in choices. The xforms:itemset element pulls the choices from the instance data, in this case from the secondary instance data, as can be seen by the instance( ) function in the XPath, which is needed any time the non-default instance data is referenced. A kind of repetition is going on here; despite the single xforms:itemset element, the list will have one choice for each node matched in the secondary instance data.
The output control displays data but doesn't provide any interface for changing it.
Example 2.6 is lengthier, but not difficult to understand.
Example 2.6. XForms markup for addresses
<xforms:switch id="DetailHider">
<xforms:case id="detail_hide">
<xforms:trigger>
<xforms:label>Show Details</xforms:label>
<xforms:toggle ev:event="DOMActivate" case="detail_show"/>
</xforms:trigger>
</xforms:case>
<xforms:case id="detail_show">
<xforms:group id="SellerParty" ref="u:SellerParty">
<xforms:label>Seller Information:</xforms:label>
<xforms:input ref="u:PartyName/u:Name">
<xforms:label>Name</xforms:label>
</xforms:input>
<xforms:group ref="u:Address">
<xforms:input ref="u:Street">
<xforms:label>Street</xforms:label>
</xforms:input>
<xforms:input ref="u:CityName">
<xforms:label>City</xforms:label>
</xforms:input>
<xforms:input ref="u:PostalZone">
<xforms:label>Postal Code</xforms:label>
</xforms:input>
<xforms:input ref="u:CountrySub-Entity">
<xforms:label>State or Province</xforms:label>
</xforms:input>
</xforms:group>
</xforms:group>
<xforms:group id="BuyerParty" ref="u:BuyerParty">
<xforms:label>Buyer Information:</xforms:label>
<xforms:input ref="u:PartyName/u:Name">
<xforms:label>Name</xforms:label>
</xforms:input>
<xforms:group ref="u:Address">
<xforms:input ref="u:Street">
<xforms:label>Street</xforms:label>
</xforms:input>
<xforms:input ref="u:CityName">
<xforms:label>City</xforms:label>
</xforms:input>
<xforms:input ref="u:PostalZone">
<xforms:label>Postal Code</xforms:label>
</xforms:input>
<xforms:input ref="u:CountrySub-Entity">
<xforms:label>State or Province</xforms:label>
</xforms:input>
</xforms:group>
</xforms:group>
<xforms:trigger>
<xforms:label>Hide Details</xforms:label>
<xforms:toggle ev:event="DOMActivate" case="detail_hide"/>
</xforms:trigger>
</xforms:case>
</xforms:switch>Figure 2.3 shows the initial state of the user interface produced by this portion of the XForms code. Figure 2.4 shows the result of toggling the switch, revealing the form controls for entering the buyer and seller information.
The xforms:switch element is a useful tool to show different portions of the user interface on command. In this case, the form controls for seller and buyer information are either entirely shown or entirely hidden. A declarative element, xforms:toggle, changes which of the xforms:case elements get to have its contents rendered, with all others suppressed. The first case, which is the default, displays only an xforms:trigger that toggles itself away, showing all the form controls in the next case in its place.
Within another group for organizational purposes, the form controls in the next section capture all the information needed about the seller referenced by the purchase order. In this case, the overall group has a label, in addition to labels on the individual form controls.
The next group, for the buyer information, is nearly identical to the one that precedes it. While earlier drafts of XForms had a technique to combine this duplicated code in a single place, that feature was dropped in favor of concentrating on getting the underlying framework correct. (One proposal involves combining XSLT with XForms, using the element template to define a template that can be instantiated multiple times throughout the document.)
The last part of this section is another xforms:toggle displayed along with the buyer and shipper information. Upon activation, it causes the contents of the first case to be displayed, which has the effect of hiding all the buyer and shipper interface. The XML instance data, however, continues to exist even when the means of viewing or changing are hidden from view.
Example 2.7 creates a dynamically expandable list of line items.
Example 2.7. Using XForms to create an expandable list.
<!-- repeating sequence for line items -->
<xforms:repeat id="lineitems" nodeset="u:OrderLine">
<xforms:group>
<xforms:range ref="u:Quantity" class="narrow"
start="1" end="9" step="1" incremental="true">
<xforms:label>Quantity <xforms:output ref="."/></xforms:label>
</xforms:range>
<xforms:input ref="u:Item/u:Description" class="wide">
<xforms:label>Description</xforms:label>
</xforms:input>
<xforms:input ref="u:Item/u:SellersItemIdentification/u:ID" class="wide">
<xforms:label>Part Number</xforms:label>
</xforms:input>
<xforms:input ref="u:Item/u:BasePrice/u:PriceAmount" class="narrow">
<xforms:label>Price</xforms:label>
</xforms:input>
</xforms:group>
</xforms:repeat>
<xforms:group id="RepeatDashboard">
<xforms:trigger>
<xforms:label>Insert new line</xforms:label>
<xforms:insert ev:event="DOMActivate" position="after"
nodeset="u:OrderLine" at="index('lineitems')"/>
</xforms:trigger>
<xforms:trigger>
<xforms:label>Remove current line</xforms:label>
<xforms:delete ev:event="DOMActivate" nodeset="u:OrderLine"
at="index('lineitems')"/>
</xforms:trigger>
</xforms:group>Figure 2.5 shows the user interface that results from this portion of the XForms code, with the first line item highlighted.
Like xforms:itemset seen earlier, xforms:repeat causes a repetition of content, once for each node in a given set of nodes—exactly the behavior needed to populate the u:OrderLine elements from UBL. All the content of xforms:repeat is effectively duplicated as many times as there are line items, which can be dynamically added and removed. The first form control on each line item is xforms:range, which allows a smoother way to select a value than typing a number; for example, a sliding indicator. The range here is from 1 to 9.
The rest of the repeating form controls are similar to ones already used in this example. One difference is the class attribute on the final xforms:input, which is used by the associated CSS to style the form control.
Outside of the repeat, a few interesting things are happening. Inside another group, an xforms:trigger is configured to insert a new line item. Another declarative action, xforms:insert, accomplishes this feat. The location of the inserted line item is either just before or just after a specific location (from the at attribute) within a particular node-set (from the nodeset attribute).
The xforms:delete action works similarly. Any repeating set keeps track of the currently active item, called the index. Both the insert and delete actions make use of the index, as obtained through the index( ) function.
The concluding part of the sample document, in Example 2.8, allows the completed document to be written to disk.
Example 2.8. XForms markup to submit the data
<xforms:submit submission="submit">
<xforms:label>Write to disk</xforms:label>
</xforms:submit>
</body>
</html>Figure 2.6 shows the rendering for this piece of XForms code.
The xforms:submit element is another form control, like xforms:trigger, but able to invoke the submission procedure without any additional coding needed. It contains a reference to the xforms:submission element contained in the XForms Model, which ultimately determines what happens when this control is activated. After the last form control, the XHTML document comes to its usual conclusion.
The philosophy of the XForms specification can be summed up in a single line, found in the Abstract of the official W3C XForms document.
XForms is not a free-standing document type, but is intended to be integrated into other markup languages, such as XHTML or SVG.
This approach has benefits as well as drawbacks. The benefits are that the XForms specification was completed more quickly, and without host language dependencies that otherwise might exist. The primary disadvantage is that more work needs to be done to actually integrate XForms with XHTML, SVG, or any other language.
Another W3C specification, Modularization of XHTML, provides a framework in which XHTML, or any other combination of XML-based languages, can be mixed and matched in order to provide a combined document type. Such combinations can take advantage of specific language features; for example, in XHTML a non-rendered head section can contain the XForms Model, and in SVG, a foreignObject element can enclose individual form controls.
Any document that uses XForms will necessarily be a combined document type, involving multiple XML namespaces. Such compound documents are still largely uncharted territory in the realm of W3C specifications, which leads to several headaches. For one thing, XML has the concept of attributes of type ID, specifying a document-unique value. Unfortunately, the id-ness of the attribute needs to be declared in a DTD or some kind of schema, which can only occur at the top of the overall document, not at the point where a subdocument starts. DTDs in general are poorly suited to validation, so until further work is done within the W3C, some XForms documents will have to suffice with being simply well-formed.
Although often scorned by developers, XML namespaces are a fact of life, particularly for W3C specifications. XForms elements conforming to the final W3C Recommendation are defined in a namespace of http://www.w3.org/2002/xforms. Other specifications could, in theory, include all the XForms elements in their own namespace, though this seems unlikely for official W3C specifications. Examples in this book show a mixture of both approaches.
One glimmer of hope is a recurring proposal for an attribute named xml:id, which would be recognized as having id-ness without a separate DTD or Schema. In examples throughout this book, any attributes named id will be considered to have been appropriately declared to be unique identifiers.
In a similar category is an attribute usually named class, which serves as a hook for attaching style sheets. As used throughout this chapter, the host language is responsible for defining this attribute and attaching it to the XForms elements.
Another attribute, src, has caused nearly as much controversy as its big brother in XHTML, href. The problem stems from tension with XLink 1.0, a W3C Recommendation, which asserts itself as the preferred technique to define any "explicit relationship between resources or portions of resources." Originally,