Comments? Feedback?

This wiki does not yet support public comments (a limitation of Google Sites), so we encourage you to post your comments either:

On Twitter by responding to @orbeon.

On our community mailing list: subscribe sending an email to ops-users-subscribe@ow2.org (content of subject/body doesn't matter), you'll get a response with the email to use to send your message to the community mailing list.

Recent site activity

How-to guides‎ > ‎XForms View‎ > ‎

Edit a hierarchical structure

The problem

Assume you have an instance, as the one below, which has an arbitrary level of nesting. How can you create a form to show or edit what is this instance?

<xforms:instance>
    <root>
      <element1>
         <element2>
            <element3>
               <element1>
                  <element2>
                     <element3/>
                  </element2>
               </element1>
            </element3>
            <element3>
               <element1/>
            </element3>
         </element2>
      </element1>
    </root>
</xforms:instance>

The solution

XForms doesn't provide a mechanism to create a arbitrarily nested structure in "output", but using the <xforms:repeat> construct you can iterate over the elements of this instance, and use the XPath expression ancestor-or-self::* to get the current level of nesting. Knowing the current level of nesting, you can produce HTML that will show what the level of nesting is. For instance:

<xforms:repeat nodeset="//*">
    <xforms:output value="string-join(for $element in ancestor-or-self::* return '', ' → ')"/>
    <xforms:output value="name()"/>
    <br/>
</xforms:repeat>

Assuming the instance seen earlier, this will produce the following output:

root
→ element1
→ → element2
→ → → element3
→ → → → element1
→ → → → → element2
→ → → → → → element3
→ → → element3
→ → → → element1

Run it and get the source