411 REFERENCE · Wikibooks
XForms/Repeat into table
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
Motivation
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.
thumbnail
Screen Image
frame|center|Screen image was made using FormFaces
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
Repeat filter Entity Selection