Switch/case

I've been writing a big form this week, and I discovered that I was  
creating admin elements just to use for their relevance, in order to drive  
model-based switch.

This led to me to realise that I would like switch/case to be a bit more  
flexible: I'd like the cases to match on expressions.

Not

<switch ref="/payment/details/@method">
   <case/>
   <case name="creditCard" label="Credit Card Details">
     ...
   </case>
   <case name="cashCard" label="Bank Account Card">
     ...
   </case>
   <case name="COD" label="Cash-on-delivery Account Information">
     ...
   </case>
</switch>

but

<switch ref="/payment/details/@method">
   <case if=". = 'creditCard'" label="Credit Card Details">
     ...
   </case>
   <case if=". = 'cashCard'" label="Bank Account Card">
     ...
   </case>
   <case if=". = 'COD'" label="Cash-on-delivery Account Information">
     ...
   </case>
   <case/>
</switch>

But then of course that led me to want:

   <switch value="...">

as well.

Well, what could I do with it. How about

<repeat ref="node()">
    <output value="concat(name(.), ':')"/>
    <switch>
      <case if="count(node()) = 0">
         <output ref="."/>
      </case>
      <case if="count(node()) > 0">
         <repeat ...> ...
         </repeat>
      </case>
    </switch>
</repeat>

Rules:
* value is obtained from switch/@ref or switch/@value
* first case with @if that evaluates to true is selected
* if last case has no condition and no case has been selected, it is  
selected.

Steven

Received on Wednesday, 28 June 2017 10:08:53 UTC