Context within a bind calculation

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

Context within a bind calculation

Toon Andries-2
Hi,

I am trying to do a calculation on a bind that requires me to switch context to a different node in the XPath expression.

Say as an example this is my instance:
<xf:instance id="something">
    <something>
        <days>
            <day name="monday" value="1" />
            <day name="tuesday" value="2" />
        </days>
        <calculations base="10">
            <calculation day="monday" value="" />
            <calculation day="tuesday" value="" />
        </calculations>
    </something>
<xf:instance>


I have the following bind to do some calculations (this is not what I'm actually trying to do, I simplified it a lot):
<xf:bind ref="instance('something')">
    <xf:bind ref="calculations/calculation/@value" type="xs:integer" calculate="../../@base + ../../../days/day[@name = context()/../@day]/@value" />
</xf:bind>


Now the problem seems to be that when you enter the square brackets after day[], the context can not be set back to the bind value you are calculating a value for. Not adding the "context()" does not work either.
The part "../../../days/day[@name = context()/../@day]/@value" will not return a value.

How can I switch back to the context I was working with before entering the square brackets?

Kind regards,
Toon Andries

Professional Service Consultant
Inventive Designers

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Reply | Threaded
Open this post in threaded view
|

Re: Context within a bind calculation

Toon Andries-2
I found the solution for the problem. Apparently you can use "current()" instead of "context()" to select the node in the @ref.
That fixed it.

Kind regards,
Toon Andries

Professional Service Consultant
Inventive Designers

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Reply | Threaded
Open this post in threaded view
|

Re: Context within a bind calculation

Alessandro  Vernet
Administrator
Hi Toon,

Yes, you should indeed used current() to get the node pointed by ref. Instead, context() will return the context node in which the <xf:bind> is evaluated. And this holds for actions, in which it is more frequently used.

Say you have an instance <xf:instance></xf:instance>. If at the top-level you run <xf:setvalue ref="/a/b" value="context()/local-name()"/>, you'll get "a", as by default the context is the document element. If you do <xf:setvalue ref="/a/b" value="current()/local-name()"/>, you get "b", which is what you want in your case. And you can play with the context attribute, and do <xf:setvalue context="/a/b" ref="." value="context()/local-name()"/>, which will also return "b" but this time using the context() function.

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: Context within a bind calculation

Alessandro  Vernet
Administrator
[Reposting, as my previous message was incorrectly escaped.]

Hi Toon,

Yes, you should indeed used current() to get the node pointed by ref.
Instead, context() will return the context node in which the <xf:bind>
is evaluated. And this holds for actions, in which it is more
frequently used.

Say you have an instance <xf:instance><a><b/></a></xf:instance>. If at
the top-level you run <xf:setvalue ref="/a/b"
value="context()/local-name()"/>, you'll get "a", as by default the
context is the document element. If you do <xf:setvalue ref="/a/b"
value="current()/local-name()"/>, you get "b", which is what you want
in your case. And you can play with the context attribute, and do
<xf:setvalue context="/a/b" ref="." value="context()/local-name()"/>,
which will also return "b" but this time using the context() function.


Alex

On Wed, Nov 26, 2014 at 6:45 PM, Alessandro  Vernet <[hidden email]> wrote:

> Hi Toon,
>
> Yes, you should indeed used current() to get the node pointed by ref.
> Instead, context() will return the context node in which the <xf:bind> is
> evaluated. And this holds for actions, in which it is more frequently used.
>
> Say you have an instance <xf:instance> * </xf:instance>. If at the top-level
> you run <xf:setvalue ref="/a/b" value="context()/local-name()"/>, you'll get
> "a", as by default the context is the document element. If you do
> <xf:setvalue ref="/a/b" value="current()/local-name()"/>, you get "b", which
> is what you want in your case. And you can play with the context attribute,
> and do <xf:setvalue context="/a/b" ref="." value="context()/local-name()"/>,
> which will also return "b" but this time using the context() function.
>
> Alex
>
> -----
> --
> Follow Orbeon on Twitter: @orbeon
> Follow me on Twitter: @avernet
> --
> View this message in context: http://discuss.orbeon.com/Context-within-a-bind-calculation-tp4659265p4659285.html
> Sent from the Orbeon Forms community mailing list mailing list archive at Nabble.com.
>
> --
> You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> To post to this group, send email to [hidden email].

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet