- From: Steven Pemberton <steven.pemberton@cwi.nl>
- Date: Wed, 07 Nov 2018 17:22:50 +0100
- To: " XForms" <public-xformsusers@w3.org>
I have an XForm, where I don't know what the incoming data looks like, but I want to view and browse it. This is what I do currently: <group> <label>DATA</label> <!-- NEST --> <repeat ref="*"> <output value="concat(name(.), ': ')"/> <output ref=".[count(*)=0]"><label/></output> <group ref=".[count(*)!=0]"> <repeat ref="@*" class="inline"> <output ref="."><label><output value="concat('@', name(.), '=')"/></label></output> </repeat> <!-- NEST --> <repeat ref="*"> <output value="concat(name(.), ': ')"/> <output ref=".[count(*)=0]"><label/></output> <group ref=".[count(*)!=0]"> <repeat ref="@*" class="inline"> <output ref="."><label><output value="concat('@', name(.), '=')"/></label></output> </repeat> <!-- NEST --> AND SO ON AS DEEP AS I WANT </group> </repeat> </group> </repeat> </group> Example output: DATA environment: night: location: people: count: 0 systemHealth: messages: router: router is not available (timeout connecting to 192.168.1.1) status: igor: core: alive: true lastActivity: 1541515205.12 lastSuccess: 1541515205.12 ignoreErrorUntil: errorMessage: save: alive: true lastActivity: 1541603734.74 lastSuccess: 1541603734.74 ignoreErrorUntil: errorMessage: etc. What you can see is that the markup between consecutive NESTs is identical, displaying the name of the element, its attributes, and then drops down one level in the hierarchy for the children of the element. The main disadvantage is that you can't go any deeper than the level of nesting in the code: it can't react dynamically to deeper levels. The structure of the markup is this: <repeat ref="*"> <output value="concat(name(.), ': ')"/> <output ref=".[count(*)=0]"><label/></output> <group ref=".[count(*)!=0]"> <repeat ref="@*" class="inline"> <output ref="."><label><output value="concat('@', name(.), '=')"/></label></output> </repeat> RECURSE HERE </group> </repeat> It strikes me that there is a direct, if simpler, counterpart in repeats: <repeat ref="whatever"> TEMPLATE </repeat> and what we have is <traverse ref="whatever"> TEMPLATE START <descend/> TEMPLATE END </traverse> In my case: <traverse ref="*"> <output value="concat(name(.), ': ')"/> <output ref=".[count(*)=0]"><label/></output> <group ref=".[count(*)!=0]"> <repeat ref="@*" class="inline"> <output ref="."><label><output value="concat('@', name(.), '=')"/></label></output> </repeat> <descend ref="*"/> </group> </traverse> Anyone experience with using or implementing something like this? Steven
Received on Wednesday, 7 November 2018 16:23:14 UTC