xform group adding if condition to check if node exists

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

xform group adding if condition to check if node exists

kanchan
This post was updated on .
Hi All,

Could you please let me know how can we check if node not exists using xforms?
here is my template
<Item>
<name></name>
<desc></desc>
<hourType></hourType>
</Item>

So, I have added new node "hourType" in my existing template. Now the existing files (Which are generated by this template) will not have this node. So, I want to check if hourType node is not present.
For new files creation, it will be present for old node will not be present.


<xforms:group relevant="if (condition to check if node not present) then . else () " ref="if (condition to check if node not present) then . else () ">

Please help.
Reply | Threaded
Open this post in threaded view
|

Re: xform group adding if condition to check if node exists

Alessandro  Vernet
Administrator
You could write:

<xf:group ref="if (exists(/Item/hourType)) then . else ()">

Don't use the relevant attribute on <xf:group>, as it won't have any effect. And we often write the above as follows, which is a bit shorter, but arguable not as clear:

<xf:group ref=".[exists(/Item/hourType)]">

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

Re: xform group adding if condition to check if node exists

kanchan
This post was updated on .
Thanks Alex.

Can we use not exists
<xf:group ref="if (not exists(/Item/hourType)) then . else ()"> in group
Reply | Threaded
Open this post in threaded view
|

Re: xform group adding if condition to check if node exists

Alessandro  Vernet
Administrator
Yes, you can do:

not(exists(…))

BTW, this is just normal XPath syntax, so you can also refer to books and online information about XPath, should you want to learn more about it.

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet