XForms/Repeat into table

< XForms

Motivation

Developers frequently desire to display XML data in tabular structures. Unfortunately the HTML

implementations used in many browsers do not lend themselves to modification.

To circumvent this problem XForms allows you to use repeat inside a table row as an attribute to the HTML

element. So instead of using a <xf:repeat> element you use a <xf:repeat-nodeset> attribute. Note that you must have the xf prefix on the attribute. This is different then the usual process.

Note: This example does not run under the FireFox 0.6 or the 0.7 extension. See Bug 280368 for details.

{{

}}== Screen Image ==

Sample Program

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms">
   <head>
      <title>Repeat Into Table Using xf:repeat-nodeset</title>
<!-- remove this line for non-formfaces implementations -->
      <script type="text/javascript" src="formfaces.js"></script>
      <xf:model>
         <xf:instance xmlns="">
            <Data xmlns="">
               <Person>
                  <PersonFullName>John Doe</PersonFullName>
                  <ContactTelephoneID>(555) 123-4567</ContactTelephoneID>
               </Person>
               <Person>
                  <PersonFullName>Jane Smith</PersonFullName>
                  <ContactTelephoneID>(555) 123-4567</ContactTelephoneID>
               </Person>
               <Person>
                  <PersonFullName>Jack Jones</PersonFullName>
                  <ContactTelephoneID>(555) 123-4567</ContactTelephoneID>
               </Person>
               <Person>
                  <PersonFullName>Sue Smith</PersonFullName>
                  <ContactTelephoneID>(555) 123-4567</ContactTelephoneID>
               </Person>
            </Data>
         </xf:instance>
      </xf:model>
   </head>
   <body>
      <table border="1">
         <tr>
            <th>Name</th>
            <th>Telephone Number</th>
         </tr>
         <tbody xf:repeat-nodeset="Person">
         <tr>
            <td>
               <xf:output ref="PersonFullName" />
            </td>
            <td>
               <xf:output ref="ContactTelephoneID" />
            </td>
         </tr>
         </tbody>
      </table>
   </body>
</html>

Discussion

The line that does the repeat is the table body tag: <tbody xf:repeat-nodeset="Person">

References

W3C Web Page on Repeating Attributes

This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.