Re: Question about optional element in instance

Hi Miyagi,

Glad to help.  However, note that a separate instance variable is not 
required.   I only used it in my example to separate the relevance 
condition from the original data in a way that you could easily see.

It depends on your condition for relevance, but usually you don't need a 
separate instance to use XForms relevance.

Perhaps you could explain the exact condition under which you want the 
"name" element to be omitted, and then the relevance condition you need 
might turn out to be easy to write.

I can see that the relevance bind you tried would not work at all, though 
I don't believe you should have got the result you did, so perhaps you hit 
an implementation bug.

Here's what your relevance bind should have done.  You wrote relevant=".". 
 This produces a nodeset containing the "name" element.  This is then 
converted to boolean; according to XPath, a nodeset cast to boolean 
produces true if the nodeset is non-empty and false if the nodeset is 
empty.

So, as long as the name element exists, I believe your declaration would 
make it relevant regardless of whether it was empty or not.  To make the 
node non-relevant if it was empty, I believe you would have to write:

<xforms:bind nodeset="name" relevant="string(.)"/>

because a string is converted to boolean false when empty.

Are you saying that you want to omit the element from submission if it is 
empty?  It's unclear why you would bother since the XML with the element 
existing but empty is also schema valid.  So, I am guessing you need a 
more elaborate condition to be met.  Send it along :-)

John M. Boyer, Ph.D.
STSM: Workplace Forms Architect and Researcher
Co-Chair, W3C Forms Working Group
Workplace, Portal and Collaboration Software
IBM Victoria Software Lab
E-Mail: boyerj@ca.ibm.com  http://www.ibm.com/software/

Blog: http://www.ibm.com/developerworks/blogs/page/JohnBoyer





m9467470@nirai.ne.jp 
02/20/2007 06:10 AM

To
John Boyer/CanWest/IBM@IBMCA
cc
www-forms@w3.org, www-forms-request@w3.org
Subject
Re: Question about optional element in instance






Thanks, John Boyer.

It is the solution for the problem.
I tried another way,

<xforms:bind nodeset="name" relevant="."/>

to avoid additional instance.
But it was not work well, cause once client inputs nothing for name,
forms to input name disappear, then never allows to input again.

As your suggestion, it behaved well by placing another "temp" instance.
Just hopes XForms depends more on XML Schema,
then the form processors worked for these Schema structure limitations.

Thanks for your suggestion, but it sounds more complex form,
because Schema I sent is just a bit of the form,
and I need to place more than 10 thoudsands "temp" instances..
(Now constructing XSL for Schema into XForms)


Any way, thanks a lot.
Miyagi

On Mon, 19 Feb 2007 17:54:34 -0800
John Boyer <boyerj@ca.ibm.com> wrote:

> Hi,
> 
> You would of course have some kind of condition that decides whether or 
> not the name or sex is needed.
> 
> You would use an xforms bind to attach this condition to the relevant 
> model item property of the nodes, like this:
> 
> <xforms:bind nodeset="name" relevant="some condition"/>
> 
> <xforms:bind nodeset="sex" relevant="some other condition"/>
> 
> Note that the conditions you set can be based on data nodes in instance 
> other than your primary data instance that represents a client.
> You can create "temporary variables" in another xforms:instance, and 
then 
> use their content in your conditions, like this:
> 
> 
> <xforms:instance id="temp" xmlns="">
>    <tempData>
>         <showName>true</showName>
>         <showSex>false</showSex>
>    </tempData>
> </xforms:instance>
> 
> <xforms:bind nodeset="name" relevant="instance('temp')/showName = 'true' 

> "/>
> 
> <xforms:bind nodeset="sex" relevant="instance('temp')/showSex = 'true' 
"/>
> 
> If the result of the XPath in the 'relevant' attribute is false, then 
the 
> node(s) indicated by the nodeset attribute is considered to be 
> non-relevant by the XForms processor. 
> 
> XForms submissions remove non-relevant nodes from data before 
submission.
> 
> Cheers,
> John M. Boyer, Ph.D.
> STSM: Workplace Forms Architect and Researcher
> Co-Chair, W3C Forms Working Group
> Workplace, Portal and Collaboration Software
> IBM Victoria Software Lab
> E-Mail: boyerj@ca.ibm.com  http://www.ibm.com/software/
> 
> Blog: http://www.ibm.com/developerworks/blogs/page/JohnBoyer
> 

Received on Tuesday, 20 February 2007 16:47:45 UTC