Element content calculation vs. form field controlled attribute

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Element content calculation vs. form field controlled attribute

Thorsten Stumpf
Hello!

The following is a bit complicated to explain but I hope the example clearifies it:
I have a problem with an automatic calculation of textual element content for an node which has an attribute controlled by a form field.

I.e. if a elements content (<element @attribute="i-dont-mean-this">CONTENT</element>) is calculated by a bind the elements attributes can not be altered by user input in a form field.

Uhm, that sounds a bit complicated, so let's rather have a look at some example:

There's an instance flights containing the basic data - for this example it contains cities:

    <flights>
        <flight code="LHR/LH522BUS">
            <city code="LHR ">London</city>
            <airline code="LH">Lufthansa</airline>
            <price currency="€">5412</price>
            <tariff code="BUS"/>
        </flight>
        <flight code=" LGW/AC853ECO">
            <city code="LGW ">London</city>
            <airline code="AC">Air Canada</airline>
            <price currency="€">845</price>
            <tariff code="ECO"/>
        </flight>            ...
    </flights>


And then there is a part in an other instance (booking) which should reflect the selected information:

    <booking>
...
        <flight type="" code="" acc="">
            <city code=""/>
            <airline code=""/>
            <price currency=""/>
            <tariff code=""/>
        </flight>
...
    </booking>


For this example at first the city is choosen by a dropdown:

    <xforms:select1 ref="$booking/city/@code">
        <xforms:label>Airport</xforms:label>
       
        <xforms:itemset nodeset="instance('response')//flight">
            <xforms:label ref="city" />
            <xforms:value ref="city/@code" />
        </xforms:itemset>
    </xforms:select1>
   
It stores the selection in the @code attribute of the city element in the booking instance (I tried to brake down the hole process which is way more complex).


The code-attribute has thus to be selectable by the user.
But I also want to get the name of the city in the XML. This is done easily by a calculate bind looking up the code (see below).

    <xforms:bind ref="$booking">
        <xforms:bind ref="@type" calculate="$anreise/@code"/>

        <xforms:bind ref="city/@code" required="true()"/>
        <xforms:bind ref="city" calculate="xforms:instance('flights')//flight/city[@code = $booking/city/@code]/text()"/>
    </xforms:bind>

If I do so the select form field above is readonly because of the calculate.

I do see the ambiguity of the XPath 'city' but IMHO this definitely should be possible.
To be more specific I tried to be explicit by adding '*', 'text()' etc. but nothing did change the behaviour

    <xforms:bind ref="city/*" calculate="xforms:instance('flights')//flight/city[@code = $booking/city/@code]/text()"/>


Be prepared: Due to the fact that I tried to break down the actual code to the relevant parts I might have missed something. ;-)

Any hints, can this issue be fixed, can I get around that somehow?

Thanks in advance!

Regards

Thorsten


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Element content calculation vs. form field controlled attribute

Erik Bruchez
Administrator
Thorsten,

The usual way is to add readonly="false()" in addition to the
calculate="…" attribute. This will make the data read-write again and
you should be all set!

Also, note that in general using text() is unneeded.

-Erik

On Fri, Nov 4, 2011 at 7:44 AM, Stumpf, Jens Thorsten
<[hidden email]> wrote:

> Hello!
>
> The following is a bit complicated to explain but I hope the example clearifies it:
> I have a problem with an automatic calculation of textual element content for an node which has an attribute controlled by a form field.
>
> I.e. if a elements content (<element @attribute="i-dont-mean-this">CONTENT</element>) is calculated by a bind the elements attributes can not be altered by user input in a form field.
>
> Uhm, that sounds a bit complicated, so let's rather have a look at some example:
>
> There's an instance flights containing the basic data - for this example it contains cities:
>
>    <flights>
>        <flight code="LHR/LH522BUS">
>            <city code="LHR ">London</city>
>            <airline code="LH">Lufthansa</airline>
>            <price currency="€">5412</price>
>            <tariff code="BUS"/>
>        </flight>
>        <flight code=" LGW/AC853ECO">
>            <city code="LGW ">London</city>
>            <airline code="AC">Air Canada</airline>
>            <price currency="€">845</price>
>            <tariff code="ECO"/>
>        </flight>            ...
>    </flights>
>
>
> And then there is a part in an other instance (booking) which should reflect the selected information:
>
>    <booking>
> ...
>        <flight type="" code="" acc="">
>            <city code=""/>
>            <airline code=""/>
>            <price currency=""/>
>            <tariff code=""/>
>        </flight>
> ...
>    </booking>
>
>
> For this example at first the city is choosen by a dropdown:
>
>    <xforms:select1 ref="$booking/city/@code">
>        <xforms:label>Airport</xforms:label>
>
>        <xforms:itemset nodeset="instance('response')//flight">
>            <xforms:label ref="city" />
>            <xforms:value ref="city/@code" />
>        </xforms:itemset>
>    </xforms:select1>
>
> It stores the selection in the @code attribute of the city element in the booking instance (I tried to brake down the hole process which is way more complex).
>
>
> The code-attribute has thus to be selectable by the user.
> But I also want to get the name of the city in the XML. This is done easily by a calculate bind looking up the code (see below).
>
>    <xforms:bind ref="$booking">
>        <xforms:bind ref="@type" calculate="$anreise/@code"/>
>
>        <xforms:bind ref="city/@code" required="true()"/>
>        <xforms:bind ref="city" calculate="xforms:instance('flights')//flight/city[@code = $booking/city/@code]/text()"/>
>    </xforms:bind>
>
> If I do so the select form field above is readonly because of the calculate.
>
> I do see the ambiguity of the XPath 'city' but IMHO this definitely should be possible.
> To be more specific I tried to be explicit by adding '*', 'text()' etc. but nothing did change the behaviour
>
>    <xforms:bind ref="city/*" calculate="xforms:instance('flights')//flight/city[@code = $booking/city/@code]/text()"/>
>
>
> Be prepared: Due to the fact that I tried to break down the actual code to the relevant parts I might have missed something. ;-)
>
> Any hints, can this issue be fixed, can I get around that somehow?
>
> Thanks in advance!
>
> Regards
>
> Thorsten
>
>
> --
> You receive this message as a subscriber of the [hidden email] mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> OW2 mailing lists service home page: http://www.ow2.org/wws
>
>


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws