Bind question

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

Bind question

joac

Hi,

 

I have a question regarding xforms bind. I have a set of items like this:

 

<items>

<item id=”0”/>

<item id=”1”/>

<item id=”2”/>

</items>

 

I want to create an xforms to add new items to the list an I want to put the constraint that the id attribute must be unique.

 

So my question is how can I do it? I tried the following but is not working:

constraint=”number(.) != number(instance(items)/item/@id)"/>

 

I get the following error:

! XForms error: A sequence of more than one item is not allowed as the first argument of number()

 

Thanks again,

 

Jordi

 



--
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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

RE: Bind question

Ryan Puddephatt
Jordi,
    Have you tried removing number() as this cannot take a sequence, which you are supplying in the second one.
 
Ryan
 

Ryan Puddephatt
Software Engineer
 

Teleflex Group - IT UK
1 Michaelson Square
Livingston
West Lothian
Scotland
EH54 7DP
 
e> [hidden email]
t> +44(0)1506 407 110
f> +44(0)1506 407 108
w> www.teleflex.com

 


From: Jordi Amatller [mailto:[hidden email]]
Sent: 12 February 2007 19:07
To: [hidden email]
Subject: [ops-users] Bind question

Hi,

 

I have a question regarding xforms bind. I have a set of items like this:

 

<items>

<item id=”0”/>

<item id=”1”/>

<item id=”2”/>

</items>

 

I want to create an xforms to add new items to the list an I want to put the constraint that the id attribute must be unique.

 

So my question is how can I do it? I tried the following but is not working:

constraint=”number(.) != number(instance(items)/item/@id)"/>

 

I get the following error:

! XForms error: A sequence of more than one item is not allowed as the first argument of number()

 

Thanks again,

 

Jordi

 



--
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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Bind question

Erik Bruchez
Administrator
In reply to this post by joac
Jordi Amatller wrote:

> Hi,
>
>  
>
> I have a question regarding xforms bind. I have a set of items like this:
>
>  
>
> <items>
>
> <item id=”0”/>
>
> <item id=”1”/>
>
> <item id=”2”/>
>
> </items>
>
>  
>
> I want to create an xforms to add new items to the list an I want to put
> the constraint that the id attribute must be unique.
>
>  
>
> So my question is how can I do it? I tried the following but is not working:
>
> constraint=”number(.) != number(instance(items)/item/@id)"/>
>
>  
>
> I get the following error:
>
> ! XForms error: A sequence of more than one item is not allowed as the
> first argument of number()
Maybe something like this:

   number(.) != (for $number in instance(items)/item/@id return
number($number))

The second part will return a sequence of numbers.

-Erik

--
Orbeon Forms - Web Forms for the Enterprise Done the Right Way
http://www.orbeon.com/



--
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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

RE: Bind question

joac
Thanks Erik,

You give me the hint. It worked like this:

sum(for $i in instance('items')/item/@id return number($i= .)) = 0

If sum is 0 means that there is no coincidence, if sum > 0  the @id is
already in the instance 'items'.

Regards,
Jordi

-----Mensaje original-----
De: Erik Bruchez [mailto:[hidden email]] En nombre de Erik Bruchez
Enviado el: martes, 13 de febrero de 2007 12:04
Para: [hidden email]
Asunto: Re: [ops-users] Bind question

Jordi Amatller wrote:

> Hi,
>
>  
>
> I have a question regarding xforms bind. I have a set of items like this:
>
>  
>
> <items>
>
> <item id="0"/>
>
> <item id="1"/>
>
> <item id="2"/>
>
> </items>
>
>  
>
> I want to create an xforms to add new items to the list an I want to put
> the constraint that the id attribute must be unique.
>
>  
>
> So my question is how can I do it? I tried the following but is not
working:
>
> constraint="number(.) != number(instance(items)/item/@id)"/>
>
>  
>
> I get the following error:
>
> ! XForms error: A sequence of more than one item is not allowed as the
> first argument of number()

Maybe something like this:

   number(.) != (for $number in instance(items)/item/@id return
number($number))

The second part will return a sequence of numbers.

-Erik

--
Orbeon Forms - Web Forms for the Enterprise Done the Right Way
http://www.orbeon.com/





--
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
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

RE: Bind question - unique constraints w/o schema (cont.)

gino-m
Sorry for reviving an old thread, but I thought this might be helpful to someone else.  This worked for me:

<xforms:bind nodeset="item/id" constraint="sum(for $i in /root/item/id return if ($i=.) then 1 else 0) = 1" required="true()"/>

This constrains id to unique, and works for strings as well.

Does anyone have a more elegant way of doing this, without an XPath for loop or XML Schema? I would like to say something like:  "count(/root/item/id[.=text()) = 1", but unfortunately, AFAIK, in XPath filter expressions '.' refers to the node being evaluated in the XPath nodeset, so there is no way to refer to the node being constrained.    Any ideas?

HTH,
Gino
Gino Miceli
Forest Information Systems Specialist
Food and Agriculture Organization of the United Nations
FAO-Finland Cooperation Programme
Sustainable Forest Management in a Changing Climate
Forest Management Division, Rm. D-406
Viale delle Terme di Caracalla, s.n.c.
00153 Rome, Italy
http://www.fao.org/forestry
Reply | Threaded
Open this post in threaded view
|

Re: RE: Bind question - unique constraints w/o schema (cont.)

Alessandro  Vernet
Administrator
Gino,

I think the following will do the trick and will be less of a brain
teaser for your fellow XForms developers who will then be reading your
code ;).

<xforms:bind nodeset="item/id"
    constraint="for $current-id in . return count(/root/item/id[. =
$current-id]) = 1"/>

Alex

On Wed, Mar 24, 2010 at 8:09 AM, gino-m <[hidden email]> wrote:

>
> Sorry for reviving an old thread, but I thought this might be helpful to
> someone else.  This worked for me:
>
> <xforms:bind nodeset="item/id" constraint="sum(for $i in /root/item/id
> return if ($i=.) then 1 else 0) = 1" required="true()"/>
>
> This constrains id to unique, and works for strings as well.
>
> Does anyone have a more elegant way of doing this, without an XPath for loop
> or XML Schema? I would like to say something like:
> "count(/root/item/id[.=text()) = 1", but unfortunately, AFAIK, in XPath
> filter expressions '.' refers to the node being evaluated in the XPath
> nodeset, so there is no way to refer to the node being constrained.    Any
> ideas?
>
> HTH,
> Gino
>
> -----
>
> Gino Miceli
> Forestry Information Systems Specialist
>
> Food and Agriculture Organization of the United Nations
> FAO-Finland Cooperation Programme
> Sustainable Forest Management in a Changing Climate
> Forest Management Division, Rm. D-406
> Forestry Department
> Viale delle Terme di Caracalla, s.n.c.
> 00153 Rome, Italy
> Tel: +39 06 570.56765
> Fax: +39 06 570.55137
> Website: http://www.fao.org/forestry
>
> --
> View this message in context: http://n4.nabble.com/Bind-question-tp32801p1680683.html
> Sent from the Orbeon Forms (ops-users) mailing list archive at Nabble.com.
>
>
> --
> 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
>
>


--
Orbeon Forms - Web forms, open-source, for the Enterprise -
http://www.orbeon.com/
My Twitter: http://twitter.com/avernet


--
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
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

RE: RE: Bind question - unique constraints w/o schema (cont.)

gino-m

Clever fix..  so you use the for loop to capture the context of the current node in $current-id.  Nice job!  Pity the XForms spec doesn’t provide a cleaner way though..  Anyway I prefer your workaround as it is more readable!

 

Thanks,

Gino

 

From: Alessandro Vernet [via Orbeon Forms (ops-users)] [mailto:[hidden email]]
Sent: 25 March 2010 06:39
To: Miceli, Gino (FOMR)
Subject: Re: RE: Bind question - unique constraints w/o schema (cont.)

 

Gino,

I think the following will do the trick and will be less of a brain
teaser for your fellow XForms developers who will then be reading your
code ;).

<xforms:bind nodeset="item/id"
    constraint="for $current-id in . return count(/root/item/id[. =
$current-id]) = 1"/>

Alex

On Wed, Mar 24, 2010 at 8:09 AM, gino-m <[hidden email]> wrote:


>
> Sorry for reviving an old thread, but I thought this might be helpful to
> someone else.  This worked for me:
>
> <xforms:bind nodeset="item/id" constraint="sum(for $i in /root/item/id
> return if ($i=.) then 1 else 0) = 1" required="true()"/>
>
> This constrains id to unique, and works for strings as well.
>
> Does anyone have a more elegant way of doing this, without an XPath for loop
> or XML Schema? I would like to say something like:
> "count(/root/item/id[.=text()) = 1", but unfortunately, AFAIK, in XPath
> filter expressions '.' refers to the node being evaluated in the XPath
> nodeset, so there is no way to refer to the node being constrained.    Any
> ideas?
>
> HTH,
> Gino
>
> -----
>
> Gino Miceli
> Forestry Information Systems Specialist
>
> Food and Agriculture Organization of the United Nations
> FAO-Finland Cooperation Programme
> Sustainable Forest Management in a Changing Climate
> Forest Management Division, Rm. D-406
> Forestry Department
> Viale delle Terme di Caracalla, s.n.c.
> 00153 Rome, Italy
> Tel: +39 06 570.56765
> Fax: +39 06 570.55137
> Website: http://www.fao.org/forestry
>
> --
> View this message in context: http://n4.nabble.com/Bind-question-tp32801p1680683.html
> Sent from the Orbeon Forms (ops-users) mailing list archive at Nabble.com.
>
>
> --
> 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
>
>



--
Orbeon Forms - Web forms, open-source, for the Enterprise -
http://www.orbeon.com/
My Twitter: http://twitter.com/avernet


--
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


View message @ http://n4.nabble.com/Bind-question-tp32801p1690209.html
To unsubscribe from RE: Bind question - unique constraints w/o schema (cont.), click here.

 

Gino Miceli
Forest Information Systems Specialist
Food and Agriculture Organization of the United Nations
FAO-Finland Cooperation Programme
Sustainable Forest Management in a Changing Climate
Forest Management Division, Rm. D-406
Viale delle Terme di Caracalla, s.n.c.
00153 Rome, Italy
http://www.fao.org/forestry