cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sylvain Wallez <>
Subject wd:choice semantics (was Re: Rename "union" to "select"?)
Date Mon, 05 Jan 2004 14:21:29 GMT
Sylvain Wallez wrote:


> Ah, and another question: why is the case-selection widget a sibling 
> of the "choice" widget? Shouldn't it be a child widget? This would 
> allow an stronger semantic grouping. But I'm not sure if this is good...

Continuing to share my (random) thoughts with you on this...

There are two problems we will quickly face with the current way 
"choices" identifies the case:
- what's the format (or convertor) used for "case" values?
- how can I express more complicated cases, e.g as comparisons?

The answer to both cases is to separate the case value from a widget 
value and turn it into a simple expression.

My previous example can then be:
<wd:choice id="schedule">
 <wd:label>Travel schedule</wd:label>
   <wd:field id="departure-date">...</wd:field>
   <wd:field id="return-date">...</wd:field>
 <wd:case id="one-way" test="travel-type == 1">
   <wd:use-widget id="departure-date"/>
 <wd:case id="two-way" test="travel-type == 2">
   <wd:use-widget id="departure-date"/>
   <wd:use-widget id="return-date"/>

The strings "one-way" and "two-way" are symbolic names that will be used 
in the template, and aren't necessarily the value of a widget.

Here's a more complicated example, that asks to input the number of 
items in various cloth categories depending on an expected temperature 
(any better use case is welcome!)

<wd:field id="expected-temp">..</wd:field>

<wd:choice id="clothes">
    <wd:field id="nb-anorak"/>
    <wd:field id="nb-t-shirts"/>
    <wd:field id="nb-pants"/>
    <wd:field id="nb-shirts"/>
  <wd:case id="cold" test="expected-temp &lt; 0.0">
    <wd:use-widget id="nb-shirts"/>
    <wd:use-widget id="nb-pants"/>
    <wd:use-widget id="nb-anoraks"/>
  <wd:case id="hot" test="expected-temp > 30.0">
    <wd:use-widget id="nb-shirts"/>
    <wd:use-widget id="nb-pants"/>
    <wd:use-widget id="nb-t-shirts"/>
    <wd:use-widget id="nb-shirts"/>
    <wd:use-widget id="nb-pants"/>

Several things to notice here:
- the "expected-temp" value considered uses the unit used 
application-wise (here deg-Celsius) watever the input unit for the user.
- the <wd:otherwise> clause.

The test condition above only involves the "expected-temp" value, but we 
could also combine it with "expected-weather" to allow for the selection 
of boots and t-shirts for tropical rains and regular shoes and anoraks 
in dry and cold areas.



Sylvain Wallez                                  Anyware Technologies 
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }
Orixo, the opensource XML business alliance  -

View raw message