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 |