Re: Get the values of an element and combine them

"Steven Pemberton" <[email protected]> Tue, 25 Feb 2014 11:11:36 +0100
Newsgroups gmane.comp.web.xforms
Organization CWI, Amsterdam
Message-ID <op.xbt09mshsmjzpq@steven-ux21a>
------------w9oX4Sglx4vliuISbXuHFH
Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes
Content-Transfer-Encoding: 7bit

On Mon, 24 Feb 2014 19:10:10 +0100, John Boyer <[email protected]> wrote:

> A couple of minor points:
> 1) It's typically better to use xforms-model-construct-done so that the  
> data values are available to the UI when it is first created, rather  
> than having any >kind of value change.
In fact this example revealed to me a place where I would like *really* to  
have an event: after instance construction, but before recalc etc are done.

> 2) The reason I don't usually push this approach is that, you're right,  
> it doesn't account for many use cases in the lifecycle of the data.  For  
> example:- If a new result is obtained from a REST or web service by an  
> xforms submission, then the xforms submit done must also do the same  
> copy operations- Similar issue if someone does a setvalue on the spatial  
> datum, they must do parallel setvalue operations on the instance data-  
> Schema validity results for the spatial datum do not transfer to the  
> controls bound to temporary instance data into which copies have been  
> made.- Model item properties like readonly, required, constraint placed  
> on the spatial datum do not transfer, and so must be recoded as more  
> binds- If this construct is within a repeat, then all of these special  
> cases have increased complexity in light of row insertions
I think you're being too negative. The root of the problem is unstructured  
data. Whoever designed the format

    <dcterms:spatial xsi:type="dcterms:Point">east=456;  
north=123;</dcterms:spatial>

should be forced to attend the beginners class on how to structure data in  
XML. It should be at least

    <dcterms:spatial  
xsi:type="dcterms:Point"><east>456</east><north>123</north></dcterms:spatial>
or
    <dcterms:spatial xsi:type="dcterms:Point" east="456" north="123"/>

but hiding the data in a string is ghastly.

But my approach is to construct a proper XML instance from the  
unstructured data right at the start, and then treat the data as it should  
be treated. You can keep the unstructured data alive with a bind, and that  
can be your return value.

Steven


>
>> Cheers,
> John M. Boyer, Ph.D.
> IBM Distinguished Engineer & IBM Master Inventor
> @johnboyerphd | [email protected]
>
>
>
>
> From:        "Steven Pemberton" <[email protected]>To:         
> [email protected], [email protected], "Jean-Baptiste Pressac"  
> <[email protected]>,Date:        02/24/2014 08:55 AM 
> Subject:        Re: Get the values of an element and combine them
>
>
> Here is an example of how I would do it:
>
>                http://www.cwi.nl/~steven/forms/dcterms.xml
>
> I'm not sure of all the requirements of your problem, but what I do is:
>
>                1. At initialisation, extract the values of east and  
> north from your input spatial value:
>
>                    <action ev:event="xforms-ready">
>                                 <setvalue ref="east"  
> value="substring-before(substring-after(instance('in')/spatial,  
> 'east='), ';')"/>
>                                 <setvalue ref="north"  
> value="substring-before(substring-after(instance('in')/spatial,  
> 'north='), ';')"/>
>                    </action>
>
>                2. Bind a calculation to the output spatial value:
>
>                    <bind ref="spatial" calculate="concat('east=',  
> ../east, '; north=', ../north, ';')"/>
>
> I hope this helps.
>
> Steven Pemberton
>
> On Thu, 20 Feb 2014 16:13:50 +0100, Jean-Baptiste Pressac  
> <[email protected]> wrote:
>
>> Hello,
>> I would like to use Xform to edit the following element :
>> <dcterms:spatial xsi:type="dcterms:Point">east=456;
>> north=123;</dcterms:spatial>
>>
>> I could use :
>> <xf:input ref="dcterms:spatial[@xsi:type='dcterms:Point']"
>> class="dcterms:spatial">
>>      <xf:label>Latitude / Longitude:</xf:label>
>> </xf:input>
>>
>> But is there a way to display two inputs to let the user enter the east
>> value and the north value separately ?
>>
>> Thanks,
------------w9oX4Sglx4vliuISbXuHFH
Content-Type: multipart/related; boundary=----------w9oX4Sglx4vliuPQqFomnU

------------w9oX4Sglx4vliuPQqFomnU
Content-Type: text/html; charset=utf-8
Content-ID: <[email protected]>
Content-Transfer-Encoding: Quoted-Printable

<!DOCTYPE html><html><head>
<style type=3D"text/css">body { font-family:'DejaVu Sans Mono'; font-siz=
e:12px}</style>
</head>
<body>On Mon, 24 Feb 2014 19:10:10 +0100, John Boyer &lt;[email protected]=
om&gt; wrote:<br><br><blockquote style=3D"margin: 0 0 0.80ex; border-lef=
t: #0000FF 2px solid; padding-left: 1ex"><font size=3D"2" face=3D"sans-s=
erif">A couple of minor points:</font>
<br>
<br><font size=3D"2" face=3D"sans-serif">1) It's typically better to use=
 xforms-model-construct-done
so that the data values are available to the UI when it is first created=
,
rather than having any kind of value change.</font>
</blockquote><div>In fact this example revealed to me a place where I wo=
uld like *really* to have an event: after instance construction, but bef=
ore recalc etc are done.</div><div><br></div><blockquote style=3D"margin=
: 0 0 0.80ex; border-left: #0000FF 2px solid; padding-left: 1ex"><font s=
ize=3D"2" face=3D"sans-serif">2) The reason I don't usually push this
approach is that, you're right, it doesn't account for many use cases in=

the lifecycle of the data. &nbsp;For example:</font>
<br><font size=3D"2" face=3D"sans-serif">- If a new result is obtained f=
rom a
REST or web service by an xforms submission, then the xforms submit done=

must also do the same copy operations</font>
<br><font size=3D"2" face=3D"sans-serif">- Similar issue if someone does=
 a setvalue
on the spatial datum, they must do parallel setvalue operations on the
instance data</font>
<br><font size=3D"2" face=3D"sans-serif">- Schema validity results for t=
he spatial
datum do not transfer to the controls bound to temporary instance data
into which copies have been made.</font>
<br><font size=3D"2" face=3D"sans-serif">- Model item properties like re=
adonly,
required, constraint placed on the spatial datum do not transfer, and so=

must be recoded as more binds</font>
<br><font size=3D"2" face=3D"sans-serif">- If this construct is within a=
 repeat,
then all of these special cases have increased complexity in light of ro=
w
insertions</font>
</blockquote><div>I think you're being too negative. The root of the pro=
blem is unstructured data. Whoever designed the format</div><div><br></d=
iv><div><tt><font size=3D"2">&nbsp; &nbsp;&lt;dcterms:spatial xsi:type=3D=
"dcterms:Point"&gt;east=3D456; north=3D123;&lt;/dcterms:spatial&gt;</fon=
t></tt></div><div><font size=3D"2"><br></font></div><div><font size=3D"2=
">should be forced to attend the beginners class on how to structure dat=
a in XML. It should be at least<br></font></div><div><font size=3D"2"><b=
r></font></div><div><font size=3D"2">&nbsp; &nbsp;</font><tt><font size=3D=
"2">&lt;dcterms:spatial xsi:type=3D"dcterms:Point"&gt;&lt;east&gt;456&lt=
;/east&gt;&lt;north&gt;123&lt;/north&gt;&lt;/dcterms:spatial&gt;</font><=
/tt><font size=3D"2"><br></font></div><div>or</div><div><div><font size=3D=
"2">&nbsp; &nbsp;</font><tt><font size=3D"2">&lt;dcterms:spatial xsi:typ=
e=3D"dcterms:Point" east=3D"456" north=3D"123"/&gt;</font></tt><font siz=
e=3D"2"><br></font></div><div><font size=3D"2"><br></font></div><div><fo=
nt size=3D"2">but hiding the data in a string is ghastly.<br></font></di=
v><div><font size=3D"2"><br></font></div><div><font size=3D"2">But my ap=
proach is to construct a proper XML instance from the unstructured data =
right at the start, and then treat the data as it should be treated. You=
 can keep the unstructured data alive with a bind, and that can be your =
return value.&nbsp;<br></font></div><div><font size=3D"2"><br></font></d=
iv><div><font size=3D"2">Steven<br></font></div><div><font size=3D"2"><b=
r></font></div></div><blockquote style=3D"margin: 0 0 0.80ex; border-lef=
t: #0000FF 2px solid; padding-left: 1ex"><br>
<br><font size=3D"2" face=3D"sans-serif">Cheers,</font>
<br><font size=3D"2" face=3D"sans-serif">John M. Boyer, Ph.D.<br>
IBM Distinguished Engineer &amp; IBM Master Inventor<br>
@johnboyerphd | [email protected]<br>
</font>
<br>
<br>
<br>
<br><font size=3D"1" color=3D"#5f5f5f" face=3D"sans-serif">From: &nbsp; =
&nbsp; &nbsp;
&nbsp;</font><font size=3D"1" face=3D"sans-serif">"Steven Pemberton"
&lt;[email protected]&gt;</font>
<br><font size=3D"1" color=3D"#5f5f5f" face=3D"sans-serif">To: &nbsp; &n=
bsp; &nbsp;
&nbsp;</font><font size=3D"1" face=3D"sans-serif">public-xformsusers@w3.=
org,
[email protected], "Jean-Baptiste Pressac" &lt;Jean-Baptiste.Pressac@univ=
-brest.fr&gt;,
</font>
<br><font size=3D"1" color=3D"#5f5f5f" face=3D"sans-serif">Date: &nbsp; =
&nbsp; &nbsp;
&nbsp;</font><font size=3D"1" face=3D"sans-serif">02/24/2014 08:55 AM</f=
ont>
<br><font size=3D"1" color=3D"#5f5f5f" face=3D"sans-serif">Subject: &nbs=
p; &nbsp;
&nbsp; &nbsp;</font><font size=3D"1" face=3D"sans-serif">Re: Get the
values of an element and combine them</font>
<br>
<hr noshade=3D"">
<br>
<br>
<br><tt><font size=3D"2">Here is an example of how I would do it:<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
</font></tt><a href=3D"http://www.cwi.nl/~steven/forms/dcterms.xml"><tt>=
<font size=3D"2">http://www.cwi.nl/~steven/forms/dcterms.xml</font></tt>=
</a><tt><font size=3D"2"><br>
<br>
I'm not sure of all the requirements of your problem, but what I do is:<=
br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
1. At initialisation, extract the values of east and north from your &nb=
sp;<br>
input spatial value:<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &lt;action ev:event=3D"xforms-ready"&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;setval=
ue
ref=3D"east" &nbsp;<br>
value=3D"substring-before(substring-after(instance('in')/spatial, 'east=3D=
'),
&nbsp;<br>
';')"/&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;setval=
ue
ref=3D"north" &nbsp;<br>
value=3D"substring-before(substring-after(instance('in')/spatial, 'north=
=3D'),
&nbsp;<br>
';')"/&gt;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &lt;/action&gt;<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
2. Bind a calculation to the output spatial value:<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &lt;bind ref=3D"spatial" calculate=3D"concat('east=3D',
../east, '; north=3D', &nbsp;<br>
../north, ';')"/&gt;<br>
<br>
I hope this helps.<br>
<br>
Steven Pemberton<br>
<br>
On Thu, 20 Feb 2014 16:13:50 +0100, Jean-Baptiste Pressac &nbsp;<br>
&lt;[email protected]&gt; wrote:<br>
<br>
&gt; Hello,<br>
&gt; I would like to use Xform to edit the following element :<br>
&gt; &lt;dcterms:spatial xsi:type=3D"dcterms:Point"&gt;east=3D456;<br>
&gt; north=3D123;&lt;/dcterms:spatial&gt;<br>
&gt;<br>
&gt; I could use :<br>
&gt; &lt;xf:input ref=3D"dcterms:spatial[@xsi:type=3D'dcterms:Point']"<b=
r>
&gt; class=3D"dcterms:spatial"&gt;<br>
&gt; &nbsp; &nbsp; &nbsp;&lt;xf:label&gt;Latitude / Longitude:&lt;/xf:la=
bel&gt;<br>
&gt; &lt;/xf:input&gt;<br>
&gt;<br>
&gt; But is there a way to display two inputs to let the user enter the
east<br>
&gt; value and the north value separately ?<br>
&gt;<br>
&gt; Thanks,<br>
<br>
</font></tt>
<br></blockquote><br><br><br></body></html>
------------w9oX4Sglx4vliuPQqFomnU--

------------w9oX4Sglx4vliuISbXuHFH--