xpath question

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

xpath question

carl.ray
if this is valid:
<xf:case id="case1" selected='true'> ....</xf:case>

why isn't this valid?
<xf:case id="case1" selected="if( //something1 = //something2, 'true',
'false' )"> ... </xf:case>

Does the if() function only work with the value and calculate
attributes? At any rate, it's not working.

_______________________________________________
dev-tech-xforms mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xforms
Reply | Threaded
Open this post in threaded view
|

Re: xpath question

Mark Seaborne-3
I'm afraid you are just a victim of the way @selected is defined in
XForms. It can only take a boolean value, so your XPath expression
just isn't being evaluated.

The best way to achieve the effect you are after is to use:

<xf:group  @ref='myNode'>

instead of your switch/case. Then in the model add a bind like this:

<xf:bind nodeset="myNode" relevant="//something1 = //something2"/>

If @relevant evaluates to true then myNode is relevant, otherwise it
is not.

You can use CSS to hide your group when it is not relevant and show it
when it is relevant.

xf|group:disabled {display: none;}

,for example.

Hope that helps

All the best

Mark

Mark Seaborne
Senior Standards Architect
PicoForms
web:    http://www.picoforms.com
e-mail: [hidden email]
tel: +44 131 2080031
mobile:  +44 787 2180215


On Sep 2, 6:10 am, [hidden email] wrote:
> if this is valid:
> <xf:case id="case1" selected='true'> ....</xf:case>
>
> why isn't this valid?
> <xf:case id="case1" selected="if( //something1 = //something2, 'true',
> 'false' )"> ... </xf:case>
>
> Does the if() function only work with the value and calculate
> attributes? At any rate, it's not working.


_______________________________________________
dev-tech-xforms mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xforms
Reply | Threaded
Open this post in threaded view
|

Re: xpath question

carl.ray
On Sep 2, 4:14 pm, [hidden email] wrote:

> The best way to achieve the effect you are after is to use:
>
> <xf:group  @ref='myNode'>
>
> instead of your switch/case. Then in the model add a bind like this:
>
> <xf:bind nodeset="myNode" relevant="//something1 = //something2"/>

> You can use CSS ...
> xf|group:disabled {display: none;}
>
> Mark Seaborne
> Senior Standards Architect
> PicoForms
> web:    http://www.picoforms.com
> e-mail: [hidden email]
> tel: +44 131 2080031
> mobile:  +44 787 2180215

note:  [sic]"@ref=" s/b "ref="
Thanks Mark,
 Don't know why I didn't think of just foregoing the case for a group
in the first place --  works beautifully now!
But it raises another question for me -- why use the CSS code, it
seems to work just fine without adding anything to my external css
file?

_______________________________________________
dev-tech-xforms mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xforms
Reply | Threaded
Open this post in threaded view
|

Re: xpath question

Mark Seaborne-3
> Thanks Mark,
>  Don't know why I didn't think of just foregoing the case for a group
> in the first place --  works beautifully now!
> But it raises another question for me -- why use the CSS code, it
> seems to work just fine without adding anything to my external css
> file?


Well, the XForms spec doesn't insist that controls bound to
non-relevant items be hidden:

"When false, associated form controls (and any children) and group and
switch elements (including content) should be made unavailable, removed
from the navigation order, and not allowed focus."

So the CSS is just to make sure that the group is "made unavailable" in
exactly the way you want for your form. Another processor might leave
the group visible but indicate in some other way that it is
unavailable, but would obey the CSS (assuming support).

So you are right, you don't need the CSS when using Firefox, but it may
improve portability if you ever use another processor.

All the best

Mark

Mark Seaborne
Senior Standards Architect
PicoForms
web:    http://www.picoforms.com
e-mail: [hidden email]
tel: +44 131 2080031
mobile:  +44 787 2180215

_______________________________________________
dev-tech-xforms mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xforms
Reply | Threaded
Open this post in threaded view
|

Re: xpath question

carl.ray
In reply to this post by carl.ray
> So the CSS is just to make sure that the group is "made unavailable" in
> exactly the way you want for your form. Another processor might leave
> the group visible but indicate in some other way that it is
> unavailable, but would obey the CSS (assuming support).
>
> So .... it may
> improve portability if you ever use another processor.

> Mark Seaborne
> Senior Standards Architect
> PicoForms
> web:    http://www.picoforms.com
> e-mail: [hidden email]
> tel: +44 131 2080031
> mobile:  +44 787 2180215

Thanks. Makes sense.

I've been thinking about the selected attribute. I was aware that it
only takes a boolean value, I just assumed that, like many other
languages, the engine would accept the result (...,'true','false') as
a boolean value. In other words, that it wouldn't care how it was
generated, but only what the end result is or was intended to be.  It
sure would seem like a handy tool if one could use the if()condition
(or invent a new function like boolean(xpath condition, 0, 1) or
something or another. Is there no hope in the future for such a
function? Surely there must be hundreds of reasons one might want to
have one or the other of many cases "selected" based on other
conditions. At any rate, how does one, then, go about getting a case
selected based on a certain condition? (this is just a theoretical
question, not relevant to my current project, so there's no hurry for
any responses).
Thanks all! and especially, thans again Mark for helping me with my
more immediate problem.

_______________________________________________
dev-tech-xforms mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-xforms