Get the values of an element and combine them

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Get the values of an element and combine them

jean-baptiste pressac
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,

--
Jean-Baptiste Pressac
Traitement et analyse de bases de données
Centre de Recherche Bretonne et Celtique
UMS 3554
20 rue Duquesne
CS 93837
29238 Brest cedex 3

tel : +33 (0)2 98 01 68 95
fax : +33 (0)2 98 01 63 93


Jean-Baptiste_Pressac.vcf (592 bytes) Download Attachment
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Get the values of an element and combine them

Erik Bruchez
Jean-Baptiste,

Some implementations have a component system allowing you do do that
kind of things, but it's not part of standard XForms.

In plain XForms, an input field can only bind to a single element or
attribute and edit its character content.

Regards,

-Erik

On Thu, Feb 20, 2014 at 7:13 AM, Jean-Baptiste Pressac
<[hidden email]> 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,
>
> --
> Jean-Baptiste Pressac
> Traitement et analyse de bases de données
> Centre de Recherche Bretonne et Celtique
> UMS 3554
> 20 rue Duquesne
> CS 93837
> 29238 Brest cedex 3
>
> tel : +33 (0)2 98 01 68 95
> fax : +33 (0)2 98 01 63 93
>

Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Get the values of an element and combine them

John Boyer
A component UI control is typically these are handled in the IBM implementation.  The control only has one xf:input, but as a matter of presentation, the "style" of the control is a group of related UI elements that collect the pieces of the datum. The control knows how to parse and shred the datum into its parts on startup and when the instance data value is changed by something else, like a setvalue or the completion of a submission.  And changes to the parts are commited by the component UI control at times that are determined by the control.

For example, gathering the input of an ip address or a long credit card number or even a good dateTime input would not be different than your case. I'd also expect that the control would focus on the two numbers involved and use presentational labels for the east and north parts, since you may want to present those labels in another language. It's only the data that has to say literally 'east' and 'north', and the control is free to mix in extra non-editable characters with the editable parts.

You could also build this up yourself out of a group of pure XForms controls, combined with some model logic and/or event handlers.  

John M. Boyer, Ph.D.
IBM Distinguished Engineer & IBM Master Inventor
@johnboyerphd | [hidden email]




From:        Erik Bruchez <[hidden email]>
To:        Jean-Baptiste Pressac <[hidden email]>,
Cc:        "[hidden email]" <[hidden email]>, "[hidden email]" <[hidden email]>
Date:        02/20/2014 10:08 AM
Subject:        Re: Get the values of an element and combine them
Sent by:        [hidden email]




Jean-Baptiste,

Some implementations have a component system allowing you do do that
kind of things, but it's not part of standard XForms.

In plain XForms, an input field can only bind to a single element or
attribute and edit its character content.

Regards,

-Erik

On Thu, Feb 20, 2014 at 7:13 AM, Jean-Baptiste Pressac
<[hidden email]> 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,
>
> --
> Jean-Baptiste Pressac
> Traitement et analyse de bases de données
> Centre de Recherche Bretonne et Celtique
> UMS 3554
> 20 rue Duquesne
> CS 93837
> 29238 Brest cedex 3
>
> tel : +33 (0)2 98 01 68 95
> fax : +33 (0)2 98 01 63 93
>


Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Get the values of an element and combine them

Steven Pemberton-3
In reply to this post by jean-baptiste pressac
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  
<[hidden email]> 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,

Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Get the values of an element and combine them

John Boyer
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.

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

Cheers,
John M. Boyer, Ph.D.
IBM Distinguished Engineer & IBM Master Inventor
@johnboyerphd | [hidden email]




From:        "Steven Pemberton" <[hidden email]>
To:        [hidden email], [hidden email], "Jean-Baptiste Pressac" <[hidden email]>,
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  
<[hidden email]> 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,


Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Get the values of an element and combine them

Erik Bruchez
All,

Here is an example using a component approach (works in Orbeon):

The component:

https://gist.github.com/ebruchez/9194679

Use of the component:

https://gist.github.com/ebruchez/9194725

You can try it here:

http://goo.gl/kA8SJa

Works with all types of updates of the data, and within repeats. As
John implies, that's what components and encapsulation give you over
plain XForms. Too bad we haven't standardized that yet!

Regards,

-Erik

On Mon, Feb 24, 2014 at 10:10 AM, John Boyer <[hidden email]> 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.
>
> 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
>
> Cheers,
> John M. Boyer, Ph.D.
> IBM Distinguished Engineer & IBM Master Inventor
> @johnboyerphd | [hidden email]
>
>
>
>
> From:        "Steven Pemberton" <[hidden email]>
> To:        [hidden email], [hidden email], "Jean-Baptiste
> Pressac" <[hidden email]>,
> 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
> <[hidden email]> 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,
>
>

Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Get the values of an element and combine them

Steven Pemberton-3
In reply to this post by John Boyer
On Mon, 24 Feb 2014 19:10:10 +0100, John Boyer <[hidden email]> 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 | [hidden email]




From:        "Steven Pemberton" <[hidden email]>
To:        [hidden email], [hidden email], "Jean-Baptiste Pressac" <[hidden email]>,
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  
<[hidden email]> 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,





Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Get the values of an element and combine them

John Boyer
Well, I agree that the root of the problem is unstructured data, but that doesn't support the characterization of "negative". A better word would be realistic.

Constructing actual XML instance data is a way to solve (agreed) ghastly problem that structured data is in the unstructured character data.  

It's just that doing so sometimes involves as little effort as you depicted, when in a simple test case, but anyone going down this road should be aware of the additional complexities that they must accommodate in order to get all the rest of the advertised benefits of XForms, especially when scaling the technique from test case to production application.  Trying to create a reusable pattern, or "best practice", out of this is frustrated by a person's attempt to use the technique in combination with other aspects of the language in different applications. It breaks in one way in application A and in another way in application B. When this happens, it is an indication that more direct language support is needed, regardless of what we think about the people who designed the data schema.

In fairness to whomever we characterized as having created a ghastly design, these things come up all over the place, even other W3C specs. For example, take a look at xsd:date, or better still xsd:dateTime. In order to provide a nice control that allows a person to input all the pieces of that value, cracking that out into instance data is just not a very scalable approach, especially if you're using these in a repeat that collects the dates and times of something like expenses, patient intake, etc.

John M. Boyer, Ph.D.
IBM Distinguished Engineer & IBM Master Inventor
@johnboyerphd | [hidden email]




From:        "Steven Pemberton" <[hidden email]>
To:        "Steven Pemberton" <[hidden email]>, John Boyer/CanWest/IBM@IBMCA,
Cc:        "Jean-Baptiste Pressac" <[hidden email]>, [hidden email], [hidden email]
Date:        02/25/2014 02:15 AM
Subject:        Re: Get the values of an element and combine them




On Mon, 24 Feb 2014 19:10:10 +0100, John Boyer <[hidden email]> 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 | [hidden email]





From:        
"Steven Pemberton" <[hidden email]>
To:        
[hidden email], [hidden email], "Jean-Baptiste Pressac" <[hidden email]>,
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  
<[hidden email]> 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,





Loading...