Jump to content

XForms/Repeat into table

From Wikibooks, open books for an open world

Motivation

[edit | edit source]

Developers frequently desire to display XML data in tabular structures. Unfortunately the HTML <table> 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 <table> 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.

File:C:\Users\Administrator\Desktop\CRF Logo.png

Screen Image

[edit | edit source]
Screen image was made using FormFaces

Sample Program

[edit | edit source]
<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

[edit | edit source]

The line that does the repeat is the table body tag:

   <tbody xf:repeat-nodeset="Person">

References

[edit | edit source]

W3C Web Page on Repeating Attributes


Next Page: Repeat filter | Previous Page: Entity Selection
Home: XForms